counterparts 0.3.20 → 0.3.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/README.md +4 -1
- package/package.json +1 -1
- package/src/adapters/claude-code/CONTRACT.md +2 -2
- package/src/adapters/claude-code/bin/hook.ts +7 -1
- package/src/adapters/claude-code/bin/runner.ts +31 -14
- package/src/adapters/claude-code/doctor.ts +24 -11
- package/src/adapters/cli/commands-delete.ts +273 -0
- package/src/adapters/cli/commands-note.ts +1 -1
- package/src/adapters/cli/commands.ts +22 -3
- package/src/adapters/cli/help.ts +2 -0
- package/src/adapters/cli/removal.ts +1 -1
- package/src/adapters/config.ts +74 -0
- package/src/adapters/dashboard/web/actions.ts +21 -2
- package/src/adapters/dashboard/web/pages/memories/sections/tools.js +73 -3
- package/src/adapters/fired.ts +1 -1
- package/src/adapters/log/index.ts +21 -0
- package/src/adapters/mcp/server-words.ts +1 -1
- package/src/adapters/plugin.ts +31 -0
- package/src/adapters/sessions.ts +5 -2
- package/src/adapters/snapshots.ts +90 -1
- package/src/core/onboarding.ts +9 -6
- package/src/core/recall/CONTRACT.md +3 -1
- package/src/core/recall/INTERFACE-GAPS.md +1 -1
- package/src/core/recall/NOTES.md +14 -0
- package/src/core/recall/session.ts +40 -1
- package/src/core/remember/CONTRACT.md +14 -8
- package/src/core/remember/owes.ts +68 -28
- package/src/core/remember/owner-strike-seam.ts +6 -3
- package/src/core/remember/spans.ts +3 -2
- package/src/core/remember/tunables.ts +18 -5
- package/src/core/remember/write-up-seam.ts +2 -1
- package/src/core/store/index.ts +39 -0
- package/src/core/store/paths.ts +9 -2
|
@@ -5,7 +5,7 @@ entry names the owner, the workaround now in the code, and what the real fix loo
|
|
|
5
5
|
|
|
6
6
|
## 1. `store/` has no meta enumeration or expiry — gate-state rows are unbounded
|
|
7
7
|
|
|
8
|
-
**Closed 2026-09-24** — gate state is the `gate_session` table, one row per record with `last_day` (`store/operational.ts`), swept by `Store#pruneGateSessions
|
|
8
|
+
**Closed 2026-09-24** — gate state is the `gate_session` table, one row per record with `last_day` (`store/operational.ts`), swept by `Store#pruneGateSessions` — which, as of 2026-10-13, nothing on a live path calls. The rows' one piece of typed text, the carried cue tokens, is emptied by `clearIdleCarries` (NOTES §6); the rows themselves are still unbounded.
|
|
9
9
|
|
|
10
10
|
**Owner:** `store/`.
|
|
11
11
|
**Needed:** per-session gate state with a defined store AND lifetime (recall contract §5
|
package/src/core/recall/NOTES.md
CHANGED
|
@@ -76,6 +76,20 @@ every turn, scoped to one session, never emitted as telemetry. The decision reco
|
|
|
76
76
|
every event carry counts and hashes only — a cue token is turn text, and turn text is
|
|
77
77
|
exactly what telemetry may not carry. Revisit if the retention review disagrees.
|
|
78
78
|
|
|
79
|
+
**2026-10-13, the retention review's answer.** "Overwritten every turn" was true of a
|
|
80
|
+
session that keeps talking; a session that ended, or was killed, kept its last turn's
|
|
81
|
+
tokens for as long as its row lived — and `Store#pruneGateSessions`, the sweep meant to
|
|
82
|
+
end that, has no live caller. Policy since PR #468 is that what the person typed is never
|
|
83
|
+
kept past the retention ceiling (`retention.maxDays`, default 14). So the scalar row now
|
|
84
|
+
records when it was saved (`at`, in its JSON — no schema change), and the worker's every
|
|
85
|
+
run calls `clearIdleCarries`, which empties `carriedCues` in every session whose row is
|
|
86
|
+
older than the ceiling (a row with no `at` counts as old, which is what clears existing
|
|
87
|
+
stores). Only the carry: the turn count, refractory and per-memory rows are ids and
|
|
88
|
+
numbers, and stay. Not done at session end: the core boundary runs at every turn, and
|
|
89
|
+
there is no clean end signal; the sweep covers ended and killed sessions alike. The
|
|
90
|
+
other gate kinds hold no typed text: `surfaced`, `credited` and `asked` are memory ids,
|
|
91
|
+
`semantic` is `{id, score}` plus a model name, `judged` is a turn number.
|
|
92
|
+
|
|
79
93
|
## 7. Deliberately NOT built (Amendment 15 — complexity is earned)
|
|
80
94
|
|
|
81
95
|
- **Deliberate recall (§9.1)** — the explicit ask, its lower-confidence labeled tier and
|
|
@@ -34,7 +34,9 @@
|
|
|
34
34
|
* **Lifetime:** the session, then `Store.pruneGateSessions()` — a real retention
|
|
35
35
|
* sweep beside `pruneSupersededVersions`, which a meta keyspace could never have.
|
|
36
36
|
* `MAX_SESSION_RECORDS` still bounds the per-session record maps, applied on the
|
|
37
|
-
* write AND on the read, so neither direction can exceed it.
|
|
37
|
+
* write AND on the read, so neither direction can exceed it. (As of 2026-10-13
|
|
38
|
+
* nothing on a live path calls `pruneGateSessions`; the one piece that is the
|
|
39
|
+
* person's words, the carried cues, is emptied by `clearIdleCarries` below.)
|
|
38
40
|
* **Observer:** never written. An instrument deposits nothing, so its gate state
|
|
39
41
|
* lives and dies in the process (`Recall` holds it in memory and stands down at
|
|
40
42
|
* the write).
|
|
@@ -167,6 +169,9 @@ interface ScalarPayload {
|
|
|
167
169
|
affectFiredTurn: number | null;
|
|
168
170
|
carriedCues: string[];
|
|
169
171
|
carriedFromTurn: number;
|
|
172
|
+
/** When this row was saved, wall-clock ms (2026-10-13). Read only by
|
|
173
|
+
* `clearIdleCarries`; absent on rows saved before it, which it treats as old. */
|
|
174
|
+
at?: number;
|
|
170
175
|
}
|
|
171
176
|
|
|
172
177
|
export function loadGateState(store: Store, sessionId: string, max = Infinity): LoadResult {
|
|
@@ -253,6 +258,7 @@ export function saveGateState(store: Store, state: GateState, max: number): void
|
|
|
253
258
|
affectFiredTurn: state.affectFiredTurn,
|
|
254
259
|
carriedCues: state.carriedCues,
|
|
255
260
|
carriedFromTurn: state.carriedFromTurn,
|
|
261
|
+
at: store.now(),
|
|
256
262
|
} satisfies ScalarPayload),
|
|
257
263
|
},
|
|
258
264
|
];
|
|
@@ -282,6 +288,39 @@ export function saveGateState(store: Store, state: GateState, max: number): void
|
|
|
282
288
|
store.setGateRecords(rows);
|
|
283
289
|
}
|
|
284
290
|
|
|
291
|
+
/**
|
|
292
|
+
* TYPED WORDS LEAVE A QUIET SESSION (2026-10-13). `carriedCues` is the one
|
|
293
|
+
* piece of gate state that is the person's own words (up to `MAX_CUES` tokens
|
|
294
|
+
* from the last turn). It is overwritten every turn, but a session that ends,
|
|
295
|
+
* or is killed, keeps its last turn's tokens in the scalar row — and in every
|
|
296
|
+
* backup — for as long as the row lives. The policy is that what the person
|
|
297
|
+
* typed is never kept more than the retention ceiling (`retention.maxDays`,
|
|
298
|
+
* default 14, `remember/tunables.ts#RETENTION_MAX_MS`), so this empties the
|
|
299
|
+
* carry of every session whose row was last saved that long ago. Only the
|
|
300
|
+
* carry: the turn count, refractory and per-memory records (ids, not text)
|
|
301
|
+
* stay, so a session that comes back keeps its dedup and loses one turn of
|
|
302
|
+
* carry, which expires after a turn anyway. A row saved before `at` existed
|
|
303
|
+
* counts as old. An unreadable row is left as it is (it reads `unreadable`).
|
|
304
|
+
*
|
|
305
|
+
* Whole-store and cheap: only rows whose carry is non-empty are read.
|
|
306
|
+
* Called by the worker (`claude-code/bin/runner.ts`) before its daily copy.
|
|
307
|
+
*/
|
|
308
|
+
export function clearIdleCarries(store: Store, maxMs: number): number {
|
|
309
|
+
const cutoff = store.now() - maxMs;
|
|
310
|
+
return store.rewriteGateValues("scalar", SCALAR_REF, '"carriedCues":["', (value) => {
|
|
311
|
+
let parsed: Partial<ScalarPayload>;
|
|
312
|
+
try {
|
|
313
|
+
parsed = JSON.parse(value) as Partial<ScalarPayload>;
|
|
314
|
+
} catch {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
if (parsed === null || typeof parsed !== "object" || parsed.v !== GATE_STATE_VERSION) return null;
|
|
318
|
+
if (!Array.isArray(parsed.carriedCues) || parsed.carriedCues.length === 0) return null;
|
|
319
|
+
if (typeof parsed.at === "number" && parsed.at > cutoff) return null;
|
|
320
|
+
return JSON.stringify({ ...parsed, carriedCues: [] });
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
|
|
285
324
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
286
325
|
// The LAGGED SEMANTIC CUE — per-session, one turn old, on the same table
|
|
287
326
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
@@ -112,10 +112,11 @@ is that the ask is ambient (constitution line 8) and its coverage is measured, n
|
|
|
112
112
|
model deposited. A session that ends normally is never swept, so anything after its
|
|
113
113
|
last authored deposit is forgotten — by design (constitution 3: forget the trials),
|
|
114
114
|
but it is a real loss and it is this rule's price.
|
|
115
|
-
- **Those spans stay in the buffer — for a
|
|
116
|
-
session that ended normally; since 2026-09-23 RETENTION deletes them
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
- **Those spans stay in the buffer — for a few days.** Nothing consumes the spans of a
|
|
116
|
+
session that ended normally; since 2026-09-23 RETENTION deletes them after the
|
|
117
|
+
session ended, when it owes no write-up — 7 days until 2026-10-13, 3 since, and never
|
|
118
|
+
more than 14 after its last activity (§5 G15, `retention.ts`). Until then this was
|
|
119
|
+
open question 5 and the buffer grew without bound.
|
|
119
120
|
- **An idle-but-alive session past the window is indistinguishable from a crash** and
|
|
120
121
|
will be swept. If its author later writes, that stretch has twins after all — which
|
|
121
122
|
is the measurement `CRASH_STALE_MS` owes: count sessions swept-then-authored. The
|
|
@@ -252,8 +253,12 @@ INTERFACE-GAPS §2a; this module still never gates and never reads them).
|
|
|
252
253
|
and belongs to no single memory. It records counts and never a hash or a word
|
|
253
254
|
(§16 G9). One window is NAMED rather than closed: a worker already holding a claim in
|
|
254
255
|
memory finishes its arc (NOTES §14).
|
|
255
|
-
15. **[M] Raw transcript is kept
|
|
256
|
-
or the host still holds it open
|
|
256
|
+
15. **[M] Raw transcript is kept 3 days after a session ends, unless it owes a write-up
|
|
257
|
+
or the host still holds it open — and never more than 14 days after its last
|
|
258
|
+
activity, whatever else is true** (owner's ruling 2026-09-23, clocks reset by Mike
|
|
259
|
+
2026-10-13: 7 days → 3, and the ceiling added; both are defaults a host may change,
|
|
260
|
+
`RetentionSources.retentionMs` / `maxMs`, which the Claude Code adapter reads from
|
|
261
|
+
the configuration's `retention` block; `owes.ts`,
|
|
257
262
|
`retention.ts`, NOTES §16). ONE rule decides what is owed, and since 2026-09-30 it is
|
|
258
263
|
`core/coverage/`'s, read by `planRetention` once per session across every scope: an
|
|
259
264
|
unwritten stretch (pieces with no claim in `coverage.jsonl`) of three pieces over
|
|
@@ -264,14 +269,15 @@ INTERFACE-GAPS §2a; this module still never gates and never reads them).
|
|
|
264
269
|
session that owes is kept however old until it is written up or lapses, and one the host's registry still
|
|
265
270
|
holds open is kept for as long as the registry keeps its record; one that owes nothing
|
|
266
271
|
loses every text line — its turns, jots, the assistant's
|
|
267
|
-
replies, quarantine, claims —
|
|
272
|
+
replies, quarantine, claims — 3 days after the latest thing known about it. The
|
|
268
273
|
deletion goes through the strike (G14) naming whole sessions, recorded
|
|
269
274
|
`by: "retention"` with counts only, from the background worker alone
|
|
270
275
|
(`remember/index.ts` does not export it; a test pins its one importer), once per date
|
|
271
276
|
behind an `O_EXCL` latch, before the day's snapshot, leaving one `remember.prune` row
|
|
272
277
|
(`deleted`, `keptOwed`, `keptYoung`, `keptLive`, `failed`). Cursors, boundaries,
|
|
273
278
|
coverage, proposals and the ledgers are not text and are kept. Raw text therefore lives
|
|
274
|
-
|
|
279
|
+
at most 14 days in the store (by default), and none of it in a snapshot: since
|
|
280
|
+
2026-10-13 `spans/` is out of the backup set (`store/paths.ts#LAYOUT`). The only way
|
|
275
281
|
out of owing — the write-up mark — is a grant behind a pinned seam
|
|
276
282
|
(`write-up-seam.ts`), refusing an unknown scope, a free-text author and a session with
|
|
277
283
|
no text, and a run is visible from the moment it holds its date (`STARTED`). Its two
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WHAT A SESSION OWES — the read-only half of raw-transcript retention.
|
|
3
3
|
*
|
|
4
|
-
* Owner's ruling 2026-09-23 (roadmap B3)
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Owner's ruling 2026-09-23 (roadmap B3), clocks reset by Mike 2026-10-13:
|
|
5
|
+
* **a session's captured text is deleted 3 days after it was written up and
|
|
6
|
+
* ended, when nothing is owed; a session that owes a write-up waits until it
|
|
7
|
+
* is written up — but never more than 14 calendar days after its last
|
|
8
|
+
* activity.** Both numbers are defaults a host may change
|
|
9
|
+
* (`RetentionSources`). This file decides; it never deletes.
|
|
7
10
|
* The deleting half is `retention.ts`, which only the background worker may
|
|
8
11
|
* import and which `index.ts` does NOT re-export (PR #189 review, B1): holding
|
|
9
12
|
* a `Counterpart` — and so its public `SpanBuffer` — reaches the plan and never
|
|
@@ -28,16 +31,24 @@
|
|
|
28
31
|
* not deleted while the registry holds it (review m10): an idle-but-alive
|
|
29
32
|
* session is not an ended one. That lasts only as long as the record does, and
|
|
30
33
|
* the registry forgets a record 7 days after its last write
|
|
31
|
-
* (`adapters/sessions.ts#pruneSessions`) —
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
+
* (`adapters/sessions.ts#pruneSessions`) — longer than the 3-day clock since
|
|
35
|
+
* 2026-10-13, so for those days this guard, not the capture clock, is what
|
|
36
|
+
* keeps an open session's text (re-review R8). The ceiling overrides it too: a
|
|
37
|
+
* record still open 14 days after the session's last activity keeps nothing.
|
|
34
38
|
*
|
|
35
39
|
* ── THE CLOCK ─────────────────────────────────────────────────────────────
|
|
36
40
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
+
* Three days by default (`TUNABLES.RETENTION_MS`, or the host's
|
|
42
|
+
* `retentionMs`) from the LATEST thing known about the session anywhere in the
|
|
43
|
+
* store: its last capture or boundary in any scope, its write-up mark, its
|
|
44
|
+
* registry end. It is the buffer's own clock. A lapsed stretch owes nothing,
|
|
45
|
+
* so its text goes on the same clock.
|
|
46
|
+
*
|
|
47
|
+
* And THE CEILING, checked first: fourteen days by default
|
|
48
|
+
* (`TUNABLES.RETENTION_MAX_MS`, or the host's `maxMs`) from the session's LAST
|
|
49
|
+
* ACTIVITY — its last capture or boundary, not a later write-up or end, so
|
|
50
|
+
* nothing that happens afterwards can extend it. Past it the text is deleted
|
|
51
|
+
* whatever else is true: owed, held open, or not.
|
|
41
52
|
*
|
|
42
53
|
* Every failure to read a fact moves toward KEEPING: a host that cannot answer
|
|
43
54
|
* is read as holding the session open.
|
|
@@ -79,9 +90,8 @@ export interface HostSessionEvidence {
|
|
|
79
90
|
/**
|
|
80
91
|
* The host's registry holds a record for this session with no end. Kept while
|
|
81
92
|
* it does — and ONLY while it does: the registry drops a record 7 days after
|
|
82
|
-
* its last write (`adapters/sessions.ts#pruneSessions`), the
|
|
83
|
-
*
|
|
84
|
-
* recently active session. That one is the capture clock (`kept-young`).
|
|
93
|
+
* its last write (`adapters/sessions.ts#pruneSessions`), and the ceiling
|
|
94
|
+
* (`maxMs`) overrides it either way.
|
|
85
95
|
*/
|
|
86
96
|
readonly open: boolean;
|
|
87
97
|
/** The registry's end, epoch ms. */
|
|
@@ -94,19 +104,30 @@ export const NO_HOST_EVIDENCE: HostSessionEvidence = {
|
|
|
94
104
|
};
|
|
95
105
|
|
|
96
106
|
/** Everything retention reads from outside the buffer: the host's evidence,
|
|
97
|
-
*
|
|
107
|
+
* the zone the store names its days in, and the two clocks. */
|
|
98
108
|
export interface RetentionSources {
|
|
99
109
|
host(session: string): HostSessionEvidence;
|
|
100
110
|
readonly zone: string;
|
|
111
|
+
/** Kept this long after the latest of activity, write-up and end, when
|
|
112
|
+
* nothing is owed. `TUNABLES.RETENTION_MS` when absent. */
|
|
113
|
+
readonly retentionMs?: number;
|
|
114
|
+
/** Never kept longer than this after the last activity, whatever is owed.
|
|
115
|
+
* `TUNABLES.RETENTION_MAX_MS` when absent. */
|
|
116
|
+
readonly maxMs?: number;
|
|
101
117
|
}
|
|
102
118
|
|
|
119
|
+
/** A clock a host handed over, or the default when it is not a positive
|
|
120
|
+
* finite number — a bad value never means "delete now". */
|
|
121
|
+
const clockOr = (ms: number | undefined, fallback: number): number =>
|
|
122
|
+
typeof ms === "number" && Number.isFinite(ms) && ms > 0 ? ms : fallback;
|
|
123
|
+
|
|
103
124
|
/**
|
|
104
125
|
* The sources as a host supplies them. Never throws: a host that cannot answer
|
|
105
126
|
* may be holding the session open, so it is read as open.
|
|
106
127
|
*/
|
|
107
128
|
export function retentionSources(
|
|
108
129
|
store: Partial<Pick<Store, "zone">>,
|
|
109
|
-
opts: { host?: (session: string) => HostSessionEvidence } = {},
|
|
130
|
+
opts: { host?: (session: string) => HostSessionEvidence; retentionMs?: number; maxMs?: number } = {},
|
|
110
131
|
): RetentionSources {
|
|
111
132
|
let zone: string;
|
|
112
133
|
try {
|
|
@@ -123,6 +144,8 @@ export function retentionSources(
|
|
|
123
144
|
}
|
|
124
145
|
},
|
|
125
146
|
zone,
|
|
147
|
+
retentionMs: clockOr(opts.retentionMs, TUNABLES.RETENTION_MS),
|
|
148
|
+
maxMs: clockOr(opts.maxMs, TUNABLES.RETENTION_MAX_MS),
|
|
126
149
|
};
|
|
127
150
|
}
|
|
128
151
|
|
|
@@ -137,7 +160,7 @@ export interface HeldSession {
|
|
|
137
160
|
readonly scopes: readonly string[];
|
|
138
161
|
readonly facts: WriteUpFacts;
|
|
139
162
|
/** It owes a write-up — `coverage/`'s rule, and the only thing that keeps
|
|
140
|
-
* its text past
|
|
163
|
+
* its text past the retention clock (never past the ceiling). */
|
|
141
164
|
readonly owes: boolean;
|
|
142
165
|
/** It owes, and what it owes is small: one line is enough. */
|
|
143
166
|
readonly small: boolean;
|
|
@@ -253,13 +276,24 @@ export function planRetention(buffer: SpanBuffer, sources: RetentionSources): He
|
|
|
253
276
|
};
|
|
254
277
|
const owes = entry?.owed === true && !facts.writtenUp;
|
|
255
278
|
const clockFrom = Math.max(t.lastActivityAt, t.writtenUpAt ?? 0, h.endedAt ?? 0);
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
279
|
+
// THE CEILING FIRST: past it nothing keeps the text — not a debt, not an
|
|
280
|
+
// open record. Read from the last activity alone, so a late write-up or a
|
|
281
|
+
// late end cannot push it out. A host's clocks are read through
|
|
282
|
+
// `clockOr` again, so a hand-built `RetentionSources` with a bad number
|
|
283
|
+
// falls back rather than deleting everything.
|
|
284
|
+
const maxMs = clockOr(sources.maxMs, TUNABLES.RETENTION_MAX_MS);
|
|
285
|
+
const retentionMs = clockOr(sources.retentionMs, TUNABLES.RETENTION_MS);
|
|
286
|
+
// A session whose every moment failed to read (0) is not judged by it.
|
|
287
|
+
const verdict: RetentionVerdict =
|
|
288
|
+
t.lastActivityAt > 0 && now - t.lastActivityAt >= maxMs
|
|
289
|
+
? "deleted"
|
|
290
|
+
: h.open
|
|
291
|
+
? "kept-live"
|
|
292
|
+
: owes
|
|
293
|
+
? "kept-owed"
|
|
294
|
+
: now - clockFrom < retentionMs
|
|
295
|
+
? "kept-young"
|
|
296
|
+
: "deleted";
|
|
263
297
|
out.push({
|
|
264
298
|
session,
|
|
265
299
|
scopes: [...t.scopes].sort(),
|
|
@@ -291,7 +325,7 @@ export interface RetentionReport {
|
|
|
291
325
|
readonly deleted: number;
|
|
292
326
|
/** ...kept because they owe a write-up, however old. */
|
|
293
327
|
readonly keptOwed: number;
|
|
294
|
-
/** ...kept because their
|
|
328
|
+
/** ...kept because their retention clock (3 days by default) has not run yet. */
|
|
295
329
|
readonly keptYoung: number;
|
|
296
330
|
/** ...kept because the host's registry holds them open. */
|
|
297
331
|
readonly keptLive: number;
|
|
@@ -304,8 +338,13 @@ export interface RetentionReport {
|
|
|
304
338
|
readonly bytes: number;
|
|
305
339
|
}
|
|
306
340
|
|
|
307
|
-
/** The payload of one `remember.prune` row.
|
|
308
|
-
|
|
341
|
+
/** The payload of one `remember.prune` row. `clocks` is the run's own, when
|
|
342
|
+
* the caller has them; the defaults otherwise. */
|
|
343
|
+
export function retentionRow(
|
|
344
|
+
report: RetentionReport,
|
|
345
|
+
date: string,
|
|
346
|
+
clocks: Partial<Pick<RetentionSources, "retentionMs" | "maxMs">> = {},
|
|
347
|
+
): Record<string, string | number> {
|
|
309
348
|
return {
|
|
310
349
|
date,
|
|
311
350
|
reason: report.reason,
|
|
@@ -317,7 +356,8 @@ export function retentionRow(report: RetentionReport, date: string): Record<stri
|
|
|
317
356
|
failed: report.failed,
|
|
318
357
|
lines: report.lines,
|
|
319
358
|
bytes: report.bytes,
|
|
320
|
-
retentionDays: Math.round(TUNABLES.RETENTION_MS / 86_400_000),
|
|
359
|
+
retentionDays: Math.round(clockOr(clocks.retentionMs, TUNABLES.RETENTION_MS) / 86_400_000),
|
|
360
|
+
maxDays: Math.round(clockOr(clocks.maxMs, TUNABLES.RETENTION_MAX_MS) / 86_400_000),
|
|
321
361
|
};
|
|
322
362
|
}
|
|
323
363
|
|
|
@@ -390,7 +430,7 @@ export function retentionRuns(store: Pick<Store, "eventLog" | "livedDay">): Rete
|
|
|
390
430
|
|
|
391
431
|
/**
|
|
392
432
|
* THE READING DOCTOR SHOWS: the newest run — how many sessions it deleted, how
|
|
393
|
-
* many are waiting on a write-up, how many are
|
|
433
|
+
* many are waiting on a write-up, how many are inside their clock, how many
|
|
394
434
|
* the host still holds open — or null when retention has never run here.
|
|
395
435
|
*/
|
|
396
436
|
export function lastRetentionRun(store: Pick<Store, "eventLog" | "livedDay">): RetentionRun | null {
|
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* **Two callers, one door** (2026-09-23). The owner's removal (the console's
|
|
5
5
|
* `remove`, in `adapters/cli/`) and the RETENTION rule the owner set that day —
|
|
6
|
-
* a session's captured text goes
|
|
7
|
-
*
|
|
6
|
+
* a session's captured text goes some days after it ended (`retention.ts`;
|
|
7
|
+
* 3 since 2026-10-13, never more than 14 after its last activity, `owes.ts`).
|
|
8
|
+
* Since 2026-10-13 the owner's console has a second way in through the same
|
|
9
|
+
* door, `delete conversation-text` (`adapters/cli/commands-delete.ts`), which
|
|
10
|
+
* names every hash and session held, `by: "owner"`. Retention names whole SESSIONS rather than hashes, records
|
|
8
11
|
* itself as `by: "retention"`, and bounds the ledger it writes; everything
|
|
9
12
|
* else — the rename-aside choreography, the recovery pass, the record with no
|
|
10
13
|
* word and no hash in it — is the same code for both, so there is still exactly
|
|
@@ -136,7 +139,7 @@ export interface StrikeRequest {
|
|
|
136
139
|
sessions?: readonly string[];
|
|
137
140
|
/**
|
|
138
141
|
* Who asked, for the record. `owner` (the default) is the removal path;
|
|
139
|
-
* `retention` is the
|
|
142
|
+
* `retention` is the retention clock, whose ledger append is also trimmed to the
|
|
140
143
|
* consumed ledger's bound — a retention run can name thousands of spans, and
|
|
141
144
|
* a keyless store never runs the `consume()` that would otherwise trim it.
|
|
142
145
|
*/
|
|
@@ -887,8 +887,9 @@ export class SpanBuffer {
|
|
|
887
887
|
|
|
888
888
|
/** Spans the sweep gave up on, in full. The sweep never drops them: this file
|
|
889
889
|
* is the owner's copy, readable in any editor (constitution line 16), until
|
|
890
|
-
* RETENTION ages a line out —
|
|
891
|
-
*
|
|
890
|
+
* RETENTION ages a line out — 3 days after its session ended when that
|
|
891
|
+
* session owes no write-up, and 14 days after its last activity whatever it
|
|
892
|
+
* owes, by default (`owes.ts`, `retention.ts`). */
|
|
892
893
|
quarantined(scope: string): Span[] {
|
|
893
894
|
return this.readSpans(this.path(scope, "quarantine.jsonl"));
|
|
894
895
|
}
|
|
@@ -93,12 +93,25 @@ export const TUNABLES = {
|
|
|
93
93
|
SWEEP_WAKE_BYTES: null as number | null,
|
|
94
94
|
/**
|
|
95
95
|
* How long a session's CAPTURED TEXT is kept after it ended, when it owes
|
|
96
|
-
* nothing (`retention.ts`). Owner's ruling 2026-09-23: seven days
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
96
|
+
* nothing (`retention.ts`). Owner's ruling 2026-09-23: seven days; Mike,
|
|
97
|
+
* 2026-10-13: three — enough to cover a weekend for the "Last said here"
|
|
98
|
+
* line (`handoff/last-exchange.ts`). Not CAL — it is a decision about how
|
|
99
|
+
* long raw transcript may sit on disk, not a threshold a corpus could
|
|
100
|
+
* calibrate. The DEFAULT: a host may set its own (`adapters/config.ts`,
|
|
101
|
+
* `retention.afterWriteUpDays`) and hands it over on `RetentionSources`.
|
|
102
|
+
* A session that OWES a write-up is kept past it — up to `RETENTION_MAX_MS`.
|
|
100
103
|
*/
|
|
101
|
-
RETENTION_MS:
|
|
104
|
+
RETENTION_MS: 3 * 24 * 60 * 60_000,
|
|
105
|
+
/**
|
|
106
|
+
* THE CEILING (Mike, 2026-10-13): no session's captured text is kept more
|
|
107
|
+
* than this long after its last activity, owed or not, open or not —
|
|
108
|
+
* whichever of this and the clock above comes first. Calendar time, beside
|
|
109
|
+
* coverage's lapse in days of use (`coverage/tunables.ts#LAPSE_DAYS_OF_USE`),
|
|
110
|
+
* which still decides what is OWED; this decides what may be KEPT, so a
|
|
111
|
+
* fortnight away loses only text nobody wrote up. A host may raise it
|
|
112
|
+
* (`retention.maxDays`); nothing here keeps text past it.
|
|
113
|
+
*/
|
|
114
|
+
RETENTION_MAX_MS: 14 * 24 * 60 * 60_000,
|
|
102
115
|
} as const;
|
|
103
116
|
|
|
104
117
|
/**
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* `owes.ts` keeps a session's captured text for as long as it owes a write-up.
|
|
5
5
|
* This mark is what ends that: once a session is marked written up, its text
|
|
6
|
-
* ages out
|
|
6
|
+
* ages out 3 days later (7 until 2026-10-13). So a mark is a DELETION ON A
|
|
7
|
+
* FUSE, and the
|
|
7
8
|
* PR #189 re-review (R1) found it was a public method on `SpanBuffer` — which
|
|
8
9
|
* `Counterpart.spans` hands to everything that holds a `Counterpart` — taking
|
|
9
10
|
* any scope (and CREATING it), any session, and free text for `by`.
|
package/src/core/store/index.ts
CHANGED
|
@@ -417,6 +417,7 @@ export const WRITE_METHODS = [
|
|
|
417
417
|
"updateMeta",
|
|
418
418
|
"setGateRecords",
|
|
419
419
|
"pruneGateSessions",
|
|
420
|
+
"rewriteGateValues",
|
|
420
421
|
"appendEvent",
|
|
421
422
|
"pruneEvents",
|
|
422
423
|
"setRanking",
|
|
@@ -3272,6 +3273,44 @@ export class Store {
|
|
|
3272
3273
|
return report;
|
|
3273
3274
|
}
|
|
3274
3275
|
|
|
3276
|
+
/**
|
|
3277
|
+
* Rewrite one record's `value` across EVERY session, in one transaction:
|
|
3278
|
+
* the rows of `(kind, ref)` whose value contains `contains` are handed to
|
|
3279
|
+
* `rewrite`, and a returned string that differs replaces the value — only
|
|
3280
|
+
* the value; the row, its turn and its day stay. `null` leaves a row alone.
|
|
3281
|
+
* Each update is conditioned on the value it read, so it never writes over
|
|
3282
|
+
* a newer save. Returns how many rows changed. The store knows nothing of
|
|
3283
|
+
* what the value means: `recall/session.ts#clearIdleCarries` does, and uses
|
|
3284
|
+
* this to take typed cue tokens out of sessions that have gone quiet.
|
|
3285
|
+
*/
|
|
3286
|
+
rewriteGateValues(kind: string, ref: string, contains: string, rewrite: (value: string) => string | null): number {
|
|
3287
|
+
const changed = this.mutate("rewriteGateValues", () => {
|
|
3288
|
+
const rows = this.ops.all<{ session_id: string; value: string }>(
|
|
3289
|
+
"SELECT session_id, value FROM gate_session WHERE kind = ? AND ref = ? AND value IS NOT NULL AND instr(value, ?) > 0",
|
|
3290
|
+
kind,
|
|
3291
|
+
ref,
|
|
3292
|
+
contains,
|
|
3293
|
+
);
|
|
3294
|
+
let n = 0;
|
|
3295
|
+
for (const row of rows) {
|
|
3296
|
+
const next = rewrite(row.value);
|
|
3297
|
+
if (next === null || next === row.value) continue;
|
|
3298
|
+
this.ops.run(
|
|
3299
|
+
"UPDATE gate_session SET value = ? WHERE session_id = ? AND kind = ? AND ref = ? AND value = ?",
|
|
3300
|
+
next,
|
|
3301
|
+
row.session_id,
|
|
3302
|
+
kind,
|
|
3303
|
+
ref,
|
|
3304
|
+
row.value,
|
|
3305
|
+
);
|
|
3306
|
+
n++;
|
|
3307
|
+
}
|
|
3308
|
+
return n;
|
|
3309
|
+
});
|
|
3310
|
+
this.emit("store.gate.rewritten", undefined, { kind, count: changed });
|
|
3311
|
+
return changed;
|
|
3312
|
+
}
|
|
3313
|
+
|
|
3275
3314
|
// ── box 2: the durable event log (SEAMS item K) ────────────────────────────
|
|
3276
3315
|
|
|
3277
3316
|
/**
|
package/src/core/store/paths.ts
CHANGED
|
@@ -272,8 +272,15 @@ export const LAYOUT: readonly LayoutEntry[] = [
|
|
|
272
272
|
{
|
|
273
273
|
name: "spans",
|
|
274
274
|
match: "exact",
|
|
275
|
-
|
|
276
|
-
|
|
275
|
+
// NOT BACKED UP, since 2026-10-13 (Mike): backups never hold conversation
|
|
276
|
+
// text. Removed, not flagged — there is no setting that turns it back on.
|
|
277
|
+
// The cost, accepted: a restored backup has lost whatever was not yet
|
|
278
|
+
// written up. The memories made from it are rows, and they are copied.
|
|
279
|
+
// Still CLASSIFIED (an unclassified name refuses the store at open), and
|
|
280
|
+
// `snapshots.ts#copyKind` keys on classification, so copies taken before
|
|
281
|
+
// this — which hold `spans/` — are still recognised and rotate as before.
|
|
282
|
+
backup: false,
|
|
283
|
+
why: "remember/'s capture buffer: conversation text awaiting its write-up, kept 3 days after that (never more than 14). Never backed up: backups never hold conversation text (Mike, 2026-10-13).",
|
|
277
284
|
},
|
|
278
285
|
{
|
|
279
286
|
name: "journal",
|