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,415 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The worker's two vector jobs — the half of the semantic channel that is
|
|
3
|
+
* allowed to take a second.
|
|
4
|
+
*
|
|
5
|
+
* **The finding, 2026-09-04, on the live store.** `RecallTurn.vector` has been
|
|
6
|
+
* an input since `recall/` was written and NEITHER live path set it: the
|
|
7
|
+
* UserPromptSubmit hook built its turn without one and the MCP recall tool built
|
|
8
|
+
* its own. So the 13,862 embeddings the store had paid for were consulted by
|
|
9
|
+
* nothing live — the semantic channel existed in tests and in the sweep's card
|
|
10
|
+
* preselection and nowhere a person could feel it. And only the sweep ever
|
|
11
|
+
* warmed a vector, so 40 authored notes, 224 episodes and 288 migrated memories
|
|
12
|
+
* had none at all: the channel was blind to the first-person material even where
|
|
13
|
+
* it did fire.
|
|
14
|
+
*
|
|
15
|
+
* **The ruling (Mike, 2026-09-04): do not embed on the hot path.** Every hook is
|
|
16
|
+
* a fresh process that already spends 700-1000 ms cold against a 1200 ms recall
|
|
17
|
+
* budget, and `recall.build` is a synchronous pass with checkpoints — an overrun
|
|
18
|
+
* does not degrade the channel, it aborts the whole turn. So the cue is computed
|
|
19
|
+
* AFTER a turn and used on the NEXT one, the way carried cues already work.
|
|
20
|
+
*
|
|
21
|
+
* **And the RANK travels with it, not the vector.** Measured hermetically at the
|
|
22
|
+
* live index's size, `Store.nearestTo` over 13,862 vectors costs 590-1040 ms:
|
|
23
|
+
* `cache.nearest` reads and JSON-parses every row.
|
|
24
|
+
*
|
|
25
|
+
* **Amended 2026-09-05, and the conclusion survives.** Box 3 now stores vectors
|
|
26
|
+
* as float32 BLOBs, and the same scan measures ~50 ms at 14,000×1,024
|
|
27
|
+
* (`store/NOTES.md`) — so the SCAN half of this argument is largely paid off.
|
|
28
|
+
* The other half is not: the network call is still a network call, and it is
|
|
29
|
+
* the one that cannot be raced against a 1200 ms synchronous budget. Ranking
|
|
30
|
+
* stays in the worker for that reason alone.
|
|
31
|
+
*
|
|
32
|
+
* Handing the hot path a vector
|
|
33
|
+
* would have moved the network call off it and left that scan on it — the same
|
|
34
|
+
* abort one layer down. So this file embeds AND ranks, and stores the top-M
|
|
35
|
+
* `{id, score}` slice as per-session gate state (`recall/session.ts`).
|
|
36
|
+
*
|
|
37
|
+
* Both jobs run in the detached worker, both take the injected `fetch` and the
|
|
38
|
+
* watchdog's `AbortSignal`, and neither may fail the run: an embedder that
|
|
39
|
+
* cannot embed costs a cue, never a day.
|
|
40
|
+
*/
|
|
41
|
+
import { EMBED_BACKFILL_EVENT, SEMANTIC_LAG_EVENT } from "../../core/counterpart.js";
|
|
42
|
+
import type { Counterpart } from "../../core/counterpart.js";
|
|
43
|
+
import { stripBoilerplate } from "../../core/recall/index.js";
|
|
44
|
+
import type { SemanticReason } from "../../core/recall/index.js";
|
|
45
|
+
import { EMBED_FAILED_PREFIX, indexTextOf } from "../../core/store/index.js";
|
|
46
|
+
|
|
47
|
+
import type { LiveEmbedder } from "./embed-client.js";
|
|
48
|
+
|
|
49
|
+
export type Emit = (name: string, data: Record<string, string | number | boolean | null>) => void;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* How much of the just-finished turn becomes the next turn's cue.
|
|
53
|
+
*
|
|
54
|
+
* **The conversation side in full (to a cap), a SHORT tail of the reply.** The
|
|
55
|
+
* prompt is what the next turn continues from — topic continuity is the thing
|
|
56
|
+
* being cued. Precisely: the conversation-side SPAN, which `SpanBuffer.capture`
|
|
57
|
+
* builds by joining every non-assistant turn of the window `enters()` kept. That
|
|
58
|
+
* is mostly the owner's own words, and since 2026-09-04 it may also carry a peer
|
|
59
|
+
* session's message — rewritten in place to name its speaker, and therefore
|
|
60
|
+
* legible in the cue rather than mistakable for the owner (CONTRACT G12). It
|
|
61
|
+
* cannot carry this system's own asks: those are `ritual` and enter nothing
|
|
62
|
+
* (G11), which is what keeps the cue from being an embedding of our own
|
|
63
|
+
* boilerplate. The reply is included because a turn is an
|
|
64
|
+
* exchange and the material actually discussed often appears only there; it is
|
|
65
|
+
* bounded hard because an assistant turn can be twenty times the prompt and a
|
|
66
|
+
* long one would drown the prompt in the embedding, which is the semantic
|
|
67
|
+
* analogue of the cue-flood scar (§2.4). 2000/800 bytes: CAL, chosen so the
|
|
68
|
+
* prompt keeps at least ~70% of the joined text at typical lengths and the whole
|
|
69
|
+
* cue stays inside one embedding call. Not measured against surfacing quality
|
|
70
|
+
* yet — the day-1 watch is whether `semantic: "lagged"` turns into surfaced
|
|
71
|
+
* items that were not already lexically cued.
|
|
72
|
+
*/
|
|
73
|
+
export const LAG_PROMPT_BYTES = 2000;
|
|
74
|
+
export const LAG_REPLY_BYTES = 800;
|
|
75
|
+
|
|
76
|
+
/** How many unembedded memories one worker run may pay for. CAL. */
|
|
77
|
+
export const BACKFILL_LIMIT = 64;
|
|
78
|
+
|
|
79
|
+
export interface LagReport {
|
|
80
|
+
readonly reason: SemanticReason;
|
|
81
|
+
readonly stored: boolean;
|
|
82
|
+
readonly hits: number;
|
|
83
|
+
/** Bytes of turn text embedded. Never the text itself. */
|
|
84
|
+
readonly bytes: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Compute the next turn's semantic cue for one session.
|
|
89
|
+
*
|
|
90
|
+
* It reads the session's own last exchange out of the span buffer — which is why
|
|
91
|
+
* it must run BEFORE the sweep, whose claim moves those spans out of the live
|
|
92
|
+
* buffer. The text is stripped of host boilerplate first: recall's §9 G3 says
|
|
93
|
+
* "before cue extraction AND before embedding", and it was measured — an image
|
|
94
|
+
* placeholder token surfaced an unrelated image-cache memory.
|
|
95
|
+
*
|
|
96
|
+
* It ALWAYS records something. A run with no embedder writes `embedder-off`, a
|
|
97
|
+
* run with no credential writes `no-credentials`, and the next turn's decision
|
|
98
|
+
* says so by name rather than looking identical to a session nobody has spoken
|
|
99
|
+
* in yet (scar §2.4).
|
|
100
|
+
*/
|
|
101
|
+
export async function laggedSemantic(input: {
|
|
102
|
+
counterpart: Counterpart;
|
|
103
|
+
sessionId: string;
|
|
104
|
+
scope: string;
|
|
105
|
+
embedder: LiveEmbedder | null;
|
|
106
|
+
/** Present ⇒ a credential answered. Its VALUE is never read here. */
|
|
107
|
+
hasCredential: boolean;
|
|
108
|
+
onEvent?: Emit;
|
|
109
|
+
}): Promise<LagReport> {
|
|
110
|
+
const { counterpart, sessionId, scope } = input;
|
|
111
|
+
const emit = input.onEvent ?? ((): void => {});
|
|
112
|
+
const note = (reason: SemanticReason, vector: number[] | null, bytes: number): LagReport => {
|
|
113
|
+
const out = counterpart.noteSessionSemantic({
|
|
114
|
+
sessionId,
|
|
115
|
+
reason,
|
|
116
|
+
vector,
|
|
117
|
+
model: input.embedder?.model ?? null,
|
|
118
|
+
});
|
|
119
|
+
emit("vectors.lag", { reason: out.reason, hits: out.hits, stored: out.stored, bytes });
|
|
120
|
+
// Durable through `noteAdapterEvent`, the ONE seam an adapter may write the
|
|
121
|
+
// event log through — so tomorrow's coverage watch can count the turns whose
|
|
122
|
+
// cue never got computed, and why, after this process is gone.
|
|
123
|
+
if (!counterpart.observer) {
|
|
124
|
+
counterpart.noteAdapterEvent(SEMANTIC_LAG_EVENT, {
|
|
125
|
+
session: sessionId,
|
|
126
|
+
reason: out.reason,
|
|
127
|
+
hits: out.hits,
|
|
128
|
+
stored: out.stored,
|
|
129
|
+
turn: out.turn,
|
|
130
|
+
bytes,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return { reason: out.reason, stored: out.stored, hits: out.hits, bytes };
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
if (input.embedder === null) return note("embedder-off", null, 0);
|
|
137
|
+
if (!input.hasCredential) return note("no-credentials", null, 0);
|
|
138
|
+
|
|
139
|
+
const text = lagText(counterpart, sessionId, scope);
|
|
140
|
+
if (text.length === 0) return note("no-text", null, 0);
|
|
141
|
+
|
|
142
|
+
let vector: number[] | null = null;
|
|
143
|
+
try {
|
|
144
|
+
vector = await input.embedder.vector(text);
|
|
145
|
+
} catch {
|
|
146
|
+
// `LiveEmbedder.vector` is documented never to throw; if a future one does,
|
|
147
|
+
// a cue is still not worth a failed run.
|
|
148
|
+
vector = null;
|
|
149
|
+
}
|
|
150
|
+
return note(vector === null ? "embed-failed" : "ok", vector, text.length);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The last exchange of one session, bounded and stripped — the string this cue
|
|
155
|
+
* is computed from.
|
|
156
|
+
*
|
|
157
|
+
* Exported for the test that asserts the bound and the strip, because "we
|
|
158
|
+
* embedded the right thing" is not observable from a vector.
|
|
159
|
+
*/
|
|
160
|
+
export function lagText(counterpart: Counterpart, sessionId: string, scope: string): string {
|
|
161
|
+
const mine = (kind: string): string | null => {
|
|
162
|
+
const spans = counterpart.spans.spans(scope);
|
|
163
|
+
for (let i = spans.length - 1; i >= 0; i -= 1) {
|
|
164
|
+
const s = spans[i];
|
|
165
|
+
if (s !== undefined && s.session === sessionId && s.kind === kind) return s.text;
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
};
|
|
169
|
+
const prompt = clip(strip(mine("conversation")), LAG_PROMPT_BYTES);
|
|
170
|
+
// The assistant's words live in their own stream (`assistantSpans`), captured
|
|
171
|
+
// beside the conversation ones.
|
|
172
|
+
const replies = counterpart.spans.assistantSpans(scope).filter((s) => s.session === sessionId);
|
|
173
|
+
const reply = clip(strip(replies.at(-1)?.text ?? null), LAG_REPLY_BYTES);
|
|
174
|
+
return [prompt, reply].filter((s) => s.length > 0).join("\n\n");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function strip(text: string | null): string {
|
|
178
|
+
if (text === null) return "";
|
|
179
|
+
return stripBoilerplate(text).text.trim();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Head, not tail: a prompt states its subject first, and a truncated cue that
|
|
183
|
+
* kept only the closing courtesy is a cue for nothing. */
|
|
184
|
+
function clip(text: string, bytes: number): string {
|
|
185
|
+
return text.length <= bytes ? text : text.slice(0, bytes);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export interface BackfillReport {
|
|
189
|
+
readonly embedded: number;
|
|
190
|
+
readonly failed: number;
|
|
191
|
+
/** Live memories still without a vector AFTER this run, EXCLUDING the ones the
|
|
192
|
+
* store has given up on. The number that must fall run over run, and the one
|
|
193
|
+
* a coverage watch reads; `skipped` is the other half of the same sum. */
|
|
194
|
+
readonly remaining: number;
|
|
195
|
+
readonly attempted: number;
|
|
196
|
+
readonly reason: "ran" | "embedder-off" | "no-credentials" | "nothing-missing" | "observer";
|
|
197
|
+
/**
|
|
198
|
+
* WHY the failures failed: the distinct `code[:status]` pairs of this run,
|
|
199
|
+
* joined by commas, or `""` when nothing failed.
|
|
200
|
+
*
|
|
201
|
+
* I33's whole shape was that this field did not exist. The backfill row said
|
|
202
|
+
* `embedded: 0, failed: 64, reason: ran` for 32 consecutive runs; the HTTP 400
|
|
203
|
+
* that explained all of them lived in a detached process's ring, and the run
|
|
204
|
+
* read like a flaky provider rather than like two poisoned rows.
|
|
205
|
+
*/
|
|
206
|
+
readonly codes: string;
|
|
207
|
+
/** Live memories the store has stopped offering: `embed.failed.<id>` at or
|
|
208
|
+
* past `EMBED_SKIP_AFTER`. Named by `store.skippedVectorIds()`. */
|
|
209
|
+
readonly skipped: number;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Give vectors to memories that have none — up to `BACKFILL_LIMIT` per run,
|
|
214
|
+
* **first-person material first**.
|
|
215
|
+
*
|
|
216
|
+
* `Store.missingVectors` owns the order and states why: what the experiencer
|
|
217
|
+
* authored (`source = 'authored'`) and its own episodes come before everything else,
|
|
218
|
+
* oldest first inside each group. A bounded backfill that only ever reaches N
|
|
219
|
+
* per run should reach the memories this brain wrote about itself.
|
|
220
|
+
*
|
|
221
|
+
* **This is the GUARANTEED path, not the only one.** The authored door already
|
|
222
|
+
* warms its own vector when a `vectors` socket is wired — `submitJot` runs the
|
|
223
|
+
* battery gate, which embeds the GATED text, and `Store.put` then finds it in
|
|
224
|
+
* the same cache. But that only helps a deposit made while an embedder was
|
|
225
|
+
* configured; every memory that predates the embedder, arrived by migration, or
|
|
226
|
+
* was minted on a run whose credential was missing has nothing, and no future
|
|
227
|
+
* deposit will ever come back for it. This does.
|
|
228
|
+
*
|
|
229
|
+
* The two-step is the seam that makes it work and the one that can silently
|
|
230
|
+
* break: `warm()` fills the live embedder's cache keyed by
|
|
231
|
+
* `indexTextOf(title, body)`, and `Store.embedOne` looks it up by exactly that
|
|
232
|
+
* string. `embedOne` reports `vector: false` on a miss, so a backfill that
|
|
233
|
+
* warmed the wrong text reports zero embedded — never a success count over an
|
|
234
|
+
* empty `embeddings` table, which is the shape of the run this whole PR exists
|
|
235
|
+
* to stop repeating.
|
|
236
|
+
*/
|
|
237
|
+
export async function backfillVectors(input: {
|
|
238
|
+
counterpart: Counterpart;
|
|
239
|
+
embedder: LiveEmbedder | null;
|
|
240
|
+
hasCredential: boolean;
|
|
241
|
+
limit?: number;
|
|
242
|
+
onEvent?: Emit;
|
|
243
|
+
}): Promise<BackfillReport> {
|
|
244
|
+
const { counterpart } = input;
|
|
245
|
+
const emit = input.onEvent ?? ((): void => {});
|
|
246
|
+
const limit = input.limit ?? BACKFILL_LIMIT;
|
|
247
|
+
const store = counterpart.store;
|
|
248
|
+
|
|
249
|
+
const done = (
|
|
250
|
+
reason: BackfillReport["reason"],
|
|
251
|
+
embedded: number,
|
|
252
|
+
failed: number,
|
|
253
|
+
attempted: number,
|
|
254
|
+
codes = "",
|
|
255
|
+
): BackfillReport => {
|
|
256
|
+
const remaining = store.unembeddedCount();
|
|
257
|
+
// Counted every run, including the refusals: "how many has this store given
|
|
258
|
+
// up on" is exactly the number a reader wants when `remaining` stops moving.
|
|
259
|
+
let skipped = 0;
|
|
260
|
+
try {
|
|
261
|
+
skipped = store.skippedVectorIds().length;
|
|
262
|
+
} catch {
|
|
263
|
+
// A read that failed costs the field, never the run.
|
|
264
|
+
}
|
|
265
|
+
const report: BackfillReport = {
|
|
266
|
+
embedded,
|
|
267
|
+
failed,
|
|
268
|
+
remaining,
|
|
269
|
+
attempted,
|
|
270
|
+
reason,
|
|
271
|
+
codes,
|
|
272
|
+
skipped,
|
|
273
|
+
};
|
|
274
|
+
emit("vectors.backfill", { ...report });
|
|
275
|
+
if (!counterpart.observer) {
|
|
276
|
+
// Durable, because a coverage watch that lives in a detached process's
|
|
277
|
+
// stderr is a watch nobody can read tomorrow.
|
|
278
|
+
counterpart.noteAdapterEvent(EMBED_BACKFILL_EVENT, { ...report });
|
|
279
|
+
}
|
|
280
|
+
return report;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
if (counterpart.observer) return done("observer", 0, 0, 0);
|
|
284
|
+
if (input.embedder === null) return done("embedder-off", 0, 0, 0);
|
|
285
|
+
if (!input.hasCredential) return done("no-credentials", 0, 0, 0);
|
|
286
|
+
|
|
287
|
+
const ids = store.missingVectors(limit);
|
|
288
|
+
if (ids.length === 0) return done("nothing-missing", 0, 0, 0);
|
|
289
|
+
|
|
290
|
+
const texts: string[] = [];
|
|
291
|
+
const wanted: string[] = [];
|
|
292
|
+
for (const id of ids) {
|
|
293
|
+
let doc;
|
|
294
|
+
try {
|
|
295
|
+
doc = store.readProse(id);
|
|
296
|
+
} catch {
|
|
297
|
+
continue; // a row whose prose has gone is not a failure worth a retry
|
|
298
|
+
}
|
|
299
|
+
// THE SAME STRING `embedOne` will ask for. Composing it any other way
|
|
300
|
+
// caches under a key the store never looks up, and the backfill becomes a
|
|
301
|
+
// paid-for no-op that reports success.
|
|
302
|
+
texts.push(indexTextOf(doc.title, doc.body));
|
|
303
|
+
wanted.push(id);
|
|
304
|
+
}
|
|
305
|
+
if (wanted.length === 0) return done("nothing-missing", 0, 0, 0);
|
|
306
|
+
|
|
307
|
+
try {
|
|
308
|
+
await input.embedder.warm(texts);
|
|
309
|
+
} catch {
|
|
310
|
+
// One batched call; a refusal leaves the cache as it was and every
|
|
311
|
+
// `embedOne` below reports `vector: false`. Counted, not thrown.
|
|
312
|
+
}
|
|
313
|
+
// The codes of the fill that just happened, before anything else can reset
|
|
314
|
+
// them. `stats()` is a read; `lastFailures` is per-fill by construction.
|
|
315
|
+
const codes = codesOf(input.embedder);
|
|
316
|
+
|
|
317
|
+
// WHOSE FAULT WAS IT. The give-up counter may only move on a failure the
|
|
318
|
+
// PROVIDER blamed on the item: a 400 the bisector narrowed to one input. A
|
|
319
|
+
// 429, a 5xx, a dead socket or an aborted watchdog is a fact about the RUN,
|
|
320
|
+
// and counting those was I33 inverted — three bad boundaries in a row retired
|
|
321
|
+
// a whole healthy window and `unembeddedCount` then read COMPLETE while those
|
|
322
|
+
// memories stayed blind.
|
|
323
|
+
//
|
|
324
|
+
// The gate is per FILL, not per id, because a `ChunkFailure`'s offsets are
|
|
325
|
+
// into the embedder's own deduped batch and do not address these ids. So a
|
|
326
|
+
// fill that mixed an isolated 400 with a 500 elsewhere still charges the 500's
|
|
327
|
+
// victims — strictly better than charging every failure, and the residue is
|
|
328
|
+
// bounded by a run that saw poison at all. It is named in INTERFACE-GAPS.
|
|
329
|
+
const itemBlamed = itemAttributable(input.embedder);
|
|
330
|
+
// ONE read of the counters, not one per id — the same bargain `missingVectors`
|
|
331
|
+
// makes two levels down.
|
|
332
|
+
let counters: Map<string, string>;
|
|
333
|
+
try {
|
|
334
|
+
counters = store.metaWithPrefix(EMBED_FAILED_PREFIX);
|
|
335
|
+
} catch {
|
|
336
|
+
counters = new Map<string, string>();
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
let embedded = 0;
|
|
340
|
+
let failed = 0;
|
|
341
|
+
// THE PER-ID GIVE-UP COUNTER (I33). An id that fails `EMBED_SKIP_AFTER` runs
|
|
342
|
+
// ON ITS OWN TEXT stops being offered by `missingVectors`, so one poisoned row
|
|
343
|
+
// cannot hold the head of a stable queue forever. Cleared the moment it lands,
|
|
344
|
+
// and by `verify --retry-skipped` — which is the remedy a repaired title
|
|
345
|
+
// needs, because a skipped id is never offered again and so cannot clear
|
|
346
|
+
// itself. Staged here and written as ONE transaction below.
|
|
347
|
+
const moves: [string, string][] = [];
|
|
348
|
+
for (const id of wanted) {
|
|
349
|
+
let landed = false;
|
|
350
|
+
try {
|
|
351
|
+
landed = store.embedOne(id).vector;
|
|
352
|
+
} catch {
|
|
353
|
+
landed = false;
|
|
354
|
+
}
|
|
355
|
+
if (landed) embedded += 1;
|
|
356
|
+
else failed += 1;
|
|
357
|
+
const key = `${EMBED_FAILED_PREFIX}${id}`;
|
|
358
|
+
const now = Number(counters.get(key) ?? "0");
|
|
359
|
+
if (landed) {
|
|
360
|
+
// Zero rather than deleted: `meta` has no delete on the write seam's
|
|
361
|
+
// allowlist, and a zero reads identically everywhere it is consulted.
|
|
362
|
+
// Nothing is written for the healthy case, which is every id on a good day.
|
|
363
|
+
if (now !== 0) moves.push([key, "0"]);
|
|
364
|
+
} else if (itemBlamed) {
|
|
365
|
+
moves.push([key, String(now + 1)]);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
writeCounters(counterpart, store, moves, emit);
|
|
369
|
+
return done("ran", embedded, failed, wanted.length, codes);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** Did the last fill blame any ONE INPUT? Only then may a counter climb. */
|
|
373
|
+
function itemAttributable(embedder: LiveEmbedder): boolean {
|
|
374
|
+
try {
|
|
375
|
+
return embedder.stats().lastFailures.some((f) => f.item === true);
|
|
376
|
+
} catch {
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** The distinct `code[:status]` pairs of the last fill, joined. Never text. */
|
|
382
|
+
function codesOf(embedder: LiveEmbedder): string {
|
|
383
|
+
try {
|
|
384
|
+
const seen = new Set<string>();
|
|
385
|
+
for (const f of embedder.stats().lastFailures) {
|
|
386
|
+
seen.add(f.status === undefined ? f.code : `${f.code}:${String(f.status)}`);
|
|
387
|
+
}
|
|
388
|
+
return [...seen].join(",");
|
|
389
|
+
} catch {
|
|
390
|
+
return "";
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* The run's counter moves, as ONE box-2 transaction.
|
|
396
|
+
*
|
|
397
|
+
* One `setMeta` per id was one write transaction — one lock acquisition — per
|
|
398
|
+
* id, at a boundary where this adapter has measured six overlapping workers
|
|
399
|
+
* against a 5 s busy timeout, and on exactly the run where things are already
|
|
400
|
+
* going wrong. A write that loses that lock costs the counters, never the run
|
|
401
|
+
* (§5 G2), which is why the whole thing sits inside one `try`.
|
|
402
|
+
*/
|
|
403
|
+
function writeCounters(
|
|
404
|
+
counterpart: Counterpart,
|
|
405
|
+
store: Counterpart["store"],
|
|
406
|
+
moves: readonly (readonly [string, string])[],
|
|
407
|
+
emit: Emit,
|
|
408
|
+
): void {
|
|
409
|
+
if (counterpart.observer || moves.length === 0) return;
|
|
410
|
+
try {
|
|
411
|
+
store.setMetaMany(moves);
|
|
412
|
+
} catch (err) {
|
|
413
|
+
emit("vectors.backfill.count.failed", { code: err instanceof Error ? err.name : "UNKNOWN" });
|
|
414
|
+
}
|
|
415
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# `adapters/cli/` — CONTRACT
|
|
2
|
+
|
|
3
|
+
## 1. Purpose
|
|
4
|
+
|
|
5
|
+
The `counterparts` command: status, install, and the owner-only operations — removal,
|
|
6
|
+
export, backup and restore — that no model-reachable path may perform.
|
|
7
|
+
|
|
8
|
+
## 2. Brain analog
|
|
9
|
+
|
|
10
|
+
None, and deliberately so. **Named deviation** (constitution line 12): humans have no
|
|
11
|
+
console on their own memory — no inspection of every unfalsifiable anchor, no deliberate
|
|
12
|
+
erasure, no export. This module is the improvement over the biological original that
|
|
13
|
+
constitution lines 4 and 6 promise: the self is **governed and owner-visible**, and the
|
|
14
|
+
owner owns the data.
|
|
15
|
+
|
|
16
|
+
## 3. Keeps
|
|
17
|
+
|
|
18
|
+
- **Destruction lives in exactly one place, and a caller-universality test pins who may
|
|
19
|
+
reach it.** [v1] behavioral-spec §16 G1–G2, earned-mechanism #14 — *no model-reachable
|
|
20
|
+
path may import it, and that test failing is the point.*
|
|
21
|
+
- **Removal is recorded, and the record is canonical, append-only, and carries no body and
|
|
22
|
+
no content hash.** [v1] §16 G7–G9, scar §2.20 — a hash of low-entropy content is
|
|
23
|
+
brute-forceable, which would make the record of removal a leak of the thing removed.
|
|
24
|
+
- **Removal is ordered so every crash point is safe** — at each moment the memory is fully
|
|
25
|
+
alive, or dark *and recorded* — and a failed record append means nothing moves. [v1] §16
|
|
26
|
+
G10–G11.
|
|
27
|
+
- **Everything that must READ the doomed content happens before anything is chased.** [v1]
|
|
28
|
+
§16 G13 — v1 named this bug: chasing copies first made every span unidentifiable.
|
|
29
|
+
- **Chase every surface, including the derived association graph.** [v1] §16 G14 — an
|
|
30
|
+
erased id left in the learned graph keeps *conducting* activation between its former
|
|
31
|
+
neighbors. **The surfaces on the rows floor are: the row and its versions (blanked in one
|
|
32
|
+
transaction), the edges, the prospective windows, the gate rows, box 3, both databases'
|
|
33
|
+
write-ahead logs and freed pages, `remember/`'s span buffer, and — since 2026-09-20 —
|
|
34
|
+
`journal/`, the episode journal's derived markdown copy.** Each is named in the report at
|
|
35
|
+
its count, **including at zero**: a surface that is silent when it is empty is the silent
|
|
36
|
+
partial success below. A copy the chase cannot reach is named under `unchased` with a
|
|
37
|
+
sentence saying what is still where; a chapter of the counterpart's own journal that
|
|
38
|
+
merely QUOTES the removed words is named under `leftAlone`, by episode id, the way a spans
|
|
39
|
+
echo is — nothing failed to be reached, and removing an account of a day is its own
|
|
40
|
+
decision with its own id.
|
|
41
|
+
- **No silent partial success**, and a contamination scan returns **ids only** — printing
|
|
42
|
+
the matches would re-leak exactly what is being erased. [v1] §16 G15.
|
|
43
|
+
- **Removal targets are restricted to memory-bearing roots.** [v1] §16 G16 — the archive,
|
|
44
|
+
backups, the graph, and the removal record itself are never nameable targets, so a typo
|
|
45
|
+
cannot point removal at the record of removal.
|
|
46
|
+
- **A removed memory cannot be silently resurrected**, via a deny-list consulted at load
|
|
47
|
+
and rebuild; a stray copy is skipped and logged, never deleted. [v1] §16 G12.
|
|
48
|
+
- **Catastrophe is covered separately, cheaply, and non-fatally**: rotated local snapshots,
|
|
49
|
+
an **allowlist not a denylist**, never leaving the machine, never throwing. [v1] §16 G18.
|
|
50
|
+
- **Dry run is the default for anything destructive**, with an interactive confirmation, and
|
|
51
|
+
the writer's lock taken only *after* the confirmation, then reload and re-plan under it.
|
|
52
|
+
[v1] scar §2.13.
|
|
53
|
+
- **Wall-clock, not active days, for any cooling-off.** [v1] §16's note on the released
|
|
54
|
+
ceremony — *a week of not using the machine must still be a week of second thoughts*, and
|
|
55
|
+
an immediate-destroy setting was rejected in v1 because it would delete the only property
|
|
56
|
+
that made the operation safe to have.
|
|
57
|
+
- **A machine-readable pass record that a runtime switch actually reads.** [v1] §17.2 — the
|
|
58
|
+
ambient path refuses to turn on until a passing run is recorded. *The gate is not a
|
|
59
|
+
document; it is a precondition.*
|
|
60
|
+
- **Everything permanent is enumerable and inspectable on demand — a list, not a cadence.**
|
|
61
|
+
[v1] §14.1 G9, earned 2026-08-24.
|
|
62
|
+
|
|
63
|
+
## 4. Drops / simplifies
|
|
64
|
+
|
|
65
|
+
- **The staged quarantine → cooling-off → chase-every-copy erase ceremony is released**
|
|
66
|
+
(owner rescope 3, settled): 871 lines, never production-fired, no designated target since
|
|
67
|
+
2026-07-29. What replaces it is **plain owner-initiated removal plus a record** — loud,
|
|
68
|
+
recorded, unreachable from any model path. Every guarantee in §3 survives the release;
|
|
69
|
+
the staging does not.
|
|
70
|
+
- **Forever-archive becomes bounded versioning** (owner rescope 3, settled). Superseded
|
|
71
|
+
rows retain ~90 lived days.
|
|
72
|
+
- **Local-only absolutism is released; the property is no silent egress** (owner rescope 2,
|
|
73
|
+
settled). `export` is therefore a first-class owner operation: **explicit owner action,
|
|
74
|
+
encrypted, owner-keyed**, in portable formats readable in any editor. Nothing leaves the
|
|
75
|
+
machine any other way, and the core has no egress path at all.
|
|
76
|
+
- **Zero runtime dependencies as a vow is released.** **PROPOSED** — owner call at
|
|
77
|
+
check-in. It was a proxy for constitution line 10 that already needed an exemption in v1,
|
|
78
|
+
and v2 ships as a distributable package where dependency hygiene is judgment. The default
|
|
79
|
+
stays zero.
|
|
80
|
+
|
|
81
|
+
## 5. Contract
|
|
82
|
+
|
|
83
|
+
**Inputs** — owner commands: `status`, `install`, `on`/`off`, `protected` (list),
|
|
84
|
+
`remove <id>`, `export`, `backup`, `restore`, `self-page` (2026-09-18), `start-fresh`
|
|
85
|
+
(2026-09-20); interactive confirmation; the data directory.
|
|
86
|
+
*`start-fresh` is the second command in this module that asks a human before it acts, and
|
|
87
|
+
the first whose danger is not deletion but MOVEMENT. It resolves its store from the host
|
|
88
|
+
CONFIGURATION rather than from `--dir`, which it refuses in words: the store that matters
|
|
89
|
+
is the one the hooks and the MCP server open, and a second answer on the command line is
|
|
90
|
+
how the wrong one would get moved.*
|
|
91
|
+
*`self-page` is deliberately NOT on `OWNER_OPS`, and it is the second command with a
|
|
92
|
+
reason of its own for that (`scope` is the first). It both READS and writes: reading the
|
|
93
|
+
page must work from an instrument, because "what does my page actually say" is the first
|
|
94
|
+
question anyone asks when the wake looks wrong, and a stood-down console is what is running
|
|
95
|
+
while they ask it. The refusal therefore lives at the WRITE, inside `self/#revisePage`, in
|
|
96
|
+
the same sentence every other write refuses in.*
|
|
97
|
+
*It is also the ONLY door that unwrites a page (`--clear`) or puts an earlier one back
|
|
98
|
+
(`--restore <seq>`); no MCP tool reaches either. `remove` refuses the page row by name and
|
|
99
|
+
points here — removal tombstones a row, and the schema index reads every schema row's
|
|
100
|
+
prose at open, so removing the page (or the identity core, which has had the same exposure
|
|
101
|
+
since it shipped) leaves a store that will not open, with the wake hook swallowing the
|
|
102
|
+
error so the symptom is silence.*
|
|
103
|
+
**Outputs** — human-readable output; durable state changes for owner operations only;
|
|
104
|
+
snapshots and exports; the removal record; telemetry by reference.
|
|
105
|
+
|
|
106
|
+
**Guarantees** — **[M]** mechanized, **[A]** advisory:
|
|
107
|
+
|
|
108
|
+
1. **[M] The destruction path is importable only from this directory**, asserted by a
|
|
109
|
+
caller-universality test over the import graph. No core module, no adapter, no model
|
|
110
|
+
path reaches it.
|
|
111
|
+
2. **[M] Destructive commands default to dry run and require interactive confirmation**,
|
|
112
|
+
and take the writer's lock only after confirmation, then reload and re-plan under it.
|
|
113
|
+
3. **[M] Every path comparison resolves and realpaths both sides before comparing**, and no
|
|
114
|
+
tool honors a pre-set data-directory environment variable when it claims a throwaway
|
|
115
|
+
directory (scar §2.13 — v1's migration guard was a raw string comparison, and
|
|
116
|
+
`--out ~/.bansai/` with a trailing slash pointed it at the live store and mass-wrote
|
|
117
|
+
~11K files).
|
|
118
|
+
4. **[M] A canonical database is backed up through the database's own backup API or
|
|
119
|
+
`VACUUM INTO`, never a file copy.** A restore test opens the copy and reads a row written
|
|
120
|
+
inside the pre-copy write window. **This is the sharpest scar in the list** (§2.11):
|
|
121
|
+
v1 copied its SQLite file without a WAL checkpoint and it was harmless *because the
|
|
122
|
+
database was a declared rebuildable cache* — and rescope 1 is precisely the removal of
|
|
123
|
+
that mitigation, which promotes the same flaw to canonical-data loss.
|
|
124
|
+
5. **[M] Every top-level path in the data directory is either in the backup set or on an
|
|
125
|
+
explicit documented exclusion list**, and adding a directory breaks the build until it is
|
|
126
|
+
classified. Documentation that says "whole store" is checked against the copy list by
|
|
127
|
+
that same test (scar §2.11 — v1's allowlist landed hours before the episode directory
|
|
128
|
+
existed and silently omitted the canonical journal for three weeks).
|
|
129
|
+
6. **[M] The archive tree is deliberately excluded from snapshots** — archive-on-overwrite
|
|
130
|
+
history is itself the redundancy layer, and snapshotting it copies an unbounded,
|
|
131
|
+
already-redundant tree into every snapshot.
|
|
132
|
+
*Correction (2026-08-25, closing the filed contradiction): as v2 shipped it, there is
|
|
133
|
+
no unbounded archive tree — rescope 3 replaced it with the `versions/` directory under
|
|
134
|
+
BOUNDED retention (H lived days). Bounded canonical-until-expiry state belongs IN the
|
|
135
|
+
backup set, and LAYOUT says so; this guarantee's premise applied to v1's shape. The
|
|
136
|
+
implementation followed LAYOUT, which guarantee 5 makes the single source of truth.*
|
|
137
|
+
*Second correction (2026-09-20, the floor): there is no `versions/` directory
|
|
138
|
+
either. An archived version is a ROW in `counterparts.sqlite`, so it is inside
|
|
139
|
+
the database the snapshot copies through `VACUUM INTO` and there is nothing
|
|
140
|
+
left for this guarantee to exclude. Still bounded, still 90 lived days — and
|
|
141
|
+
the prune now deletes the WORDS rather than a note about a file (owner ruling
|
|
142
|
+
1, 2026-09-18; `store/NOTES.md` 2026-09-20).*
|
|
143
|
+
7. **[M] `export` is the only egress**, and it is explicit, encrypted, and owner-keyed. A
|
|
144
|
+
test asserts no other module opens a network socket to a non-model, non-embedding
|
|
145
|
+
endpoint.
|
|
146
|
+
*Extended 2026-09-20 (F7, owner ruling 4 of 2026-09-18).* It takes two shapes and the
|
|
147
|
+
report names which ran: the whole store as one SQLite file through `VACUUM INTO`, or
|
|
148
|
+
`--markdown`, a readable tree — one file per memory grouped by kind, the journal as is,
|
|
149
|
+
the self page as its own file, `--with-versions` for every earlier wording. **Filenames
|
|
150
|
+
are ids, never titles.** The markdown tree **omits confidential rows unless
|
|
151
|
+
`--include-confidential`, and says how many it omitted** — in the terminal and in a
|
|
152
|
+
manifest inside the tree, at zero as well, because a directory that does not say what
|
|
153
|
+
is missing from it reads as complete. Removed rows are never exported; a row that will
|
|
154
|
+
not render is named by its id rather than silently absent. **`--markdown --passphrase`
|
|
155
|
+
is supported properly** — the tree is rendered into memory, sealed, and only then
|
|
156
|
+
written, so that path has no scratch anywhere. It refuses a non-empty target unless
|
|
157
|
+
told, refuses a target inside the store or a live v1 store, and refuses a store this
|
|
158
|
+
build cannot open in the floor's own sentence, touching nothing on either side. One
|
|
159
|
+
durable `store.export` row carries counts and flags and **not the target path**.
|
|
160
|
+
*`export` is NOT on `OWNER_OPS` (2026-09-20): an export reads the store and writes
|
|
161
|
+
outside it, so under `--observer` the copy is made, the durable row is not, and the
|
|
162
|
+
report says which.*
|
|
163
|
+
8. **[M] Backups never leave the machine and never throw** — a backup problem must not
|
|
164
|
+
block a consolidation cycle.
|
|
165
|
+
9. **[M] Reads are pure.** Inspecting the protected list or the census writes nothing and
|
|
166
|
+
logs nothing; loudness about corruption belongs at mutation time (§14.1 G8).
|
|
167
|
+
10. **[M] The runtime switch reads a machine-readable pass record** and refuses to enable a
|
|
168
|
+
gated channel without one.
|
|
169
|
+
11. **[A] Command names, flag shapes, and output formatting are surface** and may change
|
|
170
|
+
without touching a core contract.
|
|
171
|
+
12. **[M] Owner-in-the-loop is a short, named list — currently two items: removal, and
|
|
172
|
+
`start-fresh`.** Candidates for the list get discussed, never assumed (§14.3).
|
|
173
|
+
Everything else that can be safely autonomous is. *`start-fresh` joined it on
|
|
174
|
+
2026-09-20 for a reason removal does not share: what it moves cannot be checked by
|
|
175
|
+
this process. A session holding the store open by a file handle goes on writing into
|
|
176
|
+
the parked directory after the rename, and no cheap read can see an idle one — so the
|
|
177
|
+
human is not a formality here, he is the only instrument that can answer.*
|
|
178
|
+
13. **[M] `start-fresh` never deletes and never opens the store it parks** — not for
|
|
179
|
+
writing, not read-only. The only mutating call in `cli/start-fresh.ts` is `rename`,
|
|
180
|
+
and the parked directory is proved byte-identical afterwards by a fingerprint over
|
|
181
|
+
every file including the `-wal` and the `-shm` and over every directory's entry list.
|
|
182
|
+
*Read-only is not exempt: under WAL, committed pages live in the `-wal` until somebody
|
|
183
|
+
checkpoints them, and an opener is somebody.*
|
|
184
|
+
14. **[M] `start-fresh` asks the FILESYSTEM whether a store is there, never the floor.**
|
|
185
|
+
"The directory exists and holds something", never `storeExists()`. *Since F5 that
|
|
186
|
+
function answers true for a pre-rows store too, so the two readings now agree on an
|
|
187
|
+
old-floor store — and still differ on a half-made one holding only a `cache/`, where
|
|
188
|
+
`storeExists` says "no store" and would let `install` mint one beside a stale box 3.
|
|
189
|
+
Proved against four directories: absent, empty, old floor, new floor, and one wearing
|
|
190
|
+
both database names.* The command's only reading OF the floor is `preRowsMarkersIn`
|
|
191
|
+
— filenames, never an open — and it is used to SAY which floor the parked store is
|
|
192
|
+
on, never to decide anything.
|
|
193
|
+
15. **[M] `start-fresh` never creates a store at a path nobody named.** The cold arm's
|
|
194
|
+
landing place is computed from the CONFIGURATION'S own directory and an empty
|
|
195
|
+
environment, printed before it is used, pinned onto `install`, and refused if
|
|
196
|
+
anything is there. *A mistyped `--config` used to fall through to
|
|
197
|
+
`$COUNTERPARTS_DATA_DIR`, else `~/.counterparts/store` — the live one — and stamp it
|
|
198
|
+
"began today" (N1 review B1). The `Store:` line is never blank, because a blank one
|
|
199
|
+
is what let "there is no store at that path" and "Store already present at …" share a
|
|
200
|
+
screen.*
|
|
201
|
+
16. **[M] The blank store is built before anything is parked, and arrives with one
|
|
202
|
+
rename.** An `install` that refuses therefore costs a temporary directory rather than
|
|
203
|
+
leaving the configuration pointing at nothing, and the window in which another
|
|
204
|
+
process can mint a store at `dataDir` is two renames wide. A destination that is not
|
|
205
|
+
empty at the second rename is a REFUSAL naming all three directories, never a merge.
|
|
206
|
+
17. **[M] The way back is printed from the plan that RAN, and every line refuses rather
|
|
207
|
+
than nesting.** The date is frozen for the run; a re-read that finds the ground moved
|
|
208
|
+
refuses instead of executing a plan nobody read; the block is re-printed after the
|
|
209
|
+
renames and in every failure branch. *A bare `mv a b` onto an existing directory
|
|
210
|
+
moves `a` inside `b` and reports success — measured — so each printed line is
|
|
211
|
+
guarded, and `start-fresh --undo` does the same three moves without a shell.*
|
|
212
|
+
18. **[M] Both directions run ONE guard ring, and a test asserts they answer identically.**
|
|
213
|
+
`start-fresh.ts#pathGuard` is present / absolute / not a forbidden root by either
|
|
214
|
+
spelling / not a root / not the home directory / not holding the configuration / not a
|
|
215
|
+
symlink, and every path either direction would rename goes through it. *`--undo`
|
|
216
|
+
shipped as new code that ran none of the forward refusals and renamed inside a
|
|
217
|
+
`~/.bansai` with no tampering at all (confirmation review BLOCKER-1). Two
|
|
218
|
+
implementations of "what may I rename" is how they drifted; one function plus a test
|
|
219
|
+
comparing their sentences is what stops it.*
|
|
220
|
+
19. **[M] A value read back out of a store is DATA, never an instruction.**
|
|
221
|
+
`store.previous.parked` is a `meta` row anything with the store open can write, so
|
|
222
|
+
`--undo` pins its shape (`parkedSiblingRefusal`: a sibling of the store, wearing a name
|
|
223
|
+
this package writes) rather than trusting it. *Proved against the four crafted values
|
|
224
|
+
the review used: a forbidden root, the store's own parent, a symlink, and a name
|
|
225
|
+
nothing writes.*
|
|
226
|
+
20. **[M] Cut-over day is proved against a store the PINNED BUILD wrote, not a hand-made
|
|
227
|
+
one.** `test/old-floor-fixture.ts` extracts `floor/v5-last` and runs that build's own
|
|
228
|
+
`Store` API to produce a v5 store whose `-wal` holds the database its file does not.
|
|
229
|
+
`start-fresh` parks it byte-identical, its output never mentions `STORE_PRE_ROWS`
|
|
230
|
+
because nothing opened it, and the rollback lines *as printed* restore it — still
|
|
231
|
+
refused by name, still readable by the build that wrote it.
|
|
232
|
+
|
|
233
|
+
## 6. Scars honored
|
|
234
|
+
|
|
235
|
+
**E5** (the CLI is one side of the seam between locking domains — the owner console versus
|
|
236
|
+
the background worker — which is exactly where v1's surviving races clustered; a lock is
|
|
237
|
+
never held across a human prompt) · **§2.4** (every path that deletes or discards logs what
|
|
238
|
+
and how much) · **§2.11** (backup scope asserted against the layout; the canonical database
|
|
239
|
+
checkpointed, never copied) · **§2.13** (path guards resolve before they compare; no tool
|
|
240
|
+
silently accepts a pointer at real data) · **§2.17** (the removal path is a curation path,
|
|
241
|
+
and a curation path that has never fired is unproven — see open question 2) · **§2.19**
|
|
242
|
+
(permanence and write bar scale together — everything permanent is enumerable here) ·
|
|
243
|
+
**§2.20** (the removal record carries no body and no content hash).
|
|
244
|
+
|
|
245
|
+
## 7. Open questions
|
|
246
|
+
|
|
247
|
+
1. **Does `export` encrypt to a key the owner already has, or does it mint one?** Minting
|
|
248
|
+
is friendlier and is also how an owner ends up with a backup they cannot open.
|
|
249
|
+
2. **Removal has never fired in production, in any generation.** v1's erase machinery was
|
|
250
|
+
built, tested, and never once run in anger — which by scar §2.17's own criterion makes
|
|
251
|
+
it unproven rather than sound. v2 should either exercise it deliberately in bake-in or
|
|
252
|
+
carry it as declared-dormant-by-design, and say which.
|
|
253
|
+
3. **Is `restore` a supported operation or a documented manual procedure?** v1 had no
|
|
254
|
+
logged read-back of a backup ever, so there is no evidence its snapshots were usable.
|
|
255
|
+
Guarantee 4's restore test is the minimum; a real restore command is more.
|