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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,67 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.21 — 2026-10-13
|
|
4
|
+
|
|
5
|
+
Your conversation text is kept for less time, and never in a backup. The text of a conversation is now deleted 3 days after it has been written up and the session has ended (it was 7), and it is never kept more than 14 days after the session's last activity, written up or not; both numbers can be changed with `"retention": {"afterWriteUpDays": 3, "maxDays": 14}` in `claude-code.json`. The first time the new version runs on an existing memory, everything older than those limits is deleted in one go, so if you want to keep more, add the `retention` setting before your first session on 0.3.21. Daily backups stop copying conversation text; backups made before this update still hold it until they rotate out, or until you run `counterparts delete backups`. New `counterparts delete conversation-text`, `delete backups` and `delete activity-log` (and "Delete data…" on the dashboard's Memories page) each delete one kind of data after showing what they would delete. The few words recall carries from your last message are cleared once a session has been quiet past the same 14-day limit. Also: the plugin installs over HTTPS without a GitHub SSH key (run `/plugin marketplace update counterparts` first if you added the marketplace before), "installed twice" is said once, the first meeting says where the sidebar appears, and the sidebar's fox and its look in the Claude Desktop app are polished (the Desktop shows the fox, not the brain, this version). No store-format change (store v13, cache v6) and no wiring change: nothing to run after upgrading from 0.3.20, and `counterparts connect` is not needed.
|
|
6
|
+
|
|
7
|
+
- **The plugin installs without a GitHub SSH key.** On a computer with no SSH key that
|
|
8
|
+
GitHub accepts, `/plugin install counterparts@counterparts` failed with "Permission denied
|
|
9
|
+
(publickey)", even though adding the marketplace had worked. The marketplace now names the
|
|
10
|
+
repository by its `https://` address, which needs no key. If you added the marketplace
|
|
11
|
+
before, run `/plugin marketplace update counterparts` first, then install again.
|
|
12
|
+
- **"Installed twice" is said once.** With both the npm install and the plugin, the plugin
|
|
13
|
+
stands down and said so at the start of every session, which read like an error. It now
|
|
14
|
+
says it at the first session that finds both, then stays quiet; `counterparts doctor`
|
|
15
|
+
still shows it. Nothing about how the two share the memory has changed.
|
|
16
|
+
- **Conversation text is kept for less time, and never in a backup.** The text of your
|
|
17
|
+
conversations is deleted 3 days after it is written up and the session has ended (it
|
|
18
|
+
was 7), and is never kept more than 14 days after the session's last activity, written
|
|
19
|
+
up or not. Both can be changed in `claude-code.json`:
|
|
20
|
+
`"retention": {"afterWriteUpDays": 3, "maxDays": 14}`. Daily backups no longer copy it
|
|
21
|
+
at all, so restoring one loses whatever was not yet written up. Backups made before
|
|
22
|
+
this update still hold it until they rotate out, or until you delete them.
|
|
23
|
+
- **Delete one kind of data at a time.** `counterparts delete conversation-text`,
|
|
24
|
+
`delete backups` and `delete activity-log` each delete that one kind and nothing else.
|
|
25
|
+
Each shows what it would delete first (for conversation text, how many sessions were
|
|
26
|
+
still waiting to be written up and would be lost) and asks once; `--yes` skips the
|
|
27
|
+
question for a script. The dashboard's Memories page has the same three under
|
|
28
|
+
"Delete data…".
|
|
29
|
+
- **The first meeting says where the sidebar is.** In the plugin, the end of the first
|
|
30
|
+
meeting now says the memory sidebar appears on the right once the window is wide
|
|
31
|
+
enough.
|
|
32
|
+
- **The sidebar's fox is a little more alive, and calmer about it.** He does small things
|
|
33
|
+
more often (a blink, a flick of his tail tip, an ear twitch, a glance), and flicks his tail
|
|
34
|
+
within a few seconds of the sidebar opening. When something comes to mind he perks up,
|
|
35
|
+
curious, with one ear raised. Left alone, he lies down after 45 seconds and naps after two
|
|
36
|
+
minutes; anything you do gets him up. His small moves no longer make his whole body
|
|
37
|
+
flicker, in the desktop app and in Ghostty or kitty. In iTerm, WezTerm and VS Code he
|
|
38
|
+
now has his intended colours (a warmer orange, a cream chest), and his notepad shows.
|
|
39
|
+
- **A clearer hint when the window is too narrow for the sidebar.** The line under the
|
|
40
|
+
prompt now says to widen the window, instead of naming a command that can't open it there.
|
|
41
|
+
- **Your words from a session's last turn no longer stay in the database.** Recall keeps a
|
|
42
|
+
few words from your previous message to help with the next one. A session that ended,
|
|
43
|
+
or was closed abruptly, kept its last few words indefinitely. Now they are cleared once
|
|
44
|
+
the session has been quiet for the retention limit (14 days unless you changed it),
|
|
45
|
+
including for sessions from before this update. Backups taken from then on don't
|
|
46
|
+
contain them either.
|
|
47
|
+
- **The sidebar looks right in the Claude Desktop app.** It now uses the app's own colours (light or
|
|
48
|
+
dark), has no lines of dashes, wraps its text to the app's font, leaves a blank row between
|
|
49
|
+
items, and draws the "Mechanisms today" bars at a readable size. The fox no longer shows a dark
|
|
50
|
+
edge on the light page and fits a narrower pane.
|
|
51
|
+
- **The memory count sits on the sidebar's title row, beside the day** ("1511 memories · day 22",
|
|
52
|
+
shortened when the pane is narrow), in every app, and the search row appears only when search is
|
|
53
|
+
switched on.
|
|
54
|
+
- **The sidebar's "quietly available" titles read cleanly.** "Earlier (now [id]): ..." shows as
|
|
55
|
+
"Earlier: ...", "Unsettled - may be out of date, see [id]: ..." as "Unsettled: ...", "Corrected by
|
|
56
|
+
[id]: ..." as "Corrected: ...", and the trailing "(earlier: [id])" and "(corrects [id])" are left
|
|
57
|
+
off; a click on one opens that memory, not the one its note points at.
|
|
58
|
+
- **In the Desktop app the avatar is the fox or nothing.** The brain doesn't draw there yet, so the
|
|
59
|
+
avatar row offers animal and off, and a brain chosen in the terminal shows the fox on the Desktop. The
|
|
60
|
+
terminal keeps its brain.
|
|
61
|
+
- **Pressing the Counterparts switch in auto mode no longer shows an engine error.** When auto mode
|
|
62
|
+
declines the press, a short note says so and tells you what to ask Claude instead ("pause
|
|
63
|
+
Counterparts here"); the switch stays as it was.
|
|
64
|
+
|
|
3
65
|
## 0.3.20 — 2026-10-12
|
|
4
66
|
|
|
5
67
|
New installs from the plugin now remember from the second day. (Plugin first runs and scripted `install --yes` had never set a size limit for the wake, so every session opened on "No briefing has been composed yet"; earlier plugin installs had the same gap, and they are fixed automatically, with no action and no change to your configuration file; the first session after upgrading may still open on that line, and the wake is composed when that session ends.) The first meeting is the heart of this release. A new install now opens with a short, easy conversation where Claude introduces itself, asks one question at a time (all fine to pass), writes up what it learned right there, and ends with "What would you like to work on today?". Nothing interrupts it: no dream starts and the end-of-turn write-up waits, so the first dream comes the next day. Everyday words replace the internal ones: session starts say "Coming up:" and "Might be relevant:", dates read "Oct 11", and the dashboard uses the same words. A brand-new install's first `counterparts doctor` shows no ambers, a plugin install gets a one-line welcome, and the README is honest about what recall by meaning can and cannot find. The sidebar gains onboarding, a small fox, a second theme and the dashboard's store id; its Claude Code memory switch is gone, and the dead read of an A/B file in the home directory is removed. Reminders are no longer spent on a compaction nobody reads, and the wake never drops a section without saying so. No store-format change (store v13, cache v6) and no wiring change: nothing to run after upgrading from 0.3.19, and `counterparts connect` is not needed.
|
package/README.md
CHANGED
|
@@ -49,7 +49,10 @@ to be deleted. The full walkthrough is in [`docs/QUICKSTART.md`](docs/QUICKSTART
|
|
|
49
49
|
- **Things come to mind.** As you talk, related memories surface quietly, the way one
|
|
50
50
|
thing reminds you of another.
|
|
51
51
|
- **It's yours.** Everything lives on your machine in one SQLite file you can read,
|
|
52
|
-
export or delete. No API keys, no accounts, nothing sent anywhere.
|
|
52
|
+
export or delete. No API keys, no accounts, nothing sent anywhere. The text of your
|
|
53
|
+
conversations is kept only until it's written up: deleted 3 days after that, never
|
|
54
|
+
kept more than 14 days, and never in a backup. You can delete the conversation text,
|
|
55
|
+
the backups or the activity log on their own at any time (`counterparts delete`).
|
|
53
56
|
|
|
54
57
|
## Who it's for
|
|
55
58
|
|
package/package.json
CHANGED
|
@@ -1005,8 +1005,8 @@ session the host's registry knows (one our hooks saw start), so the unbound MCP
|
|
|
1005
1005
|
shared `mcp` id is passed by, and only for a person's interactive conversation: a session
|
|
1006
1006
|
whose host entrypoint (`CLAUDE_CODE_ENTRYPOINT`, kept on the registry record) says
|
|
1007
1007
|
`claude -p`, the Agent SDK, `mcp` or a GitHub action owes no short write-up (N2). It is
|
|
1008
|
-
not a retention debt (text ages out
|
|
1009
|
-
after the write-up, like a full debt) and not in doctor's awaiting count. The headless
|
|
1008
|
+
not a retention debt (text ages out on the retention clock; a written-up one keeps it up to 3
|
|
1009
|
+
days after the write-up, like a full debt, and never past the 14-day ceiling) and not in doctor's awaiting count. The headless
|
|
1010
1010
|
nightly run's child and an observer capture nothing, so they owe nothing. When a pointer
|
|
1011
1011
|
defers for room, its record names what else rode beside the wake, and doctor's advice
|
|
1012
1012
|
names that rather than the wake's budget (M3).
|
|
@@ -71,9 +71,11 @@ import {
|
|
|
71
71
|
firstRunNoticePath,
|
|
72
72
|
hookGate,
|
|
73
73
|
installRoute,
|
|
74
|
+
markTwiceSaid,
|
|
74
75
|
pluginOrigin,
|
|
75
76
|
runningAsPlugin,
|
|
76
77
|
takeFirstRunNotice,
|
|
78
|
+
twiceNoticePath,
|
|
77
79
|
} from "../../plugin.js";
|
|
78
80
|
import { claimDelivery, deliveryClaimKey, finishClaim, firesOnce } from "../claim.js";
|
|
79
81
|
|
|
@@ -708,7 +710,11 @@ async function main(): Promise<void> {
|
|
|
708
710
|
// it was installed: a first run the plugin made beside it is not this
|
|
709
711
|
// hook's to announce, now or after a later move to the plugin.
|
|
710
712
|
takeFirstRunNotice(firstRunNoticePath(choice.path));
|
|
711
|
-
|
|
713
|
+
// Said at the first session start that finds both, then not again
|
|
714
|
+
// (`plugin.ts#twiceNoticePath`).
|
|
715
|
+
if (gate.line !== null && markTwiceSaid(twiceNoticePath(choice.path, process.env))) {
|
|
716
|
+
process.stdout.write(JSON.stringify({ systemMessage: gate.line }));
|
|
717
|
+
}
|
|
712
718
|
}
|
|
713
719
|
return;
|
|
714
720
|
}
|
|
@@ -36,13 +36,15 @@
|
|
|
36
36
|
* (`core/coverage/`);
|
|
37
37
|
* 3c. RAW TRANSCRIPT RETENTION (owner's ruling 2026-09-23): once per date —
|
|
38
38
|
* behind an `O_EXCL` latch under `spans/retention/` — a session's captured
|
|
39
|
-
* text is deleted
|
|
40
|
-
* registry does not hold it open
|
|
39
|
+
* text is deleted 3 days after it ended when it owes no write-up and the
|
|
40
|
+
* registry does not hold it open, and 14 days after its last activity
|
|
41
|
+
* whatever is true — the configuration's `retention` block may set both
|
|
42
|
+
* (`config.ts#retentionClocks`; `remember/owes.ts` decides,
|
|
41
43
|
* `remember/retention.ts` deletes, and this file is the only one that may
|
|
42
44
|
* import the second), and one `remember.prune` row says what was deleted,
|
|
43
|
-
* what is waiting on a write-up, what is
|
|
44
|
-
* still open. Keyless, like every step but the sweep.
|
|
45
|
-
*
|
|
45
|
+
* what is waiting on a write-up, what is inside its clock and what is
|
|
46
|
+
* still open. Keyless, like every step but the sweep. (Before the snapshot,
|
|
47
|
+
* which since 2026-10-13 copies no conversation text at all.)
|
|
46
48
|
* 4. the DAILY ROTATING SNAPSHOT (`adapters/snapshots.ts`), last and outside
|
|
47
49
|
* the cycle. Last because it copies the state the three steps above just
|
|
48
50
|
* left; outside because sleep must not learn that the floor is changing —
|
|
@@ -69,6 +71,7 @@ import { fileURLToPath } from "node:url";
|
|
|
69
71
|
|
|
70
72
|
import { Counterpart, RUNNER_FAILED_EVENT } from "../../../core/counterpart.js";
|
|
71
73
|
import { recordCoverage } from "../../../core/coverage/index.js";
|
|
74
|
+
import { clearIdleCarries } from "../../../core/recall/index.js";
|
|
72
75
|
import { RETENTION_EVENT, retentionRow, retentionRuns } from "../../../core/remember/index.js";
|
|
73
76
|
import type { HostSessionEvidence, RetentionReport } from "../../../core/remember/index.js";
|
|
74
77
|
// THE DELETING HALF, by path, and from this file alone (PR #189 review, B1):
|
|
@@ -92,7 +95,7 @@ import {
|
|
|
92
95
|
} from "../../config-path.js";
|
|
93
96
|
import type { ConfigChoice } from "../../config-path.js";
|
|
94
97
|
|
|
95
|
-
import { loadConfig, withBudgetDefault, withEmbedderDefault } from "../../config.js";
|
|
98
|
+
import { loadConfig, retentionClocks, withBudgetDefault, withEmbedderDefault } from "../../config.js";
|
|
96
99
|
import type { AdapterConfig } from "../../config.js";
|
|
97
100
|
import { openEmbedder } from "../index.js";
|
|
98
101
|
import type { LiveEmbedder } from "../embed-client.js";
|
|
@@ -198,6 +201,9 @@ export const retentionHost: (store: Store) => (session: string) => HostSessionEv
|
|
|
198
201
|
export function retentionJob(input: {
|
|
199
202
|
counterpart: Counterpart;
|
|
200
203
|
date: string;
|
|
204
|
+
/** The configuration's two clocks (`config.ts#retentionClocks`); the
|
|
205
|
+
* defaults when absent. */
|
|
206
|
+
clocks?: { retentionMs: number; maxMs: number };
|
|
201
207
|
onEvent?: (name: string, data: Record<string, string | number | boolean | null>) => void;
|
|
202
208
|
}): RetentionJobReport {
|
|
203
209
|
const { counterpart, date } = input;
|
|
@@ -210,7 +216,7 @@ export function retentionJob(input: {
|
|
|
210
216
|
// THE SAME SOURCES THE WRITE-UP READS (`sessions.ts#writeUpSources`), so
|
|
211
217
|
// what this pass keeps as owed and what the next session is asked to write
|
|
212
218
|
// up are one set, by construction rather than by two copies agreeing.
|
|
213
|
-
const sources = writeUpSources(store);
|
|
219
|
+
const sources = writeUpSources(store, input.clocks ?? {});
|
|
214
220
|
// THE DATE IS VISIBLE FROM THE MOMENT IT IS HELD (re-review R7): a
|
|
215
221
|
// `STARTED` row goes in as soon as the latch is taken, before anything is
|
|
216
222
|
// planned, so a run the watchdog kills halfway leaves "started, never
|
|
@@ -220,7 +226,7 @@ export function retentionJob(input: {
|
|
|
220
226
|
store.appendEvent({
|
|
221
227
|
name: RETENTION_EVENT,
|
|
222
228
|
day: store.livedDay(),
|
|
223
|
-
payload: retentionRow({ ...EMPTY_RETENTION, reason: "STARTED" }, date),
|
|
229
|
+
payload: retentionRow({ ...EMPTY_RETENTION, reason: "STARTED" }, date, sources),
|
|
224
230
|
dedupKey: `${RETENTION_EVENT}:${date}:started`,
|
|
225
231
|
});
|
|
226
232
|
} catch (err) {
|
|
@@ -236,7 +242,7 @@ export function retentionJob(input: {
|
|
|
236
242
|
store.appendEvent({
|
|
237
243
|
name: RETENTION_EVENT,
|
|
238
244
|
day: store.livedDay(),
|
|
239
|
-
payload: retentionRow({ ...EMPTY_RETENTION, reason: "LATCH_HELD" }, date),
|
|
245
|
+
payload: retentionRow({ ...EMPTY_RETENTION, reason: "LATCH_HELD" }, date, sources),
|
|
240
246
|
dedupKey: `${RETENTION_EVENT}:${date}:held`,
|
|
241
247
|
});
|
|
242
248
|
} catch (err) {
|
|
@@ -256,7 +262,7 @@ export function retentionJob(input: {
|
|
|
256
262
|
store.appendEvent({
|
|
257
263
|
name: RETENTION_EVENT,
|
|
258
264
|
day: store.livedDay(),
|
|
259
|
-
payload: retentionRow(report, date),
|
|
265
|
+
payload: retentionRow(report, date, sources),
|
|
260
266
|
dedupKey: `${RETENTION_EVENT}:${date}`,
|
|
261
267
|
});
|
|
262
268
|
recorded = true;
|
|
@@ -450,17 +456,28 @@ export async function runOnce(input: {
|
|
|
450
456
|
emit("coverage.threw", { code: err instanceof Error ? err.name : "UNKNOWN" });
|
|
451
457
|
}
|
|
452
458
|
// 3c. RETENTION — on the failed path as well as the good one (a day whose
|
|
453
|
-
// sweep broke still ages the
|
|
454
|
-
//
|
|
455
|
-
//
|
|
459
|
+
// sweep broke still ages the text of sessions that owe nothing), with the
|
|
460
|
+
// configuration's clocks. Its own try: a retention pass may not cost the
|
|
461
|
+
// snapshot.
|
|
456
462
|
try {
|
|
457
|
-
retentionReport = retentionJob({ counterpart, date: today, onEvent: emit });
|
|
463
|
+
retentionReport = retentionJob({ counterpart, date: today, clocks: retentionClocks(config), onEvent: emit });
|
|
458
464
|
if (retentionReport.reason === "failed") {
|
|
459
465
|
noteFailure(counterpart, emit, retentionReport.code ?? "UNKNOWN", "retention", today);
|
|
460
466
|
}
|
|
461
467
|
} catch (err) {
|
|
462
468
|
emit("retention.threw", { code: err instanceof Error ? err.name : "UNKNOWN" });
|
|
463
469
|
}
|
|
470
|
+
// 3d. TYPED WORDS LEAVE QUIET SESSIONS (2026-10-13): recall's carried cue
|
|
471
|
+
// tokens are emptied in every session idle past the same ceiling, so a
|
|
472
|
+
// session that ended or was killed does not keep them, and the copy below
|
|
473
|
+
// does not take them. Every run, not once a date: it reads only rows that
|
|
474
|
+
// still carry words. Its own try, like the steps above.
|
|
475
|
+
try {
|
|
476
|
+
const cleared = clearIdleCarries(counterpart.store, retentionClocks(config).maxMs);
|
|
477
|
+
if (cleared > 0) emit("runner.carries", { cleared });
|
|
478
|
+
} catch (err) {
|
|
479
|
+
emit("carries.threw", { code: err instanceof Error ? err.name : "UNKNOWN" });
|
|
480
|
+
}
|
|
464
481
|
// 4. THE DAY'S COPY OF THE STORE — after everything above has written, on
|
|
465
482
|
// the failed path as well as the good one, and before the store is closed.
|
|
466
483
|
// It never throws by construction (`adapters/snapshots.ts`); the try is
|
|
@@ -100,7 +100,7 @@ import {
|
|
|
100
100
|
readSnapshotsDir,
|
|
101
101
|
resolveSnapshotsDir,
|
|
102
102
|
} from "../snapshots.js";
|
|
103
|
-
import { TUNABLES, resolveEmbedder, withEmbedderDefault } from "../config.js";
|
|
103
|
+
import { TUNABLES, resolveEmbedder, retentionClocks, withEmbedderDefault } from "../config.js";
|
|
104
104
|
import type { EmbedderSource } from "../config.js";
|
|
105
105
|
import { MODEL_FILE, STATIC_WEIGHTS_ENV, STATIC_WEIGHTS_PACKAGE, resolveStaticWeights } from "../../core/embed/static.js";
|
|
106
106
|
import { DATABASE_FILE, heldExits, readRollbackHold, rollbackHeld } from "../../core/store/index.js";
|
|
@@ -855,12 +855,12 @@ const KEY_HISTORY_ROWS = 200;
|
|
|
855
855
|
* RAW TRANSCRIPTS — how long the captured conversation is kept, and what the
|
|
856
856
|
* newest retention pass did (remember INTERFACE-GAPS §11; roadmap B3).
|
|
857
857
|
*
|
|
858
|
-
* The first clause is the POLICY,
|
|
859
|
-
*
|
|
860
|
-
*
|
|
861
|
-
*
|
|
862
|
-
*
|
|
863
|
-
*
|
|
858
|
+
* The first clause is the POLICY (Mike, 2026-10-13): the text is deleted a
|
|
859
|
+
* few days after a session is written up and ended, and never kept past the
|
|
860
|
+
* ceiling, owed or not; backups never hold it. Both numbers are read — the
|
|
861
|
+
* configuration's `retention` block, else `remember/`'s defaults, through
|
|
862
|
+
* `config.ts#retentionClocks` — never retyped. A field in that block this
|
|
863
|
+
* could not read is named, amber, the way the Snapshot line names its own.
|
|
864
864
|
*
|
|
865
865
|
* The rest is the newest `remember.prune` row, in sessions. Grades:
|
|
866
866
|
*
|
|
@@ -876,11 +876,24 @@ const KEY_HISTORY_ROWS = 200;
|
|
|
876
876
|
*/
|
|
877
877
|
function retentionFindings(input: DoctorInput, store: Store): Finding[] {
|
|
878
878
|
const TITLE = "Raw transcripts";
|
|
879
|
-
const
|
|
880
|
-
const
|
|
881
|
-
const policy =
|
|
879
|
+
const clocks = retentionClocks(input.config);
|
|
880
|
+
const days = clocks.afterWriteUpDays;
|
|
881
|
+
const policy = `deleted ${String(days)} day${days === 1 ? "" : "s"} after a session is written up and ended, never kept more than ${String(clocks.maxDays)} · never in backups`;
|
|
882
882
|
const run = lastRetentionRun(store);
|
|
883
|
-
const base = { retentionDays: days,
|
|
883
|
+
const base = { retentionDays: days, maxDays: clocks.maxDays };
|
|
884
|
+
const ignored = input.config.retention?.ignored ?? [];
|
|
885
|
+
if (ignored.length > 0) {
|
|
886
|
+
return [
|
|
887
|
+
finding(
|
|
888
|
+
"retention",
|
|
889
|
+
"amber",
|
|
890
|
+
TITLE,
|
|
891
|
+
`${policy} · the configuration's retention block was partly ignored: ${ignored.join("; ")}`,
|
|
892
|
+
`Fix "retention" in ${tilde(input.configPath)}: whole days, at least 1.`,
|
|
893
|
+
{ ...base, ran: run !== null, ignored: ignored.length },
|
|
894
|
+
),
|
|
895
|
+
];
|
|
896
|
+
}
|
|
884
897
|
if (run === null) {
|
|
885
898
|
return [finding("retention", "green", TITLE, `${policy} · not run yet`, "", { ...base, ran: false })];
|
|
886
899
|
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `delete <kind>` — DELETE ONE KIND OF DATA, AND NOTHING ELSE (Mike, 2026-10-13).
|
|
3
|
+
*
|
|
4
|
+
* Three kinds, each one sentence of the policy:
|
|
5
|
+
*
|
|
6
|
+
* - `conversation-text` — every word of conversation the store still holds
|
|
7
|
+
* (the span buffer: conversation, the assistant's turns, jots, quarantine,
|
|
8
|
+
* claims in flight), through `remember/`'s own strike — the one door that
|
|
9
|
+
* destroys a span. Sessions still owed a write-up are counted first and
|
|
10
|
+
* said out loud: their text is lost with the rest.
|
|
11
|
+
* - `backups` — every daily snapshot and every pre-migration copy this
|
|
12
|
+
* package wrote, in the snapshots directory and its mirror, taken apart by
|
|
13
|
+
* name (`snapshots.ts#deleteAllCopies`). Rollback has nothing to go back to
|
|
14
|
+
* afterwards, and the console says so before it asks.
|
|
15
|
+
* - `activity-log` — the process log's dated files (`sessions/log/`).
|
|
16
|
+
*
|
|
17
|
+
* Memories have `start-fresh`, and are not a kind here; nor are the dream
|
|
18
|
+
* journal and the self page (lightly held: not unless asked).
|
|
19
|
+
*
|
|
20
|
+
* **One shape for all three.** No `--yes`: the plan, in counts, and "Nothing has
|
|
21
|
+
* changed". A terminal is then asked once; anything that cannot ask (a pipe, a
|
|
22
|
+
* script, the dashboard, which asks in the browser first) passes `--yes`. Each
|
|
23
|
+
* delete that ran leaves one `owner.deleted` row — the kind and counts, never a
|
|
24
|
+
* word, a hash or a path. Under observer it refuses (`OWNER_OPS`).
|
|
25
|
+
*/
|
|
26
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
27
|
+
import { join } from "node:path";
|
|
28
|
+
|
|
29
|
+
import { SpanBuffer } from "../../core/remember/index.js";
|
|
30
|
+
// The buffer's destruction seam — this directory may import it, and
|
|
31
|
+
// `test/cli.test.ts` pins that nothing outside it does.
|
|
32
|
+
import { strikeSpans } from "../../core/remember/owner-strike-seam.js";
|
|
33
|
+
import type { Store } from "../../core/store/index.js";
|
|
34
|
+
import { loadConfig } from "../config.js";
|
|
35
|
+
import type { AdapterConfig } from "../config.js";
|
|
36
|
+
import { clearLog, logDates } from "../log/index.js";
|
|
37
|
+
import { writeUpPlan } from "../sessions.js";
|
|
38
|
+
import { deleteAllCopies, readSnapshotsDir, resolveSnapshotsDir } from "../snapshots.js";
|
|
39
|
+
|
|
40
|
+
import { EXIT, openStoreAt } from "./commands-shared.js";
|
|
41
|
+
import type { Io } from "./commands-shared.js";
|
|
42
|
+
import { confirm, isInteractive, isPromptAborted } from "./ui.js";
|
|
43
|
+
import type { UiEnv } from "./ui.js";
|
|
44
|
+
|
|
45
|
+
export const DELETE_KINDS = ["conversation-text", "backups", "activity-log"] as const;
|
|
46
|
+
export type DeleteKind = (typeof DELETE_KINDS)[number];
|
|
47
|
+
|
|
48
|
+
/** The row each delete that ran leaves. Kind and counts only. */
|
|
49
|
+
export const OWNER_DELETED_EVENT = "owner.deleted";
|
|
50
|
+
|
|
51
|
+
const NOTHING_CHANGED = "Nothing has changed.";
|
|
52
|
+
|
|
53
|
+
// ── conversation text ───────────────────────────────────────────────────────
|
|
54
|
+
|
|
55
|
+
/** Every hash and session the buffer holds text for, from the four readers
|
|
56
|
+
* retention counts. Naming hashes as well as sessions means a line that
|
|
57
|
+
* carries no session is not missed. */
|
|
58
|
+
function heldText(buffer: SpanBuffer): { hashes: string[]; sessions: string[] } {
|
|
59
|
+
const hashes = new Set<string>();
|
|
60
|
+
const sessions = new Set<string>();
|
|
61
|
+
for (const scope of buffer.scopes()) {
|
|
62
|
+
for (const span of [
|
|
63
|
+
...buffer.spans(scope),
|
|
64
|
+
...buffer.assistantSpans(scope),
|
|
65
|
+
...buffer.quarantined(scope),
|
|
66
|
+
...buffer.claimedSpans(scope),
|
|
67
|
+
]) {
|
|
68
|
+
if (typeof span.hash === "string") hashes.add(span.hash);
|
|
69
|
+
if (typeof span.session === "string" && span.session.length > 0) sessions.add(span.session);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return { hashes: [...hashes], sessions: [...sessions] };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** What the store holds of conversation text now. Counts, never words. */
|
|
76
|
+
export function planConversationText(store: Store): { sessions: number; owed: number; lines: number } {
|
|
77
|
+
const buffer = new SpanBuffer({ dir: store.dir, observer: true, day: () => store.livedDay() });
|
|
78
|
+
const plan = writeUpPlan({ store, spans: buffer });
|
|
79
|
+
return {
|
|
80
|
+
sessions: plan.length,
|
|
81
|
+
owed: plan.filter((h) => h.owes).length,
|
|
82
|
+
lines: plan.reduce((n, h) => n + h.lines, 0),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Strike every line of text the buffer holds, recorded `by: "owner"`. */
|
|
87
|
+
export function deleteConversationText(store: Store): { ok: boolean; lines: number; reason: string } {
|
|
88
|
+
const buffer = new SpanBuffer({ dir: store.dir, day: () => store.livedDay() });
|
|
89
|
+
const held = heldText(buffer);
|
|
90
|
+
if (held.hashes.length === 0 && held.sessions.length === 0) return { ok: true, lines: 0, reason: "NOTHING" };
|
|
91
|
+
const report = strikeSpans(buffer, { scope: null, hashes: held.hashes, sessions: held.sessions, by: "owner" });
|
|
92
|
+
return {
|
|
93
|
+
ok: report.reason !== "OBSERVER" && report.reason !== "IO_FAILED",
|
|
94
|
+
lines: report.struck,
|
|
95
|
+
reason: report.reason,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ── backups ─────────────────────────────────────────────────────────────────
|
|
100
|
+
|
|
101
|
+
/** The configuration beside the store (`<base>/claude-code.json`), or none. */
|
|
102
|
+
function configBeside(dir: string): AdapterConfig {
|
|
103
|
+
const beside = join(dir, "..", "claude-code.json");
|
|
104
|
+
if (!existsSync(beside)) return {};
|
|
105
|
+
try {
|
|
106
|
+
return loadConfig(JSON.parse(readFileSync(beside, "utf8"))).config;
|
|
107
|
+
} catch {
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The directories copies live in: the snapshots directory and its mirror. */
|
|
113
|
+
function backupDirs(dir: string): string[] {
|
|
114
|
+
const config = configBeside(dir);
|
|
115
|
+
const out: string[] = [];
|
|
116
|
+
const primary = resolveSnapshotsDir(dir, config.snapshots?.dir).dir;
|
|
117
|
+
if (primary !== null) out.push(primary);
|
|
118
|
+
const mirror = config.snapshots?.mirror;
|
|
119
|
+
if (mirror !== undefined && !out.includes(mirror)) out.push(mirror);
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** How many copies of ours each directory holds. Read-only. */
|
|
124
|
+
export function planBackups(dir: string): { daily: number; preMigration: number; left: number } {
|
|
125
|
+
let daily = 0;
|
|
126
|
+
let preMigration = 0;
|
|
127
|
+
let left = 0;
|
|
128
|
+
for (const d of backupDirs(dir)) {
|
|
129
|
+
const read = readSnapshotsDir(d);
|
|
130
|
+
daily += read.names.length;
|
|
131
|
+
preMigration += read.preMigration.length;
|
|
132
|
+
left += read.preRows.length + read.unrecognised.length;
|
|
133
|
+
}
|
|
134
|
+
return { daily, preMigration, left };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ── the command ─────────────────────────────────────────────────────────────
|
|
138
|
+
|
|
139
|
+
function plural(n: number, one: string, many = `${one}s`): string {
|
|
140
|
+
return `${String(n)} ${n === 1 ? one : many}`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The plan, in words, and the question it ends on. Opens the store read-only
|
|
144
|
+
* and closes it before anyone is asked. */
|
|
145
|
+
function describe(kind: DeleteKind, dir: string): { lines: string[]; question: string; empty: boolean } {
|
|
146
|
+
if (kind === "conversation-text") {
|
|
147
|
+
const store = openStoreAt({ dir, observer: true });
|
|
148
|
+
let p;
|
|
149
|
+
try {
|
|
150
|
+
p = planConversationText(store);
|
|
151
|
+
} finally {
|
|
152
|
+
store.close();
|
|
153
|
+
}
|
|
154
|
+
const lines = [
|
|
155
|
+
`Conversation text held: ${plural(p.sessions, "session")}, ${plural(p.lines, "line")}.`,
|
|
156
|
+
p.owed === 0
|
|
157
|
+
? "None of it is still owed a write-up."
|
|
158
|
+
: `${plural(p.owed, "session is", "sessions are")} still owed a write-up; ${p.owed === 1 ? "its" : "their"} text is lost if you delete now.`,
|
|
159
|
+
"Memories already made from it are not touched.",
|
|
160
|
+
];
|
|
161
|
+
return { lines, question: "Delete all conversation text now?", empty: p.lines === 0 };
|
|
162
|
+
}
|
|
163
|
+
if (kind === "backups") {
|
|
164
|
+
const p = planBackups(dir);
|
|
165
|
+
const lines = [
|
|
166
|
+
`Backups held: ${plural(p.daily, "daily copy", "daily copies")} and ${plural(p.preMigration, "copy", "copies")} taken before an upgrade.`,
|
|
167
|
+
"After this, rollback has nothing to go back to until the next daily copy.",
|
|
168
|
+
];
|
|
169
|
+
if (p.left > 0) lines.push(`${plural(p.left, "other folder")} in the backups directory ${p.left === 1 ? "is" : "are"} not ours and will be left.`);
|
|
170
|
+
return { lines, question: "Delete all backups now?", empty: p.daily + p.preMigration === 0 };
|
|
171
|
+
}
|
|
172
|
+
const days = logDates(dir).length;
|
|
173
|
+
return {
|
|
174
|
+
lines: [`Activity log: ${plural(days, "day")} of files.`, "It holds what the processes did, never what was said."],
|
|
175
|
+
question: "Delete the activity log now?",
|
|
176
|
+
empty: days === 0,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Do it, and say what happened. Returns the counts for the row. */
|
|
181
|
+
function act(kind: DeleteKind, dir: string, store: Store): { ok: boolean; said: string[]; counts: Record<string, number> } {
|
|
182
|
+
if (kind === "conversation-text") {
|
|
183
|
+
const before = planConversationText(store);
|
|
184
|
+
const r = deleteConversationText(store);
|
|
185
|
+
return {
|
|
186
|
+
ok: r.ok,
|
|
187
|
+
said: r.ok
|
|
188
|
+
? [`Deleted ${plural(r.lines, "line")} of conversation text from ${plural(before.sessions, "session")}.`]
|
|
189
|
+
: [`The delete did not finish (${r.reason}); ${plural(r.lines, "line")} went. Run it again.`],
|
|
190
|
+
counts: { sessions: before.sessions, owed: before.owed, lines: r.lines },
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
if (kind === "backups") {
|
|
194
|
+
let copies = 0;
|
|
195
|
+
let left = 0;
|
|
196
|
+
const errors: string[] = [];
|
|
197
|
+
for (const d of backupDirs(dir)) {
|
|
198
|
+
try {
|
|
199
|
+
const r = deleteAllCopies(dir, d);
|
|
200
|
+
copies += r.deleted.length;
|
|
201
|
+
left += r.left.length;
|
|
202
|
+
errors.push(...r.errors);
|
|
203
|
+
} catch (err) {
|
|
204
|
+
errors.push(String((err as Error).message ?? err));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const said = [`Deleted ${plural(copies, "backup")}.`];
|
|
208
|
+
if (left > 0) said.push(`Left ${plural(left, "folder")} that ${left === 1 ? "is" : "are"} not ours.`);
|
|
209
|
+
for (const e of errors.slice(0, 5)) said.push(` could not: ${e}`);
|
|
210
|
+
return { ok: errors.length === 0, said, counts: { copies, left, errors: errors.length } };
|
|
211
|
+
}
|
|
212
|
+
const r = clearLog(dir);
|
|
213
|
+
return {
|
|
214
|
+
ok: r.failed === 0,
|
|
215
|
+
said: [`Deleted ${plural(r.removed, "day")} of activity log.${r.failed > 0 ? ` ${plural(r.failed, "file")} would not go.` : ""}`],
|
|
216
|
+
counts: { files: r.removed, failed: r.failed },
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export async function deleteCommand(
|
|
221
|
+
dir: string,
|
|
222
|
+
io: Io,
|
|
223
|
+
env: UiEnv,
|
|
224
|
+
positional: readonly string[],
|
|
225
|
+
flags: Record<string, string | boolean | undefined>,
|
|
226
|
+
): Promise<number> {
|
|
227
|
+
const kind = positional[0];
|
|
228
|
+
if (kind === undefined || !(DELETE_KINDS as readonly string[]).includes(kind) || positional.length > 1) {
|
|
229
|
+
io.err(`delete takes one kind: ${DELETE_KINDS.join(", ")}.`);
|
|
230
|
+
return EXIT.usage;
|
|
231
|
+
}
|
|
232
|
+
const k = kind as DeleteKind;
|
|
233
|
+
const plan = describe(k, dir);
|
|
234
|
+
for (const line of plan.lines) io.out(line);
|
|
235
|
+
if (plan.empty) {
|
|
236
|
+
io.out(`There is nothing to delete. ${NOTHING_CHANGED}`);
|
|
237
|
+
return EXIT.ok;
|
|
238
|
+
}
|
|
239
|
+
if (flags["yes"] !== true) {
|
|
240
|
+
if (!isInteractive(io, env)) {
|
|
241
|
+
io.out(`${NOTHING_CHANGED} To delete: counterparts delete ${k} --yes`);
|
|
242
|
+
return EXIT.ok;
|
|
243
|
+
}
|
|
244
|
+
let go: boolean;
|
|
245
|
+
try {
|
|
246
|
+
go = await confirm(io, plan.question, { default: false });
|
|
247
|
+
} catch (err) {
|
|
248
|
+
if (!isPromptAborted(err)) throw err;
|
|
249
|
+
go = false;
|
|
250
|
+
}
|
|
251
|
+
if (!go) {
|
|
252
|
+
io.out(NOTHING_CHANGED);
|
|
253
|
+
return EXIT.refused;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const store = openStoreAt({ dir });
|
|
257
|
+
try {
|
|
258
|
+
const done = act(k, dir, store);
|
|
259
|
+
for (const line of done.said) io.out(line);
|
|
260
|
+
try {
|
|
261
|
+
store.appendEvent({
|
|
262
|
+
name: OWNER_DELETED_EVENT,
|
|
263
|
+
day: store.livedDay(),
|
|
264
|
+
payload: { kind: k, ok: done.ok, ...done.counts },
|
|
265
|
+
});
|
|
266
|
+
} catch {
|
|
267
|
+
io.err("(the record of this delete could not be written)");
|
|
268
|
+
}
|
|
269
|
+
return done.ok ? EXIT.ok : EXIT.failed;
|
|
270
|
+
} finally {
|
|
271
|
+
store.close();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -580,7 +580,7 @@ export function exportCommand(
|
|
|
580
580
|
// no export kind carries it, and a person taking "a copy of my memory"
|
|
581
581
|
// somewhere should not have to discover which half stayed behind.
|
|
582
582
|
io.out(
|
|
583
|
-
"Not included: spans/ — the raw captured conversation,
|
|
583
|
+
"Not included: spans/ — the raw captured conversation, deleted 3 days after a session is written up and ended, and never kept more than 14 days.",
|
|
584
584
|
);
|
|
585
585
|
// THE DURABLE ROW. Counts and flags only: which kind, how many rows went,
|
|
586
586
|
// how many confidential ones were left out, whether it was sealed. NOT the
|