counterparts 0.1.0
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/CONSTITUTION.md +68 -0
- package/LICENSE +21 -0
- package/README.md +348 -0
- package/docs/ELI5.md +84 -0
- package/docs/QUICKSTART.md +1258 -0
- package/docs/module-map.md +81 -0
- package/package.json +63 -0
- package/src/adapters/claude-code/CONTRACT.md +606 -0
- package/src/adapters/claude-code/INTERFACE-GAPS.md +655 -0
- package/src/adapters/claude-code/NOTES.md +1055 -0
- package/src/adapters/claude-code/bin/hook.ts +820 -0
- package/src/adapters/claude-code/bin/runner.ts +522 -0
- package/src/adapters/claude-code/config.ts +778 -0
- package/src/adapters/claude-code/credentials.ts +199 -0
- package/src/adapters/claude-code/doctor.ts +2557 -0
- package/src/adapters/claude-code/embed-client.ts +617 -0
- package/src/adapters/claude-code/hooks.ts +2240 -0
- package/src/adapters/claude-code/index.ts +224 -0
- package/src/adapters/claude-code/interpret-client.ts +395 -0
- package/src/adapters/claude-code/page-writer.ts +462 -0
- package/src/adapters/claude-code/primacy.ts +162 -0
- package/src/adapters/claude-code/spawn.ts +241 -0
- package/src/adapters/claude-code/standdown.ts +536 -0
- package/src/adapters/claude-code/transcript.ts +661 -0
- package/src/adapters/claude-code/vectors.ts +415 -0
- package/src/adapters/cli/CONTRACT.md +255 -0
- package/src/adapters/cli/INTERFACE-GAPS.md +350 -0
- package/src/adapters/cli/NOTES.md +936 -0
- package/src/adapters/cli/bin/counterparts.ts +74 -0
- package/src/adapters/cli/commands.ts +6095 -0
- package/src/adapters/cli/export.ts +766 -0
- package/src/adapters/cli/index.ts +103 -0
- package/src/adapters/cli/install.ts +670 -0
- package/src/adapters/cli/removal.ts +1186 -0
- package/src/adapters/cli/repair-dates.ts +659 -0
- package/src/adapters/cli/self-page.ts +229 -0
- package/src/adapters/cli/snapshot.ts +279 -0
- package/src/adapters/cli/start-fresh.ts +1228 -0
- package/src/adapters/config-path.ts +342 -0
- package/src/adapters/dashboard/CONTRACT.md +67 -0
- package/src/adapters/dashboard/INTERFACE-GAPS.md +139 -0
- package/src/adapters/dashboard/NOTES.md +474 -0
- package/src/adapters/dashboard/activity.ts +121 -0
- package/src/adapters/dashboard/ansi.ts +82 -0
- package/src/adapters/dashboard/bin/dashboard.ts +479 -0
- package/src/adapters/dashboard/browse.ts +298 -0
- package/src/adapters/dashboard/identity.ts +182 -0
- package/src/adapters/dashboard/index.ts +183 -0
- package/src/adapters/dashboard/layout.ts +149 -0
- package/src/adapters/dashboard/registries.ts +291 -0
- package/src/adapters/dashboard/resolve.ts +206 -0
- package/src/adapters/dashboard/source.ts +48 -0
- package/src/adapters/dashboard/status.ts +327 -0
- package/src/adapters/dashboard/stories.ts +194 -0
- package/src/adapters/dashboard/web/app.html +1731 -0
- package/src/adapters/dashboard/web/brain.html +463 -0
- package/src/adapters/dashboard/web/fired.ts +31 -0
- package/src/adapters/dashboard/web/flow.ts +457 -0
- package/src/adapters/dashboard/web/narrate.ts +1042 -0
- package/src/adapters/dashboard/web/reveal.ts +135 -0
- package/src/adapters/dashboard/web/server.ts +287 -0
- package/src/adapters/dashboard/web/views.ts +1744 -0
- package/src/adapters/expansions.ts +569 -0
- package/src/adapters/fired.ts +1580 -0
- package/src/adapters/mcp/CONTRACT.md +240 -0
- package/src/adapters/mcp/INTERFACE-GAPS.md +271 -0
- package/src/adapters/mcp/NOTES.md +205 -0
- package/src/adapters/mcp/bin/serve.ts +349 -0
- package/src/adapters/mcp/deliberate.ts +619 -0
- package/src/adapters/mcp/index.ts +101 -0
- package/src/adapters/mcp/protocol.ts +170 -0
- package/src/adapters/mcp/server.ts +1740 -0
- package/src/adapters/mcp/stdio.ts +56 -0
- package/src/adapters/mcp/tools.ts +779 -0
- package/src/adapters/scopes.ts +657 -0
- package/src/adapters/sessions.ts +402 -0
- package/src/adapters/snapshots.ts +1069 -0
- package/src/adapters/stance-env.ts +137 -0
- package/src/core/associate/CONTRACT.md +118 -0
- package/src/core/associate/INTERFACE-GAPS.md +173 -0
- package/src/core/associate/NOTES.md +194 -0
- package/src/core/associate/buffer.ts +66 -0
- package/src/core/associate/edges.ts +188 -0
- package/src/core/associate/index.ts +570 -0
- package/src/core/associate/pending.ts +383 -0
- package/src/core/associate/spread.ts +149 -0
- package/src/core/associate/tunables.ts +123 -0
- package/src/core/bridge.ts +272 -0
- package/src/core/briefing.ts +67 -0
- package/src/core/counterpart.ts +3855 -0
- package/src/core/encode/CONTRACT.md +151 -0
- package/src/core/encode/INTERFACE-GAPS.md +135 -0
- package/src/core/encode/NOTES.md +146 -0
- package/src/core/encode/aliases.ts +71 -0
- package/src/core/encode/battery.ts +284 -0
- package/src/core/encode/chunk.ts +265 -0
- package/src/core/encode/emotion.ts +119 -0
- package/src/core/encode/floor.ts +76 -0
- package/src/core/encode/index.ts +100 -0
- package/src/core/encode/precision.ts +162 -0
- package/src/core/encode/preselect.ts +269 -0
- package/src/core/encode/salience.ts +108 -0
- package/src/core/encode/secrets.ts +265 -0
- package/src/core/encode/tunables.ts +99 -0
- package/src/core/encode/types.ts +286 -0
- package/src/core/encode/words.ts +75 -0
- package/src/core/handoff/CONTRACT.md +199 -0
- package/src/core/handoff/INTERFACE-GAPS.md +166 -0
- package/src/core/handoff/NOTES.md +206 -0
- package/src/core/handoff/index.ts +957 -0
- package/src/core/mint.ts +279 -0
- package/src/core/observer.ts +28 -0
- package/src/core/physics/CONTRACT.md +341 -0
- package/src/core/physics/NOTES.md +155 -0
- package/src/core/physics/clock.ts +51 -0
- package/src/core/physics/index.ts +1054 -0
- package/src/core/prospective/CONTRACT.md +137 -0
- package/src/core/prospective/INTERFACE-GAPS.md +112 -0
- package/src/core/prospective/NOTES.md +160 -0
- package/src/core/prospective/derive.ts +188 -0
- package/src/core/prospective/index.ts +1030 -0
- package/src/core/prospective/tunables.ts +72 -0
- package/src/core/prospective/windows.ts +187 -0
- package/src/core/recall/CONTRACT.md +326 -0
- package/src/core/recall/INTERFACE-GAPS.md +163 -0
- package/src/core/recall/NOTES.md +472 -0
- package/src/core/recall/activate.ts +521 -0
- package/src/core/recall/cues.ts +275 -0
- package/src/core/recall/gate.ts +441 -0
- package/src/core/recall/index.ts +692 -0
- package/src/core/recall/probe.ts +239 -0
- package/src/core/recall/reference.ts +201 -0
- package/src/core/recall/render.ts +285 -0
- package/src/core/recall/session.ts +403 -0
- package/src/core/recall/tunables.ts +329 -0
- package/src/core/remember/CONTRACT.md +293 -0
- package/src/core/remember/INTERFACE-GAPS.md +189 -0
- package/src/core/remember/NOTES.md +373 -0
- package/src/core/remember/fallback.ts +452 -0
- package/src/core/remember/index.ts +103 -0
- package/src/core/remember/owner-strike-seam.ts +479 -0
- package/src/core/remember/proposals.ts +609 -0
- package/src/core/remember/spans.ts +1310 -0
- package/src/core/remember/tunables.ts +111 -0
- package/src/core/remember/updates.ts +198 -0
- package/src/core/retrieval.ts +96 -0
- package/src/core/revision.ts +441 -0
- package/src/core/schemas/CONTRACT.md +190 -0
- package/src/core/schemas/INTERFACE-GAPS.md +172 -0
- package/src/core/schemas/NOTES.md +260 -0
- package/src/core/schemas/aliases.ts +160 -0
- package/src/core/schemas/index.ts +1459 -0
- package/src/core/schemas/tunables.ts +44 -0
- package/src/core/schemas/types.ts +387 -0
- package/src/core/self/CONTRACT.md +459 -0
- package/src/core/self/INTERFACE-GAPS.md +284 -0
- package/src/core/self/NOTES.md +1057 -0
- package/src/core/self/briefing.ts +980 -0
- package/src/core/self/episodes.ts +483 -0
- package/src/core/self/freeze.ts +103 -0
- package/src/core/self/identity.ts +604 -0
- package/src/core/self/index.ts +2130 -0
- package/src/core/self/journal-file.ts +760 -0
- package/src/core/self/page.ts +404 -0
- package/src/core/self/tunables.ts +244 -0
- package/src/core/self/writer.ts +714 -0
- package/src/core/sleep/CONTRACT.md +298 -0
- package/src/core/sleep/INTERFACE-GAPS.md +262 -0
- package/src/core/sleep/NOTES.md +770 -0
- package/src/core/sleep/briefing.ts +86 -0
- package/src/core/sleep/consolidate.ts +241 -0
- package/src/core/sleep/cycle.ts +598 -0
- package/src/core/sleep/decay.ts +237 -0
- package/src/core/sleep/dedup.ts +373 -0
- package/src/core/sleep/index.ts +112 -0
- package/src/core/sleep/log.ts +116 -0
- package/src/core/sleep/markers.ts +164 -0
- package/src/core/sleep/prune.ts +170 -0
- package/src/core/sleep/strength-cache.ts +176 -0
- package/src/core/sleep/tunables.ts +135 -0
- package/src/core/sleep/types.ts +542 -0
- package/src/core/store/CONTRACT.md +446 -0
- package/src/core/store/NOTES.md +1068 -0
- package/src/core/store/cache.ts +709 -0
- package/src/core/store/db.ts +275 -0
- package/src/core/store/errors.ts +134 -0
- package/src/core/store/index.ts +2450 -0
- package/src/core/store/operational.ts +610 -0
- package/src/core/store/owner-op-seam.ts +428 -0
- package/src/core/store/paths.ts +494 -0
- package/src/core/store/prose.ts +165 -0
- package/src/core/store/render.ts +87 -0
- package/src/core/store/walk-seam.ts +78 -0
- package/src/core/types.ts +68 -0
- package/tools/install-loop/run.sh +1063 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wake briefing re-render — the cycle's LAST content write.
|
|
3
|
+
*
|
|
4
|
+
* `self/` owns the briefing: what goes in it, the composed byte budget, the trim
|
|
5
|
+
* order, the header/sentinel counts, and the atomic publish (`self/CONTRACT.md`
|
|
6
|
+
* §5 G1–G3). `sleep/` owns exactly one thing about it: that it happens LAST,
|
|
7
|
+
* after revision, so it sees this boundary's own supersedes, promotions, merges,
|
|
8
|
+
* and prunes (CONTRACT §3 G5).
|
|
9
|
+
*
|
|
10
|
+
* `self/` is being built in parallel, so this module DOES NOT IMPORT IT. The
|
|
11
|
+
* seam is an injected `RenderFn`; a test asserts sleep imports nothing from
|
|
12
|
+
* `../self/`. When self's render export exists, the wiring is one line at the
|
|
13
|
+
* coordinator — see INTERFACE-GAPS.md §2.
|
|
14
|
+
*
|
|
15
|
+
* A missing renderer is `did-not-run` with reason `no-render-fn`, NOT a failure
|
|
16
|
+
* and NOT "ran and found nothing" (§5 G6, scar §2.4). The three are different
|
|
17
|
+
* records and a wake that never got re-rendered must be visible as such.
|
|
18
|
+
*
|
|
19
|
+
* Zero generative calls: this module calls the function it was handed and counts
|
|
20
|
+
* bytes. Whatever the renderer does is the renderer's contract, and the launch
|
|
21
|
+
* ruling is that it renders WITHOUT a model (module-map ruling 3).
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import type { PhaseCtx, PhaseOutcome, SleepStore } from "./types.js";
|
|
25
|
+
import { emptyOutcome } from "./types.js";
|
|
26
|
+
|
|
27
|
+
export interface BriefingContext {
|
|
28
|
+
readonly store: SleepStore;
|
|
29
|
+
readonly day: number;
|
|
30
|
+
/** Always false when the renderer is actually invoked — see `runBriefing`. */
|
|
31
|
+
readonly observer: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The HOST's reported injection ceiling, in bytes (SEAMS item G, scar §2.18).
|
|
34
|
+
* `sleep/` has no business inventing one and does not: it carries the number
|
|
35
|
+
* the adapter handed `runCycle` and hands it to the renderer unread. Absent
|
|
36
|
+
* means the host reported none, and the renderer decides what that means —
|
|
37
|
+
* `self/` REQUIRES it, so its adapter refuses rather than guessing.
|
|
38
|
+
*/
|
|
39
|
+
readonly budgetBytes?: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface BriefingOutcome {
|
|
43
|
+
/** Composed size of the published briefing. Counts, never the text. */
|
|
44
|
+
readonly bytes?: number;
|
|
45
|
+
/** How many elements survived the trim order. */
|
|
46
|
+
readonly elements?: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type RenderFn = (ctx: BriefingContext) => BriefingOutcome | void;
|
|
50
|
+
|
|
51
|
+
export interface BriefingResult extends PhaseOutcome {
|
|
52
|
+
readonly rendered: boolean;
|
|
53
|
+
readonly bytes: number;
|
|
54
|
+
readonly elements: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function runBriefing(
|
|
58
|
+
ctx: PhaseCtx,
|
|
59
|
+
render: RenderFn | undefined,
|
|
60
|
+
budgetBytes?: number,
|
|
61
|
+
): BriefingResult {
|
|
62
|
+
const out = emptyOutcome();
|
|
63
|
+
if (render === undefined) {
|
|
64
|
+
out.skipped["no-render-fn"] = 1;
|
|
65
|
+
return { ...out, rendered: false, bytes: 0, elements: 0 };
|
|
66
|
+
}
|
|
67
|
+
out.examined = 1;
|
|
68
|
+
if (!ctx.apply) {
|
|
69
|
+
// An observer never invokes the renderer: publishing a briefing is a content
|
|
70
|
+
// write, and the whole point of the read-only report is that it makes none.
|
|
71
|
+
out.skipped["observer-report"] = 1;
|
|
72
|
+
return { ...out, rendered: false, bytes: 0, elements: 0 };
|
|
73
|
+
}
|
|
74
|
+
const result =
|
|
75
|
+
render({
|
|
76
|
+
store: ctx.store,
|
|
77
|
+
day: ctx.day,
|
|
78
|
+
observer: false,
|
|
79
|
+
...(budgetBytes === undefined ? {} : { budgetBytes }),
|
|
80
|
+
}) ?? ({} as BriefingOutcome);
|
|
81
|
+
out.changed = 1;
|
|
82
|
+
const bytes = result.bytes ?? 0;
|
|
83
|
+
const elements = result.elements ?? 0;
|
|
84
|
+
ctx.event("sleep.briefing.rendered", undefined, { bytes, elements, day: ctx.day });
|
|
85
|
+
return { ...out, rendered: true, bytes, elements };
|
|
86
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consolidation marking, and the ONE place identity promotion happens.
|
|
3
|
+
*
|
|
4
|
+
* Two jobs, in this order, because the second depends on the first:
|
|
5
|
+
*
|
|
6
|
+
* 1. **Consolidation marking.** A memory that has survived at least one lived day
|
|
7
|
+
* past its birth and now sits at or above the semantic floor gets
|
|
8
|
+
* `consolidated = true`, which is worth `+CONS_BONUS` to `base` for the rest
|
|
9
|
+
* of its life (`physics/` §5.2). This is the replay-and-integrate pass, on
|
|
10
|
+
* v0's 3-lived-day cadence.
|
|
11
|
+
*
|
|
12
|
+
* The criterion MOVED to `physics.consolidationEligibility()` on 2026-08-25
|
|
13
|
+
* (SEAMS item M, INTERFACE-GAPS.md §5). This phase now executes a crossing it
|
|
14
|
+
* does not define — the shape the whole contract is built on, and the same
|
|
15
|
+
* relationship it already had with `promotionEligibility`. The property the
|
|
16
|
+
* old inline criterion was written to protect travelled with it: there is
|
|
17
|
+
* deliberately NO reinforcement requirement, because "a formative one-shot
|
|
18
|
+
* consolidates without repetition" is a property physics protects with a
|
|
19
|
+
* `max`, and a repetition gate would quietly repeal it.
|
|
20
|
+
*
|
|
21
|
+
* 2. **Identity promotion — HERE AND ONLY HERE.** Physics decides eligibility
|
|
22
|
+
* (`base >= THETA_ID` AND reinforcement on >= N = 3 DISTINCT lived days);
|
|
23
|
+
* sleep executes the crossing. The crossing is an EXPLICIT, COUNTED EVENT
|
|
24
|
+
* with a persisted §5.3 record — never an emergent side effect of a number
|
|
25
|
+
* drifting past a line (scar §2.4). Nothing is born into identity; this and
|
|
26
|
+
* revision inheritance are the only two doors.
|
|
27
|
+
*
|
|
28
|
+
* Ordering matters: consolidation runs first *within* this phase, so the
|
|
29
|
+
* `+0.2` it grants is visible to the promotion test in the same cycle. That
|
|
30
|
+
* is the intended path into the identity band, not an accident of sequencing.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import { consolidationEligibility, promote } from "../physics/index.js";
|
|
34
|
+
import type { PromotionReason } from "../physics/index.js";
|
|
35
|
+
import { rowToPhysics } from "../store/operational.js";
|
|
36
|
+
import { readCursor, resumeIndex, writeCursor } from "./markers.js";
|
|
37
|
+
import { PROMOTION_RECORD_PREFIX } from "./tunables.js";
|
|
38
|
+
import type { Phase, PhaseCtx, PhaseOutcome, PromotionRecord } from "./types.js";
|
|
39
|
+
import { countSkip, emptyOutcome, isJournal } from "./types.js";
|
|
40
|
+
|
|
41
|
+
/** This phase's own name, for the cursor it keeps. Typed, so a rename in the
|
|
42
|
+
* phase vocabulary fails `tsc` here rather than reading an empty cursor. */
|
|
43
|
+
const CONSOLIDATE_PHASE: Phase = "consolidate";
|
|
44
|
+
|
|
45
|
+
export const CONSOLIDATION_SKIPS = [
|
|
46
|
+
// The three housekeeping entries. The rest of this list IS physics' reason
|
|
47
|
+
// vocabulary, so a reason cannot drift between the two.
|
|
48
|
+
"archived",
|
|
49
|
+
"removed",
|
|
50
|
+
"journal",
|
|
51
|
+
"already-consolidated",
|
|
52
|
+
"born-today",
|
|
53
|
+
"below-semantic-floor",
|
|
54
|
+
] as const;
|
|
55
|
+
|
|
56
|
+
export type ConsolidationSkip = (typeof CONSOLIDATION_SKIPS)[number];
|
|
57
|
+
|
|
58
|
+
export interface ConsolidateResult extends PhaseOutcome {
|
|
59
|
+
readonly consolidated: readonly string[];
|
|
60
|
+
readonly promoted: readonly PromotionRecord[];
|
|
61
|
+
/** Every blocking promotion reason, counted. "Never asked" is not "refused". */
|
|
62
|
+
readonly promotionBlocked: Readonly<Record<string, number>>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function promotionRecordKey(id: string): string {
|
|
66
|
+
return `${PROMOTION_RECORD_PREFIX}${id}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Is this the SELF PAGE's row? Read structurally rather than by importing
|
|
71
|
+
* `self/page.ts` — `sleep/` depends on nothing in `self/`, and a shape check
|
|
72
|
+
* that fails reads as "not the page", which is master's behaviour and therefore
|
|
73
|
+
* the safe direction. The role string's owner is `self/page.ts#SELF_PAGE_ROLE`.
|
|
74
|
+
*
|
|
75
|
+
* Only ever called for a `type: "schema"`, `kind: "self"` row, so the prose read
|
|
76
|
+
* costs the page, the identity core and any belief held about the self — two or
|
|
77
|
+
* three rows on a real store, once per cycle each.
|
|
78
|
+
*/
|
|
79
|
+
function isThePage(store: PhaseCtx["store"], id: string): boolean {
|
|
80
|
+
try {
|
|
81
|
+
return store.read(id).doc.meta["role"] === "page";
|
|
82
|
+
} catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function runConsolidate(ctx: PhaseCtx): ConsolidateResult {
|
|
88
|
+
const out = emptyOutcome();
|
|
89
|
+
for (const skip of CONSOLIDATION_SKIPS) out.skipped[skip] = 0;
|
|
90
|
+
const promotionBlocked: Record<string, number> = {};
|
|
91
|
+
const consolidated: string[] = [];
|
|
92
|
+
const promoted: PromotionRecord[] = [];
|
|
93
|
+
|
|
94
|
+
const { store, day } = ctx;
|
|
95
|
+
const denied = new Set(store.deniedIds());
|
|
96
|
+
const ids = store.list();
|
|
97
|
+
|
|
98
|
+
// WHERE THE LAST RUN STOPPED. `store.list()` is `ORDER BY id`, so the rotation
|
|
99
|
+
// is stable and a cursor means something: this run resumes strictly after it
|
|
100
|
+
// and wraps to the head once it reaches the end, visiting each id at most once
|
|
101
|
+
// per run. A store larger than the budget is therefore covered in
|
|
102
|
+
// ceil(N / budget) runs instead of the first budget's worth being re-examined
|
|
103
|
+
// every night and the rest never. Measured 2026-09-17
|
|
104
|
+
// (`docs/promotion-diagnosis-2026-09-17.md`): 15,292 rows against a budget of
|
|
105
|
+
// 5,000, and 10,000+ memories had never once been asked whether they belong to
|
|
106
|
+
// who the owner is. A budget is still not a debt (§3) — the marker still
|
|
107
|
+
// advances and nothing is owed; only the STARTING PLACE moved.
|
|
108
|
+
const start = resumeIndex(ids, readCursor(store, CONSOLIDATE_PHASE));
|
|
109
|
+
let visited = 0;
|
|
110
|
+
let stoppedAt: string | null = null;
|
|
111
|
+
|
|
112
|
+
while (visited < ids.length) {
|
|
113
|
+
if (out.examined >= ctx.budget) {
|
|
114
|
+
out.budgetExhausted = true;
|
|
115
|
+
out.skippedForBudget = ids.length - visited;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
const id = ids[(start + visited) % ids.length] as string;
|
|
119
|
+
const index = visited + 1;
|
|
120
|
+
visited += 1;
|
|
121
|
+
stoppedAt = id;
|
|
122
|
+
const row = store.row(id);
|
|
123
|
+
if (row === undefined) continue;
|
|
124
|
+
if (denied.has(id)) {
|
|
125
|
+
countSkip(out, "removed");
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (row.archived === 1) {
|
|
129
|
+
countSkip(out, "archived");
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
// A source is not consolidated and cannot cross into the identity band; the
|
|
133
|
+
// MEMORY made from it can, and that is the path (`types.ts#isJournal`).
|
|
134
|
+
if (isJournal(row)) {
|
|
135
|
+
countSkip(out, "journal");
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
out.examined += 1;
|
|
139
|
+
|
|
140
|
+
let p = rowToPhysics(row);
|
|
141
|
+
|
|
142
|
+
// ── 1. consolidation marking ────────────────────────────────────────────
|
|
143
|
+
// Physics decides; this phase executes and counts. The skip vocabulary below
|
|
144
|
+
// IS physics' reason vocabulary, so a reason cannot drift between them.
|
|
145
|
+
const eligibility = consolidationEligibility(p, day);
|
|
146
|
+
if (!eligibility.eligible) {
|
|
147
|
+
countSkip(out, eligibility.reason);
|
|
148
|
+
} else {
|
|
149
|
+
if (ctx.apply) store.updatePhysics(id, { consolidated: true });
|
|
150
|
+
p = { ...p, consolidated: true };
|
|
151
|
+
consolidated.push(id);
|
|
152
|
+
out.changed += 1;
|
|
153
|
+
ctx.event("sleep.consolidated", id, { kind: p.kind, day });
|
|
154
|
+
ctx.step("item", { index, id });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ── 2. the identity crossing ────────────────────────────────────────────
|
|
158
|
+
//
|
|
159
|
+
// THE SELF PAGE DOES NOT CROSS (2026-09-18) — and nothing else changes.
|
|
160
|
+
//
|
|
161
|
+
// The page can be promoted: give it the physics repeated recall credit
|
|
162
|
+
// leaves and forty cycles later it carries `promoted_identity`, `band
|
|
163
|
+
// identity` and a `band.promoted` crossing record, on a row `scanActive` can
|
|
164
|
+
// never rank, counted by the promotion diagnostics and printed by `status`
|
|
165
|
+
// as an identity-band memory. The wake is unaffected; the telemetry is not.
|
|
166
|
+
//
|
|
167
|
+
// **The guard is THE PAGE and not schema rows generally**, which is where a
|
|
168
|
+
// first attempt went wrong and the second review caught it: `physics#decay`
|
|
169
|
+
// returns 1 for a promoted row, so withholding the crossing from beliefs,
|
|
170
|
+
// current-states and entities would stop them becoming decay-exempt — a
|
|
171
|
+
// retention change for three row classes across the owner's whole store,
|
|
172
|
+
// measured at four rows crossing on master and none here, inside a PR about
|
|
173
|
+
// one page. Whether a belief should cross at all is a real question with a
|
|
174
|
+
// one-query answer nobody has yet; it is not this change's to take.
|
|
175
|
+
//
|
|
176
|
+
// The prose read is gated on the row's own columns, so only a schema row of
|
|
177
|
+
// the self kind pays for it — the page, the identity core, and any belief
|
|
178
|
+
// held about the self. The identity core is deliberately NOT exempted: it
|
|
179
|
+
// could cross on master, and exempting it would be the same kind of quiet
|
|
180
|
+
// retention change.
|
|
181
|
+
if (row.type === "schema" && row.kind === "self" && isThePage(store, id)) {
|
|
182
|
+
promotionBlocked["self-page"] = (promotionBlocked["self-page"] ?? 0) + 1;
|
|
183
|
+
countSkip(out, "promotion:self-page");
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const outcome = promote(p, day);
|
|
187
|
+
if (!outcome.promoted || outcome.crossing === null) {
|
|
188
|
+
// Promotion needs ALL conditions, so ALL blocking reasons are reported —
|
|
189
|
+
// "base too low" and "not enough distinct days" are different diagnoses,
|
|
190
|
+
// and mirrored into the skip map they reach the cycle report as well.
|
|
191
|
+
for (const reason of outcome.verdict.blockedBy) {
|
|
192
|
+
promotionBlocked[reason] = (promotionBlocked[reason] ?? 0) + 1;
|
|
193
|
+
countSkip(out, `promotion:${reason}`);
|
|
194
|
+
}
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const record: PromotionRecord = { id, ...outcome.crossing };
|
|
198
|
+
if (ctx.apply) {
|
|
199
|
+
// Record BEFORE the flag: a crossing nobody could account for afterwards
|
|
200
|
+
// is exactly the emergent promotion this phase exists to replace. If the
|
|
201
|
+
// record cannot be written, the memory does not cross.
|
|
202
|
+
store.setMeta(promotionRecordKey(id), JSON.stringify(record));
|
|
203
|
+
store.appendEvent?.({
|
|
204
|
+
name: record.event,
|
|
205
|
+
day,
|
|
206
|
+
ref: id,
|
|
207
|
+
dedupKey: promotionRecordKey(id),
|
|
208
|
+
payload: { ...record },
|
|
209
|
+
});
|
|
210
|
+
store.updatePhysics(id, { promotedIdentity: true });
|
|
211
|
+
// The band column in box 2 is canonical for a crossing (it is a decision,
|
|
212
|
+
// not a decay reading), and the crossing writes it FIRST. Since U8
|
|
213
|
+
// (2026-09-14) decay writes the same column too — it brings every other
|
|
214
|
+
// row to `band(m, d)` — so this is no longer the only writer; what it
|
|
215
|
+
// still is, is the only writer of `identity`. Decay touches no OTHER
|
|
216
|
+
// canonical state: no `uses`, no `lastUsedDay`, no prose (`sleep/NOTES.md`
|
|
217
|
+
// §5).
|
|
218
|
+
store.setBand(id, "identity", day);
|
|
219
|
+
}
|
|
220
|
+
promoted.push(record);
|
|
221
|
+
out.changed += 1;
|
|
222
|
+
ctx.event("sleep.promoted", id, {
|
|
223
|
+
kind: record.kind,
|
|
224
|
+
base: record.base,
|
|
225
|
+
reinforcedDays: record.reinforcedDays,
|
|
226
|
+
day,
|
|
227
|
+
});
|
|
228
|
+
ctx.step("item", { index, id });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// The cursor moves only where a row was actually visited, and only under
|
|
232
|
+
// `apply`: an observer's read-only report may not move the store's place in
|
|
233
|
+
// the store (§5 G10). A run killed mid-phase leaves the cursor where it was
|
|
234
|
+
// and re-walks the same stretch, which is the marker's own bargain — replay a
|
|
235
|
+
// day exactly once rather than skip it.
|
|
236
|
+
if (ctx.apply && stoppedAt !== null) writeCursor(store, CONSOLIDATE_PHASE, stoppedAt);
|
|
237
|
+
|
|
238
|
+
return { ...out, consolidated, promoted, promotionBlocked };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export type { PromotionReason };
|