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,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The RANKING CACHE — box 3, and only box 3.
|
|
3
|
+
*
|
|
4
|
+
* Strength is a PURE FUNCTION of stored state and the lived day
|
|
5
|
+
* (`physics/` §5.4). Nothing here is truth: this file holds a materialized copy
|
|
6
|
+
* of `strength(m, d)` and `band(m, d)` so a ranker does not have to recompute
|
|
7
|
+
* the whole store per query. Delete it and nothing is lost but a re-materialize;
|
|
8
|
+
* that is the definition of box 3.
|
|
9
|
+
*
|
|
10
|
+
* Two consequences the contract leans on:
|
|
11
|
+
*
|
|
12
|
+
* - **A replayed day is a no-op BY CONSTRUCTION** (§4, owner rescope 1), not by
|
|
13
|
+
* a per-item stamp. Same state, same day ⇒ same number ⇒ the same row.
|
|
14
|
+
* - **Canonical state takes no decay STEP.** No `uses`, no prose, and no
|
|
15
|
+
* strength anywhere but here. A decay pass that materialized strength into
|
|
16
|
+
* canonical state would be v1's materialize-decay churn, which v2 got as an
|
|
17
|
+
* open choice and declined. *(Amended 2026-09-14, U8: the box-2 `band`
|
|
18
|
+
* column is reconciled by the same pass — it is the band of record, and a
|
|
19
|
+
* table that contradicted the cache was reported as fact by the `status`
|
|
20
|
+
* tool for 869 rows. One UPDATE per disagreeing row, never a strength
|
|
21
|
+
* write; `sleep/NOTES.md` §5.)*
|
|
22
|
+
*
|
|
23
|
+
* **SEAMS item J closed 2026-08-25:** `Store` now owns a `ranking` table inside
|
|
24
|
+
* `cache/cache.sqlite`, and `storeRankingCache()` below is the shipped default —
|
|
25
|
+
* one owner for box 3, one rebuild story (`resetCache` drops `ranking` with the
|
|
26
|
+
* rest). `sqliteStrengthCache()` stays as the fallback for a store-shaped port
|
|
27
|
+
* that does not implement the writer, and as the historical record of why the
|
|
28
|
+
* side file existed: the store holds an open connection to `cache.sqlite` and
|
|
29
|
+
* takes `BEGIN IMMEDIATE` on it, so a SECOND CONNECTION to the same file would
|
|
30
|
+
* contend for its write lock. Going through the store's own connection is what
|
|
31
|
+
* makes the table safe; a foreign connection would not have been.
|
|
32
|
+
*
|
|
33
|
+
* Opening is LAZY. An eagerly-opened SQLite file is a created file, and an
|
|
34
|
+
* observer cycle that creates a file has already failed the byte-compare it
|
|
35
|
+
* exists to pass.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
import { mkdirSync } from "node:fs";
|
|
39
|
+
import { dirname, join } from "node:path";
|
|
40
|
+
import type { Band } from "../types.js";
|
|
41
|
+
import { openDb } from "../store/db.js";
|
|
42
|
+
import type { Db } from "../store/db.js";
|
|
43
|
+
|
|
44
|
+
export const STRENGTH_CACHE_FILE = "strength.sqlite";
|
|
45
|
+
|
|
46
|
+
export function strengthCachePath(dir: string): string {
|
|
47
|
+
return join(dir, "cache", STRENGTH_CACHE_FILE);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface StrengthRow {
|
|
51
|
+
id: string;
|
|
52
|
+
strength: number;
|
|
53
|
+
band: Band;
|
|
54
|
+
day: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface StrengthCache {
|
|
58
|
+
/** Never opens anything that is not already open — a miss is `undefined`. */
|
|
59
|
+
readAll(): Map<string, StrengthRow>;
|
|
60
|
+
write(rows: readonly StrengthRow[]): void;
|
|
61
|
+
close(): void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface CacheRow {
|
|
65
|
+
memory_id: string;
|
|
66
|
+
strength: number;
|
|
67
|
+
band: string;
|
|
68
|
+
day: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const DDL = `CREATE TABLE IF NOT EXISTS ranking (
|
|
72
|
+
memory_id TEXT PRIMARY KEY,
|
|
73
|
+
strength REAL NOT NULL,
|
|
74
|
+
band TEXT NOT NULL,
|
|
75
|
+
day INTEGER NOT NULL
|
|
76
|
+
)`;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The shipped implementation: one small SQLite file inside the cache directory,
|
|
80
|
+
* opened on first use and closed with the cycle.
|
|
81
|
+
*/
|
|
82
|
+
export function sqliteStrengthCache(dir: string): StrengthCache {
|
|
83
|
+
const path = strengthCachePath(dir);
|
|
84
|
+
let db: Db | null = null;
|
|
85
|
+
|
|
86
|
+
const open = (): Db => {
|
|
87
|
+
if (db === null) {
|
|
88
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
89
|
+
db = openDb(path);
|
|
90
|
+
db.exec(DDL);
|
|
91
|
+
}
|
|
92
|
+
return db;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
readAll(): Map<string, StrengthRow> {
|
|
97
|
+
const rows = open().all<CacheRow>("SELECT * FROM ranking");
|
|
98
|
+
const out = new Map<string, StrengthRow>();
|
|
99
|
+
for (const r of rows) {
|
|
100
|
+
out.set(r.memory_id, {
|
|
101
|
+
id: r.memory_id,
|
|
102
|
+
strength: r.strength,
|
|
103
|
+
band: r.band as Band,
|
|
104
|
+
day: r.day,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
},
|
|
109
|
+
write(rows: readonly StrengthRow[]): void {
|
|
110
|
+
if (rows.length === 0) return;
|
|
111
|
+
const d = open();
|
|
112
|
+
d.transaction(() => {
|
|
113
|
+
const st = d.prepare(
|
|
114
|
+
"INSERT OR REPLACE INTO ranking (memory_id, strength, band, day) VALUES (?, ?, ?, ?)",
|
|
115
|
+
);
|
|
116
|
+
for (const r of rows) st.run(r.id, r.strength, r.band, r.day);
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
close(): void {
|
|
120
|
+
if (db !== null) {
|
|
121
|
+
db.close();
|
|
122
|
+
db = null;
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The shipped default: box 3's `ranking` table, written through the store's own
|
|
130
|
+
* connection. No second file, no second lock, and `rebuildCache()` clears it.
|
|
131
|
+
*/
|
|
132
|
+
export interface RankingWriter {
|
|
133
|
+
setRanking?(rows: readonly StrengthRow[]): void;
|
|
134
|
+
rankingAll?(): Map<string, StrengthRow>;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function supportsRanking(
|
|
138
|
+
store: RankingWriter,
|
|
139
|
+
): store is Required<Pick<RankingWriter, "setRanking" | "rankingAll">> & RankingWriter {
|
|
140
|
+
return typeof store.setRanking === "function" && typeof store.rankingAll === "function";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function storeRankingCache(store: RankingWriter): StrengthCache {
|
|
144
|
+
return {
|
|
145
|
+
readAll: () => (store.rankingAll?.() ?? new Map<string, StrengthRow>()),
|
|
146
|
+
write(rows: readonly StrengthRow[]): void {
|
|
147
|
+
if (rows.length === 0) return;
|
|
148
|
+
store.setRanking?.(rows);
|
|
149
|
+
},
|
|
150
|
+
close: () => {
|
|
151
|
+
// The store owns the connection and closes it with the store.
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** An injectable in-process cache — for probes, replay scoring, and tests. */
|
|
157
|
+
export function memoryStrengthCache(seed: readonly StrengthRow[] = []): StrengthCache & {
|
|
158
|
+
rows: Map<string, StrengthRow>;
|
|
159
|
+
writes: number;
|
|
160
|
+
} {
|
|
161
|
+
const rows = new Map<string, StrengthRow>();
|
|
162
|
+
for (const r of seed) rows.set(r.id, { ...r });
|
|
163
|
+
const self = {
|
|
164
|
+
rows,
|
|
165
|
+
writes: 0,
|
|
166
|
+
readAll: () => new Map(rows),
|
|
167
|
+
write(batch: readonly StrengthRow[]): void {
|
|
168
|
+
for (const r of batch) rows.set(r.id, { ...r });
|
|
169
|
+
self.writes += batch.length;
|
|
170
|
+
},
|
|
171
|
+
close: () => {
|
|
172
|
+
/* nothing to close */
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
return self;
|
|
176
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every constant the cycle has, in one visible place, and the two pure
|
|
3
|
+
* configuration checks that are mechanized guarantees rather than taste.
|
|
4
|
+
*
|
|
5
|
+
* CAL = calibration-required: ships with a recorded measurement, or ships
|
|
6
|
+
* disabled (scar §2.8). The budgets below are NOT calibrated — they are sized to
|
|
7
|
+
* be generous on a personal store and to make the "a budget is not a debt"
|
|
8
|
+
* behavior reachable in a test, which is the honest reason to state a number.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { MemorySource } from "../types.js";
|
|
12
|
+
import type { Phase } from "./types.js";
|
|
13
|
+
|
|
14
|
+
export const TUNABLES = {
|
|
15
|
+
/** Auto-consolidation cadence, in LIVED days [v0: every 3 days]. */
|
|
16
|
+
CONSOLIDATION_EVERY_DAYS: 3,
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Below this change in cached strength, the row is left alone — CALM BY
|
|
20
|
+
* DEFAULT (§3, v1 §11 G8). Exponential decay moves a floor memory by ~1e-9 a
|
|
21
|
+
* day; without a quantum every quiet day would rewrite the whole cache and
|
|
22
|
+
* "almost no motion" would be a claim rather than a measurement.
|
|
23
|
+
*/
|
|
24
|
+
DECAY_QUANTUM: 1e-4,
|
|
25
|
+
|
|
26
|
+
/** Per-phase work budgets. Unspent budget carries NO obligation. */
|
|
27
|
+
BUDGETS: {
|
|
28
|
+
clock: 1,
|
|
29
|
+
decay: 20_000,
|
|
30
|
+
consolidate: 5_000,
|
|
31
|
+
prune: 1_000,
|
|
32
|
+
dedup: 1_000,
|
|
33
|
+
versions: 1,
|
|
34
|
+
briefing: 1,
|
|
35
|
+
/**
|
|
36
|
+
* The log sweep's cap: unlatched event rows deleted per pass, oldest first.
|
|
37
|
+
* A store swept for the first time takes its backlog a cap's worth a day
|
|
38
|
+
* rather than in one long transaction — a budget is not a debt, and the
|
|
39
|
+
* rows left are reported as `skippedForBudget`, not carried as arrears.
|
|
40
|
+
* NOT calibrated (CAL): sized so one pass is milliseconds on SQLite (on a
|
|
41
|
+
* 100,000-row log, a 5,000-row capped delete measured 17 ms warm and
|
|
42
|
+
* 177 ms cold; 20,000 rows, 35 ms — NOTES.md §15) and so a day's inflow
|
|
43
|
+
* on a busy store — hundreds of `recall.decision` and `adapter.*` rows —
|
|
44
|
+
* clears in one pass with room to spare.
|
|
45
|
+
*/
|
|
46
|
+
log: 5_000,
|
|
47
|
+
} as const satisfies Record<Phase, number>,
|
|
48
|
+
|
|
49
|
+
/** Cadence in lived days per phase. 1 = every lived day. */
|
|
50
|
+
CADENCE: {
|
|
51
|
+
clock: 1,
|
|
52
|
+
decay: 1,
|
|
53
|
+
consolidate: 3,
|
|
54
|
+
prune: 1,
|
|
55
|
+
dedup: 1,
|
|
56
|
+
versions: 1,
|
|
57
|
+
briefing: 1,
|
|
58
|
+
log: 1,
|
|
59
|
+
} as const satisfies Record<Phase, number>,
|
|
60
|
+
} as const;
|
|
61
|
+
|
|
62
|
+
/** A marker that has never been written. Reads as "due", which is forward-safe. */
|
|
63
|
+
export const MARKER_UNSET = -1;
|
|
64
|
+
|
|
65
|
+
/** Box-2 meta key prefixes. See INTERFACE-GAPS.md §3 — these want real tables. */
|
|
66
|
+
export const MARKER_PREFIX = "sleep.marker.";
|
|
67
|
+
/** Where a budgeted phase stopped, so the next run resumes there (`markers.ts`). */
|
|
68
|
+
export const CURSOR_PREFIX = "sleep.cursor.";
|
|
69
|
+
export const PRUNE_RECORD_PREFIX = "sleep.pruned.";
|
|
70
|
+
export const PROMOTION_RECORD_PREFIX = "sleep.promoted.";
|
|
71
|
+
export const MERGE_RECORD_PREFIX = "sleep.merged.";
|
|
72
|
+
|
|
73
|
+
/** The archive reason the floor prune writes. Archival, never deletion. */
|
|
74
|
+
export const PRUNE_ARCHIVE_REASON = "pruned";
|
|
75
|
+
/** The archive reason a merged duplicate carries. */
|
|
76
|
+
export const MERGE_ARCHIVE_REASON = "merged";
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The channel a revision's successor is minted on (`types.ts#MEMORY_SOURCES`),
|
|
80
|
+
* named here because `dedup.ts` reads it to recognize one. Typed against the
|
|
81
|
+
* vocabulary so a rename in `types.ts` breaks the build rather than silently
|
|
82
|
+
* turning the refusal off.
|
|
83
|
+
*/
|
|
84
|
+
export const ACCOMMODATION_SOURCE: MemorySource = "accommodation";
|
|
85
|
+
|
|
86
|
+
export type WatchdogReason =
|
|
87
|
+
| "OK"
|
|
88
|
+
| "SOFT_NOT_FINITE"
|
|
89
|
+
| "HARD_NOT_FINITE"
|
|
90
|
+
| "LEASE_NOT_FINITE"
|
|
91
|
+
| "SOFT_NOT_BEFORE_HARD"
|
|
92
|
+
| "HARD_KILL_AFTER_LEASE_RECLAIMABLE";
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* CONTRACT §5 G2 — the cross-key invariant, as arithmetic instead of a doc line.
|
|
96
|
+
*
|
|
97
|
+
* The single-writer lease depends on a wedged runner DYING BEFORE ITS LOCK CAN BE
|
|
98
|
+
* TAKEN. If the hard kill can land after the lease becomes reclaimable, a second
|
|
99
|
+
* runner takes the lock while the first is still alive, and v1's double-ticked
|
|
100
|
+
* clock is back. Configuration refuses that setting; it does not warn about it.
|
|
101
|
+
*
|
|
102
|
+
* Pure arithmetic on three numbers — the lock itself belongs to the adapter that
|
|
103
|
+
* spawns the cycle (INTERFACE-GAPS.md §6), but the check belongs here, with the
|
|
104
|
+
* numbers it is about.
|
|
105
|
+
*/
|
|
106
|
+
export function validateWatchdog(
|
|
107
|
+
softMs: number,
|
|
108
|
+
hardMs: number,
|
|
109
|
+
leaseMs: number,
|
|
110
|
+
): { ok: boolean; reason: WatchdogReason } {
|
|
111
|
+
if (!Number.isFinite(softMs) || softMs <= 0) return { ok: false, reason: "SOFT_NOT_FINITE" };
|
|
112
|
+
if (!Number.isFinite(hardMs) || hardMs <= 0) return { ok: false, reason: "HARD_NOT_FINITE" };
|
|
113
|
+
if (!Number.isFinite(leaseMs) || leaseMs <= 0) return { ok: false, reason: "LEASE_NOT_FINITE" };
|
|
114
|
+
if (softMs >= hardMs) return { ok: false, reason: "SOFT_NOT_BEFORE_HARD" };
|
|
115
|
+
if (hardMs >= leaseMs) return { ok: false, reason: "HARD_KILL_AFTER_LEASE_RECLAIMABLE" };
|
|
116
|
+
return { ok: true, reason: "OK" };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export type SpawnReason = "spawn" | "observer";
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* CONTRACT §5 G10 — an observer session SPAWNS NO CYCLE. A cycle advances the
|
|
123
|
+
* clock, materializes decay, and rewrites the briefing: the instrument mutating
|
|
124
|
+
* what it measures (scar E7).
|
|
125
|
+
*
|
|
126
|
+
* `runCycle` under an observer store still produces a full read-only REPORT —
|
|
127
|
+
* that is the dashboard's and the replay scorer's path, and it writes nothing.
|
|
128
|
+
* This predicate is the spawner's question, and its answer is no.
|
|
129
|
+
*/
|
|
130
|
+
export function shouldSpawn(store: { observer: boolean }): {
|
|
131
|
+
spawn: boolean;
|
|
132
|
+
reason: SpawnReason;
|
|
133
|
+
} {
|
|
134
|
+
return store.observer ? { spawn: false, reason: "observer" } : { spawn: true, reason: "spawn" };
|
|
135
|
+
}
|