counterparts 0.3.0 → 0.3.1
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 +28 -0
- package/package.json +2 -1
- package/src/adapters/claude-code/CONTRACT.md +2 -1
- package/src/adapters/claude-code/NOTES.md +58 -2
- package/src/adapters/claude-code/bin/hook.ts +2 -0
- package/src/adapters/claude-code/bin/runner.ts +1 -0
- package/src/adapters/claude-code/doctor.ts +110 -7
- package/src/adapters/claude-code/hooks.ts +5 -0
- package/src/adapters/claude-code/index.ts +1 -0
- package/src/adapters/claude-code/standdown.ts +12 -1
- package/src/adapters/claude-code/transcript.ts +79 -6
- package/src/adapters/cli/INTERFACE-GAPS.md +4 -0
- package/src/adapters/cli/commands.ts +32 -3
- package/src/adapters/cli/snapshot.ts +4 -27
- package/src/adapters/dashboard/INTERFACE-GAPS.md +4 -0
- package/src/adapters/fired.ts +110 -14
- package/src/adapters/mcp/INTERFACE-GAPS.md +4 -1
- package/src/adapters/mcp/bin/serve.ts +5 -1
- package/src/adapters/mcp/index.ts +4 -0
- package/src/adapters/mcp/server.ts +5 -1
- package/src/adapters/sessions.ts +18 -1
- package/src/adapters/snapshots.ts +71 -39
- package/src/core/associate/INTERFACE-GAPS.md +8 -0
- package/src/core/counterpart.ts +56 -6
- package/src/core/encode/INTERFACE-GAPS.md +12 -0
- package/src/core/handoff/INTERFACE-GAPS.md +2 -0
- package/src/core/prospective/INTERFACE-GAPS.md +4 -0
- package/src/core/recall/INTERFACE-GAPS.md +6 -0
- package/src/core/remember/INTERFACE-GAPS.md +10 -0
- package/src/core/schemas/INTERFACE-GAPS.md +8 -0
- package/src/core/schemas/NOTES.md +118 -1
- package/src/core/schemas/index.ts +330 -40
- package/src/core/schemas/tunables.ts +23 -0
- package/src/core/schemas/types.ts +64 -1
- package/src/core/self/CONTRACT.md +3 -0
- package/src/core/self/INTERFACE-GAPS.md +10 -0
- package/src/core/self/NOTES.md +16 -2
- package/src/core/self/episodes.ts +53 -12
- package/src/core/self/index.ts +8 -1
- package/src/core/sleep/NOTES.md +36 -0
- package/src/core/sleep/cycle.ts +30 -1
- package/src/core/sleep/fade.ts +76 -0
- package/src/core/sleep/index.ts +4 -1
- package/src/core/sleep/prune.ts +8 -1
- package/src/core/sleep/tunables.ts +5 -0
- package/src/core/sleep/types.ts +24 -0
- package/src/core/store/CONTRACT.md +10 -0
- package/src/core/store/NOTES.md +55 -0
- package/src/core/store/errors.ts +7 -0
- package/src/core/store/index.ts +42 -0
- package/src/core/store/operational.ts +107 -11
- package/src/core/store/paths.ts +15 -1
- package/src/core/store/pre-migration.ts +256 -0
|
@@ -4938,7 +4938,8 @@ export function askGist(title: string | null, body: string): string {
|
|
|
4938
4938
|
|
|
4939
4939
|
/**
|
|
4940
4940
|
* The quieter line under an answer: what it is, when, and its id —
|
|
4941
|
-
* `self · chapter 1 · Wed 23 Sep 2026 · lived day 2 · mem_0a1b2c3d4e5f
|
|
4941
|
+
* `self · chapter 1 · Wed 23 Sep 2026 · claude-opus-5-5 · lived day 2 · mem_0a1b2c3d4e5f`
|
|
4942
|
+
* (the model only where the heading names one).
|
|
4942
4943
|
*
|
|
4943
4944
|
* The DATE is the one the chapter's own heading names when it names one (a
|
|
4944
4945
|
* chapter written since 2026-09-24 carries the day it was written, in the
|
|
@@ -4958,6 +4959,7 @@ export function askMeta(
|
|
|
4958
4959
|
}
|
|
4959
4960
|
const date = lead.date ?? (learnedOn === null ? "" : readableDate(learnedOn));
|
|
4960
4961
|
if (date.length > 0) parts.push(date);
|
|
4962
|
+
if (lead.model !== null) parts.push(lead.model);
|
|
4961
4963
|
if (lead.livedDay !== null) parts.push(`lived day ${String(lead.livedDay)}`);
|
|
4962
4964
|
parts.push(m.id);
|
|
4963
4965
|
return parts.join(" · ");
|
|
@@ -7955,14 +7957,32 @@ export function openCounterpart(
|
|
|
7955
7957
|
// one way, with a name from a flag instead of from `claude-code.json`.
|
|
7956
7958
|
// `embed` likewise: the option every composition root hands its embedder's
|
|
7957
7959
|
// sync face through (`ask`, 2026-09-24).
|
|
7960
|
+
const snapshotsDir = observer ? undefined : snapshotsDirBeside(dir);
|
|
7958
7961
|
return Counterpart.open({
|
|
7959
7962
|
dir,
|
|
7960
7963
|
observer,
|
|
7961
7964
|
...(identity === undefined ? {} : { identity }),
|
|
7962
7965
|
...(embed === undefined ? {} : { embed }),
|
|
7966
|
+
...(snapshotsDir === undefined ? {} : { snapshotsDir }),
|
|
7963
7967
|
});
|
|
7964
7968
|
}
|
|
7965
7969
|
|
|
7970
|
+
/**
|
|
7971
|
+
* `snapshots.dir` from the host configuration beside the store
|
|
7972
|
+
* (`<base>/claude-code.json`, the file `install` writes), so a migration the
|
|
7973
|
+
* console runs puts its copy where the worker's rotation and doctor look.
|
|
7974
|
+
* Absent, unreadable or unset: undefined, and the store's default applies.
|
|
7975
|
+
*/
|
|
7976
|
+
export function snapshotsDirBeside(dir: string): string | undefined {
|
|
7977
|
+
const beside = join(dir, "..", "claude-code.json");
|
|
7978
|
+
if (!existsSync(beside)) return undefined;
|
|
7979
|
+
try {
|
|
7980
|
+
return loadConfig(JSON.parse(readFileSync(beside, "utf8"))).config.snapshots?.dir;
|
|
7981
|
+
} catch {
|
|
7982
|
+
return undefined;
|
|
7983
|
+
}
|
|
7984
|
+
}
|
|
7985
|
+
|
|
7966
7986
|
// ── doctor ──────────────────────────────────────────────────────────────────
|
|
7967
7987
|
|
|
7968
7988
|
/**
|
|
@@ -8160,8 +8180,17 @@ function doctorCommand(
|
|
|
8160
8180
|
// `Counterpart.open` throws at every session start (H1). Inside this `try`
|
|
8161
8181
|
// rather than above it, because `doctor` is the command people run BECAUSE
|
|
8162
8182
|
// something is wrong, and its own reading must not be the thing that throws.
|
|
8163
|
-
const open = storeExists(dir) ? readCounterpartOpen(dir) : undefined;
|
|
8164
|
-
if (storeExists(dir))
|
|
8183
|
+
const open = storeExists(dir) ? readCounterpartOpen(dir, undefined, config.snapshots?.dir) : undefined;
|
|
8184
|
+
if (storeExists(dir)) {
|
|
8185
|
+
try {
|
|
8186
|
+
store = Store.open({ dir, observer: true });
|
|
8187
|
+
} catch (err) {
|
|
8188
|
+
// A store BEHIND this build refuses an observer until a session has
|
|
8189
|
+
// upgraded it; the Store open line already grades that, so the rest of
|
|
8190
|
+
// the reading goes on without a handle rather than failing.
|
|
8191
|
+
if (open?.migration === undefined || !isStoreError(err, "STORE_UNINITIALIZED")) throw err;
|
|
8192
|
+
}
|
|
8193
|
+
}
|
|
8165
8194
|
const findings = doctorFindings({
|
|
8166
8195
|
configPath,
|
|
8167
8196
|
configReason: reason,
|
|
@@ -34,10 +34,10 @@ import {
|
|
|
34
34
|
} from "node:fs";
|
|
35
35
|
import { basename, dirname, join, resolve } from "node:path";
|
|
36
36
|
|
|
37
|
-
import { openDb } from "../../core/store/db.js";
|
|
38
37
|
import {
|
|
39
38
|
DATABASE_FILE,
|
|
40
39
|
LAYOUT,
|
|
40
|
+
vacuumInto,
|
|
41
41
|
assertSafeDataDir,
|
|
42
42
|
forbiddenRoots,
|
|
43
43
|
isWithin,
|
|
@@ -246,32 +246,9 @@ export function snapshot(store: Store, target: string): SnapshotReport {
|
|
|
246
246
|
return { ok: errors.length === 0, target: resolvedTarget, copied, excluded, errors };
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
/**
|
|
250
|
-
*
|
|
251
|
-
|
|
252
|
-
* silently replaces yesterday's is one crash away from being no backup at all.
|
|
253
|
-
*/
|
|
254
|
-
export function vacuumInto(
|
|
255
|
-
source: string,
|
|
256
|
-
destination: string,
|
|
257
|
-
): { ok: true } | { ok: false; error: string } {
|
|
258
|
-
if (!existsSync(source)) return { ok: false, error: "no canonical database at source" };
|
|
259
|
-
if (existsSync(destination)) {
|
|
260
|
-
return { ok: false, error: `destination already exists: ${destination}` };
|
|
261
|
-
}
|
|
262
|
-
let db;
|
|
263
|
-
try {
|
|
264
|
-
db = openDb(source);
|
|
265
|
-
// Single-quoted SQL literal: the path is escaped for SQL, never interpolated
|
|
266
|
-
// into a shell, because nothing here shells out.
|
|
267
|
-
db.exec(`VACUUM INTO '${destination.replace(/'/g, "''")}'`);
|
|
268
|
-
return { ok: true };
|
|
269
|
-
} catch (err) {
|
|
270
|
-
return { ok: false, error: String((err as Error).message ?? err) };
|
|
271
|
-
} finally {
|
|
272
|
-
db?.close();
|
|
273
|
-
}
|
|
274
|
-
}
|
|
249
|
+
/** `VACUUM INTO` on its own connection — the store's own copy primitive, kept
|
|
250
|
+
* exported here for the callers that always found it here. */
|
|
251
|
+
export { vacuumInto };
|
|
275
252
|
|
|
276
253
|
/** A snapshot directory name that sorts chronologically and never collides. */
|
|
277
254
|
export function snapshotName(at: number): string {
|
|
@@ -10,6 +10,8 @@ of debt that goes silent if it is not written down.
|
|
|
10
10
|
|
|
11
11
|
## §1 — A read-only open still writes. `store/cache.ts`, `openCache`
|
|
12
12
|
|
|
13
|
+
**Closed 2026-09-24** — `store/cache.ts#openCache` writes the version row only when it differs, and leaves a cache from a newer build as found (`cacheAhead`, #190). The dashboard test's box-3 split may now be tightened.
|
|
14
|
+
|
|
13
15
|
**Found by:** the byte-identical test, on its first run.
|
|
14
16
|
|
|
15
17
|
**Have:** `Store.open` constructs box 3 through `openCache`, which unconditionally
|
|
@@ -71,6 +73,8 @@ records are not, so the two are not interchangeable for an old cycle.
|
|
|
71
73
|
|
|
72
74
|
## §3 — `self.enumerate` drops what it cannot read
|
|
73
75
|
|
|
76
|
+
**Closed 2026-09-24** — `self/identity.ts#enumerate` returns `absences` (`removed` / `unreadable`, and whether the row was protected, from the row or its tombstone). A `list({ protected: true })` filter is still absent.
|
|
77
|
+
|
|
74
78
|
**Found by:** the identity-view test that removes a protected element.
|
|
75
79
|
|
|
76
80
|
**Have:** `self/identity.ts`'s `enumerateOne` returns `null` when `readProse` or
|
package/src/adapters/fired.ts
CHANGED
|
@@ -143,7 +143,27 @@ export type ProbeId =
|
|
|
143
143
|
| `versions:${string}`;
|
|
144
144
|
|
|
145
145
|
export type Evidence =
|
|
146
|
-
| {
|
|
146
|
+
| {
|
|
147
|
+
readonly kind: "event";
|
|
148
|
+
readonly names: readonly DurableEventName[];
|
|
149
|
+
/**
|
|
150
|
+
* A NUMERIC PAYLOAD FIELD THAT MUST BE ABOVE ZERO for a row to count
|
|
151
|
+
* (2026-09-25, the entity-card fade). Some mechanisms have no row of their
|
|
152
|
+
* own and ride a row that lands whether they did anything or not: the fade
|
|
153
|
+
* is a count on the nightly `sleep.cycle` row, and reading that row plain
|
|
154
|
+
* would grade every night as a fade. With this set, a row counts toward
|
|
155
|
+
* `total`, the two windows and `lastFired` only when `payload[positive]`
|
|
156
|
+
* is a number greater than zero — a `null` (a cycle that died before it
|
|
157
|
+
* could count, scar §2.4) is not a zero and is not a firing either.
|
|
158
|
+
*
|
|
159
|
+
* The unit is still ROWS, like every other line on this page: a night that
|
|
160
|
+
* faded three cards is one firing. And a filtered reading carries NO
|
|
161
|
+
* refusals of its own — the row's refusal reader answers for every phase
|
|
162
|
+
* on it, and none of that is this mechanism's to claim. A mechanism that
|
|
163
|
+
* wants a refusal column names one with `Mechanism.refusals`.
|
|
164
|
+
*/
|
|
165
|
+
readonly positive?: string;
|
|
166
|
+
}
|
|
147
167
|
/** `undated`: the one line to print when the probe yields a count and no date
|
|
148
168
|
* at all — a column with no history is blind however many rows it holds. */
|
|
149
169
|
| { readonly kind: "probe"; readonly probe: ProbeId; readonly undated?: string }
|
|
@@ -534,6 +554,31 @@ export const MECHANISMS: readonly Mechanism[] = [
|
|
|
534
554
|
since: "2026-09-20",
|
|
535
555
|
},
|
|
536
556
|
},
|
|
557
|
+
{
|
|
558
|
+
// The entity-card fade (#215, 2026-09-24): its own sleep phase right after
|
|
559
|
+
// the prune, which now leaves cards alone (sleep NOTES §17). Its per-card
|
|
560
|
+
// events — `schema.faded`, `sleep.faded` — are in-process ring events, and
|
|
561
|
+
// the card itself is archived `faded-by-decay` with no date, so the one
|
|
562
|
+
// DURABLE trace is the `faded` count on the cycle row. Read plain, that row
|
|
563
|
+
// would make every night a fade; `positive` takes only the nights that
|
|
564
|
+
// faded something.
|
|
565
|
+
//
|
|
566
|
+
// **NO REFUSAL COLUMN, deliberately.** The phase's `fade/blocked:<reason>`
|
|
567
|
+
// skips count EVERY blocker of every card that stayed — `blockedBy` lists
|
|
568
|
+
// all the reasons a card may not fade, not the one that decided it — so
|
|
569
|
+
// even the rule-like ones (`has-live-attached-elements`, `identity-core`)
|
|
570
|
+
// land on cards nowhere near qualifying: the self card is blocked by
|
|
571
|
+
// `identity-core` at every sweep. Declaring them would reproduce the
|
|
572
|
+
// `dwell-too-short ×240` false alarm the prune row above describes. What
|
|
573
|
+
// would fix it: a per-card DECIDING reason, recorded only for cards whose
|
|
574
|
+
// physics verdict (the months of quiet) had already passed.
|
|
575
|
+
id: "fade",
|
|
576
|
+
label:
|
|
577
|
+
"a card nobody has mentioned in months fades out of the vocabulary (gently: months of quiet, longer for people)",
|
|
578
|
+
module: "sleep/fade.ts, schemas/index.ts",
|
|
579
|
+
evidence: { kind: "event", names: ["sleep.cycle"], positive: "faded" },
|
|
580
|
+
since: "2026-09-24",
|
|
581
|
+
},
|
|
537
582
|
{
|
|
538
583
|
id: "revision",
|
|
539
584
|
label: "a belief took a credited challenge and was revised under the pressure",
|
|
@@ -1153,7 +1198,7 @@ function readEvidence(m: Mechanism, log: LogRead, probed: Probed | null): Readin
|
|
|
1153
1198
|
? { ...EMPTY_READING, evidence: "no durable row", blind: m.evidence.reason }
|
|
1154
1199
|
: m.evidence.kind === "probe"
|
|
1155
1200
|
? probeReading(m.evidence.probe, m.evidence.undated ?? null, probed)
|
|
1156
|
-
: eventReading(m.evidence.names, log);
|
|
1201
|
+
: eventReading(m.evidence.names, log, m.evidence.positive);
|
|
1157
1202
|
if (m.refusals === undefined) return base;
|
|
1158
1203
|
// Refusals from ANOTHER row, folded in without touching the counts that say
|
|
1159
1204
|
// whether this mechanism fired.
|
|
@@ -1193,7 +1238,11 @@ function refusalReading(src: RefusalSource, log: LogRead): { refused: number; re
|
|
|
1193
1238
|
return { refused, refusals };
|
|
1194
1239
|
}
|
|
1195
1240
|
|
|
1196
|
-
function eventReading(
|
|
1241
|
+
function eventReading(
|
|
1242
|
+
names: readonly DurableEventName[],
|
|
1243
|
+
log: LogRead,
|
|
1244
|
+
positive?: string,
|
|
1245
|
+
): Reading {
|
|
1197
1246
|
let total = 0;
|
|
1198
1247
|
let inWindow = 0;
|
|
1199
1248
|
let inPreviousWindow = 0;
|
|
@@ -1201,7 +1250,7 @@ function eventReading(names: readonly DurableEventName[], log: LogRead): Reading
|
|
|
1201
1250
|
let lastFired: string | null = null;
|
|
1202
1251
|
const refusals = new Map<string, number>();
|
|
1203
1252
|
for (const name of names) {
|
|
1204
|
-
const t = log.byName.get(name);
|
|
1253
|
+
const t = log.byName.get(positive === undefined ? name : filteredKey(name, positive));
|
|
1205
1254
|
if (t === undefined) continue;
|
|
1206
1255
|
total += t.total;
|
|
1207
1256
|
inWindow += t.inWindow;
|
|
@@ -1221,7 +1270,9 @@ function eventReading(names: readonly DurableEventName[], log: LogRead): Reading
|
|
|
1221
1270
|
refused,
|
|
1222
1271
|
topRefusal: topOf(refusals),
|
|
1223
1272
|
refusals,
|
|
1224
|
-
evidence:
|
|
1273
|
+
// The filter is part of the evidence: `sleep.cycle` alone would read as the
|
|
1274
|
+
// same row the `sleep-cycle` line is, to the reader who greps.
|
|
1275
|
+
evidence: positive === undefined ? names.join(", ") : `${names.join(", ")} (${positive} > 0)`,
|
|
1225
1276
|
refusalEvidence: names.join(", "),
|
|
1226
1277
|
blind: null,
|
|
1227
1278
|
};
|
|
@@ -1256,6 +1307,32 @@ interface LogRead {
|
|
|
1256
1307
|
readonly oldestDate: string | null;
|
|
1257
1308
|
}
|
|
1258
1309
|
|
|
1310
|
+
/**
|
|
1311
|
+
* The tally key for a name read through a `positive` filter. A character no
|
|
1312
|
+
* durable event name carries, so it cannot collide with a real one.
|
|
1313
|
+
*/
|
|
1314
|
+
function filteredKey(name: string, field: string): string {
|
|
1315
|
+
return `${name}#${field}`;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
/**
|
|
1319
|
+
* Every payload filter the registry declares, by event name — derived from
|
|
1320
|
+
* `MECHANISMS` rather than listed, so a row that adds a filter is tallied
|
|
1321
|
+
* without a second list to keep in step.
|
|
1322
|
+
*/
|
|
1323
|
+
const POSITIVE_FIELDS: ReadonlyMap<string, readonly string[]> = (() => {
|
|
1324
|
+
const out = new Map<string, string[]>();
|
|
1325
|
+
for (const m of MECHANISMS) {
|
|
1326
|
+
if (m.evidence.kind !== "event" || m.evidence.positive === undefined) continue;
|
|
1327
|
+
for (const name of m.evidence.names) {
|
|
1328
|
+
const fields = out.get(name) ?? [];
|
|
1329
|
+
if (!fields.includes(m.evidence.positive)) fields.push(m.evidence.positive);
|
|
1330
|
+
out.set(name, fields);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
return out;
|
|
1334
|
+
})();
|
|
1335
|
+
|
|
1259
1336
|
function emptyTally(): NameTally {
|
|
1260
1337
|
return {
|
|
1261
1338
|
total: 0,
|
|
@@ -1305,19 +1382,19 @@ function tallyRow(
|
|
|
1305
1382
|
w: Window,
|
|
1306
1383
|
age: { oldest: string | null },
|
|
1307
1384
|
): void {
|
|
1308
|
-
let t = byName.get(row.name);
|
|
1309
|
-
if (t === undefined) {
|
|
1310
|
-
t = emptyTally();
|
|
1311
|
-
byName.set(row.name, t);
|
|
1312
|
-
}
|
|
1313
|
-
t.total += 1;
|
|
1314
1385
|
const payload = payloadOf(row);
|
|
1315
1386
|
const date = rowDate(row, payload);
|
|
1316
1387
|
if (age.oldest === null || date < age.oldest) age.oldest = date;
|
|
1317
|
-
|
|
1388
|
+
const t = countInto(byName, row.name, date, w);
|
|
1389
|
+
// THE FILTERED TALLIES, in the same pass (`Evidence.positive`). They count
|
|
1390
|
+
// the row and NOTHING ELSE: the refusal reader below answers for every phase
|
|
1391
|
+
// on a cycle row, and a filtered tally that copied it would hand the fade
|
|
1392
|
+
// row `prune/blocked:dwell-too-short ×240` on its own line.
|
|
1393
|
+
for (const field of POSITIVE_FIELDS.get(row.name) ?? []) {
|
|
1394
|
+
const v = payload[field];
|
|
1395
|
+
if (typeof v === "number" && v > 0) countInto(byName, filteredKey(row.name, field), date, w);
|
|
1396
|
+
}
|
|
1318
1397
|
const inWindow = date >= w.from && date <= w.to;
|
|
1319
|
-
if (inWindow) t.inWindow += 1;
|
|
1320
|
-
else if (date >= w.previousFrom && date <= w.previousTo) t.inPreviousWindow += 1;
|
|
1321
1398
|
if (!inWindow) return;
|
|
1322
1399
|
const reader = REFUSAL_READERS[row.name];
|
|
1323
1400
|
if (reader === undefined) return;
|
|
@@ -1328,6 +1405,25 @@ function tallyRow(
|
|
|
1328
1405
|
}
|
|
1329
1406
|
}
|
|
1330
1407
|
|
|
1408
|
+
/** One row counted under `key`: its total, its date, and which window it fell in. */
|
|
1409
|
+
function countInto(
|
|
1410
|
+
byName: Map<string, NameTally>,
|
|
1411
|
+
key: string,
|
|
1412
|
+
date: string,
|
|
1413
|
+
w: Window,
|
|
1414
|
+
): NameTally {
|
|
1415
|
+
let t = byName.get(key);
|
|
1416
|
+
if (t === undefined) {
|
|
1417
|
+
t = emptyTally();
|
|
1418
|
+
byName.set(key, t);
|
|
1419
|
+
}
|
|
1420
|
+
t.total += 1;
|
|
1421
|
+
if (t.lastDate === null || date > t.lastDate) t.lastDate = date;
|
|
1422
|
+
if (date >= w.from && date <= w.to) t.inWindow += 1;
|
|
1423
|
+
else if (date >= w.previousFrom && date <= w.previousTo) t.inPreviousWindow += 1;
|
|
1424
|
+
return t;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1331
1427
|
/** The CALENDAR date a row is about: its own field, else the wall clock it was
|
|
1332
1428
|
* written at. `day` is the lived-day column and answers a different question. */
|
|
1333
1429
|
function rowDate(row: EventRow, payload: Record<string, unknown>): string {
|
|
@@ -299,7 +299,10 @@ JSON" was narrowed to what stays true: never without a notice, and never the doc
|
|
|
299
299
|
|
|
300
300
|
**Also filed from this build, for the modules that own them.**
|
|
301
301
|
|
|
302
|
-
-
|
|
302
|
+
- **Closed 2026-09-24** — `store/cache.ts#openCache` now leaves a cache from a newer build
|
|
303
|
+
as found (`cacheAhead`, #190).
|
|
304
|
+
|
|
305
|
+
**`store/cache.ts#openCache` stamps an AHEAD cache backwards.** It re-runs the DDL and
|
|
303
306
|
rewrites `cache_meta.schemaVersion` whenever the stamp DIFFERS, so a build opening a cache
|
|
304
307
|
a newer build wrote writes the older number over it instead of refusing, the way
|
|
305
308
|
`operational.ts` refuses `SCHEMA_AHEAD`. Not this server's hole (it never reopens) — a
|
|
@@ -169,6 +169,8 @@ export function launchOptions(
|
|
|
169
169
|
export function questionEmbedder(path = CONFIG_PATH): {
|
|
170
170
|
embedder: LiveEmbedder | null;
|
|
171
171
|
reason: string;
|
|
172
|
+
/** The configuration's `snapshots.dir`, for the store's pre-migration copy. */
|
|
173
|
+
snapshotsDir?: string;
|
|
172
174
|
} {
|
|
173
175
|
let raw: unknown;
|
|
174
176
|
try {
|
|
@@ -184,6 +186,7 @@ export function questionEmbedder(path = CONFIG_PATH): {
|
|
|
184
186
|
const config = withEmbedderDefault(load.config);
|
|
185
187
|
return {
|
|
186
188
|
reason: load.reason,
|
|
189
|
+
...(config.snapshots?.dir === undefined ? {} : { snapshotsDir: config.snapshots.dir }),
|
|
187
190
|
// `openEmbedder` is the ONE answer to "is there an embedder": the knob is
|
|
188
191
|
// the gate and an observer gets none.
|
|
189
192
|
embedder: openEmbedder(config),
|
|
@@ -228,7 +231,7 @@ async function main(): Promise<void> {
|
|
|
228
231
|
process.exitCode = 1;
|
|
229
232
|
return;
|
|
230
233
|
}
|
|
231
|
-
const { embedder, reason } = questionEmbedder(choice.path);
|
|
234
|
+
const { embedder, reason, snapshotsDir } = questionEmbedder(choice.path);
|
|
232
235
|
const unreadable = namedUnreadableRefusal(choice, reason);
|
|
233
236
|
if (unreadable !== null) {
|
|
234
237
|
process.stderr.write(`${unreadable}\n`);
|
|
@@ -290,6 +293,7 @@ async function main(): Promise<void> {
|
|
|
290
293
|
observer: stance === "observer" || opts.observer,
|
|
291
294
|
scopesFile,
|
|
292
295
|
embedder,
|
|
296
|
+
...(snapshotsDir === undefined ? {} : { snapshotsDir }),
|
|
293
297
|
});
|
|
294
298
|
// THE BUILD THIS PROCESS WILL KEEP FOR THE REST OF THE SESSION, left where
|
|
295
299
|
// the hooks can compare it with the installed one every turn
|
|
@@ -86,6 +86,9 @@ export interface OpenServerOptions extends Omit<McpServerOptions, "counterpart">
|
|
|
86
86
|
* paid seat's sync face is a cache, so passing it costs no call.
|
|
87
87
|
*/
|
|
88
88
|
embed?: Embedder;
|
|
89
|
+
/** Where the store's pre-migration copy goes — the host config's
|
|
90
|
+
* `snapshots.dir`, so it lands where rotation and doctor look. */
|
|
91
|
+
snapshotsDir?: string;
|
|
89
92
|
}
|
|
90
93
|
|
|
91
94
|
/** The sync face of a live embedder, when `embedder` is one. Duck-typed on purpose: this file must not import the claude-code adapter. */
|
|
@@ -104,6 +107,7 @@ export function openServer(opts: OpenServerOptions = {}): McpServer {
|
|
|
104
107
|
const counterpart = Counterpart.open({
|
|
105
108
|
...(embed === undefined ? {} : { embed }),
|
|
106
109
|
...(opts.dir === undefined ? {} : { dir: opts.dir }),
|
|
110
|
+
...(opts.snapshotsDir === undefined ? {} : { snapshotsDir: opts.snapshotsDir }),
|
|
107
111
|
...(opts.observer === undefined ? {} : { observer: opts.observer }),
|
|
108
112
|
...(opts.owner === undefined ? {} : { owner: opts.owner }),
|
|
109
113
|
});
|
|
@@ -110,7 +110,7 @@ export const SERVER_NAME = "counterparts";
|
|
|
110
110
|
* host decides whether to trust what follows. Read from a constant rather than
|
|
111
111
|
* from disk so the server opens no file to answer its first message.
|
|
112
112
|
*/
|
|
113
|
-
export const SERVER_VERSION = "0.3.
|
|
113
|
+
export const SERVER_VERSION = "0.3.1";
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
116
|
* THE ONE LINE EVERY TOOL ANSWERS WITH when the store on disk is a schema AHEAD
|
|
@@ -1657,10 +1657,14 @@ export class McpServer {
|
|
|
1657
1657
|
}
|
|
1658
1658
|
const session = this.session as string;
|
|
1659
1659
|
const title = args["title"];
|
|
1660
|
+
// The model the hooks last saw answer in this session. A Stop records it
|
|
1661
|
+
// before its ask goes out, so the chapter that answers the ask has it.
|
|
1662
|
+
const model = readSession(this.registryDir, session)?.model;
|
|
1660
1663
|
let written: ChapterResult;
|
|
1661
1664
|
try {
|
|
1662
1665
|
written = this.counterpart.appendEpisode(session, text, {
|
|
1663
1666
|
...(typeof title === "string" && title.length > 0 ? { title } : {}),
|
|
1667
|
+
...(model === undefined ? {} : { model }),
|
|
1664
1668
|
});
|
|
1665
1669
|
} catch (err) {
|
|
1666
1670
|
// A journal that throws must not look like a journal that refused.
|
package/src/adapters/sessions.ts
CHANGED
|
@@ -72,7 +72,7 @@ import type {
|
|
|
72
72
|
Span,
|
|
73
73
|
SpanBuffer,
|
|
74
74
|
} from "../core/remember/index.js";
|
|
75
|
-
import { episodeFacts } from "../core/self/index.js";
|
|
75
|
+
import { episodeFacts, isModelId } from "../core/self/index.js";
|
|
76
76
|
import { CACHE_SCHEMA_VERSION, SCHEMA_VERSION } from "../core/store/index.js";
|
|
77
77
|
import type { Store } from "../core/store/index.js";
|
|
78
78
|
|
|
@@ -243,6 +243,13 @@ export interface SessionRecord {
|
|
|
243
243
|
* Carried forward like `config`. Still host state: an id, a number, a word.
|
|
244
244
|
*/
|
|
245
245
|
readonly writeUpFor?: WriteUpFor;
|
|
246
|
+
/**
|
|
247
|
+
* The model that wrote the transcript's last assistant entry, as the host
|
|
248
|
+
* reports it (`claude-opus-5-5`). Refreshed at every boundary, carried like
|
|
249
|
+
* `config`; the `chapter` tool reads it so each chapter records its model.
|
|
250
|
+
* Still host state, still no content: an id.
|
|
251
|
+
*/
|
|
252
|
+
readonly model?: string;
|
|
246
253
|
}
|
|
247
254
|
|
|
248
255
|
/** The part of an ended session the MCP door handed a live one. */
|
|
@@ -383,6 +390,8 @@ export function recordSession(
|
|
|
383
390
|
/** The ended session the SessionStart hook pointed this one at (C2).
|
|
384
391
|
* Carried forward like `config`; the newest answer wins. */
|
|
385
392
|
writeUpPointer?: string;
|
|
393
|
+
/** The model that last answered. Carried like `config`; newest wins. */
|
|
394
|
+
model?: string;
|
|
386
395
|
},
|
|
387
396
|
): SessionRecord | null {
|
|
388
397
|
if (!isSessionId(input.sessionId)) return null;
|
|
@@ -468,6 +477,12 @@ export function recordSession(
|
|
|
468
477
|
? { writeUpPointer: prior.writeUpPointer }
|
|
469
478
|
: {}),
|
|
470
479
|
...(prior?.writeUpFor !== undefined ? { writeUpFor: prior.writeUpFor } : {}),
|
|
480
|
+
// Newest wins, so a /model switch shows at the next boundary.
|
|
481
|
+
...(isModelId(input.model)
|
|
482
|
+
? { model: input.model }
|
|
483
|
+
: prior?.model !== undefined
|
|
484
|
+
? { model: prior.model }
|
|
485
|
+
: {}),
|
|
471
486
|
};
|
|
472
487
|
|
|
473
488
|
return writeRecord(dataDir, path, record);
|
|
@@ -1129,6 +1144,8 @@ function parseRecord(raw: unknown): SessionRecord | null {
|
|
|
1129
1144
|
const writeUpFor = parseWriteUpFor(rec["writeUpFor"]);
|
|
1130
1145
|
return writeUpFor === null ? {} : { writeUpFor };
|
|
1131
1146
|
})(),
|
|
1147
|
+
// A value that is not a plain model id is no mark: it goes into a heading.
|
|
1148
|
+
...(isModelId(rec["model"]) ? { model: rec["model"] } : {}),
|
|
1132
1149
|
};
|
|
1133
1150
|
}
|
|
1134
1151
|
|