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
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.1 — unreleased
|
|
4
|
+
|
|
5
|
+
A small release of fixes. No change to the store's format, so no migration and no
|
|
6
|
+
Reconnect.
|
|
7
|
+
|
|
8
|
+
- **Cards for people, places and the identity core are no longer archived after about
|
|
9
|
+
90 days of use** (#215). The nightly cleanup was treating them like ordinary memories.
|
|
10
|
+
They now fade only through a gentle phase of their own: months of quiet on both the
|
|
11
|
+
lived and the calendar clock (180 days, 365 for people), never while beliefs still
|
|
12
|
+
hang on them, and never the identity core. Nobody's store is old enough to have been
|
|
13
|
+
hit, which is why this ships now.
|
|
14
|
+
- **A faded card comes back when a saved memory names it** (#220), and **a card named
|
|
15
|
+
in a saved memory counts as used** (#218), so the people and things you still talk
|
|
16
|
+
about stay live.
|
|
17
|
+
- **Prompts typed while Claude is still working are saved** (#213). They were missed
|
|
18
|
+
before, about one typed prompt in twelve.
|
|
19
|
+
- **A checked snapshot is taken before any change to the store's format** (#214). If the
|
|
20
|
+
copy can't be made, the change waits. `doctor` shows a store that needs one: red when
|
|
21
|
+
the copy can't be made, amber when it can.
|
|
22
|
+
- **Each journal chapter records the model that wrote it** (#217).
|
|
23
|
+
- **`counterparts fired` and `doctor` show fading** as a mechanism of its own.
|
|
24
|
+
|
|
25
|
+
## 0.3.0 — 2026-09-24
|
|
26
|
+
|
|
27
|
+
No API keys: nothing leaves the machine except through Claude Code. A quieter end-of-turn
|
|
28
|
+
ask, paced by what you type. `counterparts ask` searches by meaning.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "counterparts",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Memory that turns AI tools into counterparts - a local-first, human-memory-modeled memory layer for AI.",
|
|
6
6
|
"repository": {
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"tools/install-loop/",
|
|
50
50
|
"CONSTITUTION.md",
|
|
51
51
|
"README.md",
|
|
52
|
+
"CHANGELOG.md",
|
|
52
53
|
"LICENSE"
|
|
53
54
|
],
|
|
54
55
|
"dependencies": {
|
|
@@ -228,7 +228,8 @@ row, saying which source answered, existed until the keys were removed — §1a.
|
|
|
228
228
|
record is also WHERE THE SESSION IS FILED.** SessionStart writes
|
|
229
229
|
`<dataDir>/sessions/<id>.json` (id, scope, started, last boundary, and the marks a
|
|
230
230
|
later hook process needs: which configuration was read, whether the first-launch
|
|
231
|
-
question went out, the wake's sentinel and whether its arrival has been checked
|
|
231
|
+
question went out, the wake's sentinel and whether its arrival has been checked, the
|
|
232
|
+
model that last answered — which the `chapter` tool records per chapter), Stop
|
|
232
233
|
refreshes the clock — creating the record when it is missing — and SessionEnd closes
|
|
233
234
|
it. The writes
|
|
234
235
|
are atomic (temp + rename), tiny, and silent on failure, because a hook may not fail
|
|
@@ -1073,7 +1073,8 @@ one pacer — nothing here adds a second).
|
|
|
1073
1073
|
|
|
1074
1074
|
Measured 2026-09-23 on Claude Code 2.1.28x, reading **shapes only** (keys, flags, the
|
|
1075
1075
|
first few characters of host frames) across every transcript under `~/.claude/projects/`;
|
|
1076
|
-
no content was copied. `parseTranscript` reads only entries with a `message.role
|
|
1076
|
+
no content was copied. `parseTranscript` reads only entries with a `message.role` (and, since
|
|
1077
|
+
2026-09-24, the person's queued prompts).
|
|
1077
1078
|
|
|
1078
1079
|
| what | the entry's own metadata | text opens with | now |
|
|
1079
1080
|
|---|---|---|---|
|
|
@@ -1088,7 +1089,7 @@ no content was copied. `parseTranscript` reads only entries with a `message.role
|
|
|
1088
1089
|
| slash-command echo, `!`-command | no metadata | `<command-name>`, `<local-command-stdout>`, `<bash-input>`, `<bash-stdout>` | unchanged text rule; `<bash-stdout>`/`<bash-stderr>` now `injected` |
|
|
1089
1090
|
| an interrupt | `interruptedMessageId`, no origin | `[Request interrupted by user]` | `injected` |
|
|
1090
1091
|
| hook output (`UserPromptSubmit hook success`, `hook_additional_context`, `hook_system_message`) | `type: "attachment"`, **no role** | — | never a turn (unchanged) |
|
|
1091
|
-
| **a prompt typed while the model works** (review M3: 76 seen
|
|
1092
|
+
| **a prompt typed while the model works** (review M3: 76 seen) | `type: "attachment"`, `attachment.type: "queued_command"`, `commandMode: "prompt"`, `origin.kind: "human"` | — | `conversation` since 2026-09-24 — see "Prompts typed mid-turn" below (was never a turn) |
|
|
1092
1093
|
| an API error written as the assistant | `isApiErrorMessage: true`, `model: "<synthetic>"` | `API Error: …` | `injected` (was `conversation`) |
|
|
1093
1094
|
|
|
1094
1095
|
So "UserPromptSubmit hook success" was never counted by this reader: it is how the host
|
|
@@ -1123,6 +1124,61 @@ capture keeps its wrapper verbatim, labelled only by `injected`. It is out of pa
|
|
|
1123
1124
|
either way; whether capture should label it the way a `<cross-session-message>` is
|
|
1124
1125
|
labelled is a capture-quality question for another round.
|
|
1125
1126
|
|
|
1127
|
+
### Prompts typed mid-turn (2026-09-24)
|
|
1128
|
+
|
|
1129
|
+
A prompt the person types while the model is still working reaches the model inside
|
|
1130
|
+
the running turn, and the host writes it only as an attachment line:
|
|
1131
|
+
`type: "attachment"`, `attachment: { type: "queued_command", commandMode: "prompt",
|
|
1132
|
+
origin: { kind: "human" }, prompt, source_uuid, timestamp }`, sometimes `humanTurn: true`
|
|
1133
|
+
or `imagePasteIds`, with `rendered` on the entry. `prompt` is a string, or content blocks
|
|
1134
|
+
when an image was pasted. The same attachment type also carries host work —
|
|
1135
|
+
`commandMode: "task-notification"`, and `commandMode: "prompt"` with `origin.kind: "peer"`
|
|
1136
|
+
and `isMeta: true` (hand-backs) — which stays skipped.
|
|
1137
|
+
|
|
1138
|
+
`parseTranscript` now reads the human ones as a typed user turn at the position the line
|
|
1139
|
+
stands in, with its own entry ordinal, through the same `blocksOf`/`pieceOf` as a typed
|
|
1140
|
+
entry. A mode other than `prompt` (`bash`, say) is skipped; none was seen. A prompt
|
|
1141
|
+
that opens with `/` is kept, as the same typed words would be ("/tmp is full"); the
|
|
1142
|
+
host was never seen writing a slash command as a `prompt` attachment.
|
|
1143
|
+
|
|
1144
|
+
Measured on this project's 27 transcripts (shapes only): 33 such prompts, against 376
|
|
1145
|
+
typed turns before — 409 after, about 8% of what the person typed. The queue itself is
|
|
1146
|
+
logged as `queue-operation` lines (`enqueue`, `dequeue`, `remove` with
|
|
1147
|
+
`reason: "absorbed_mid_turn"`); a prompt still queued when the turn ends is instead
|
|
1148
|
+
written as an ordinary user entry with `promptSource: "queued"` (7 seen), which was
|
|
1149
|
+
always read.
|
|
1150
|
+
|
|
1151
|
+
**No twin was found.** None of the 33 was written again as a user entry. The only later
|
|
1152
|
+
copies are inside a compaction summary (7, all in one session; `injected`, never
|
|
1153
|
+
paced) and in the assistant's own tool calls. `source_uuid` matches no `uuid` or
|
|
1154
|
+
`promptId` in any file, and the attachment's `timestamp` is the line's own. So the
|
|
1155
|
+
dedupe is defensive: a user entry with `origin.kind: "human"`, `promptSource: "queued"`
|
|
1156
|
+
and the same text (whitespace collapsed) as a queued prompt already read is skipped,
|
|
1157
|
+
once per queued prompt. The first appearance is kept because the capture cursor is an
|
|
1158
|
+
index into the turn list, and the list may only grow.
|
|
1159
|
+
|
|
1160
|
+
The window is the person's next sent entry. Any other human entry closes it, so the
|
|
1161
|
+
same short words queued again much later ("yes") still count; a person who types them
|
|
1162
|
+
the ordinary way always counts. Assistant lines do not close it, because the turn goes
|
|
1163
|
+
on after the attachment, and a prompt still queued at a turn's end is written after
|
|
1164
|
+
`turn_duration`, as the next turn's first entry — where a twin would most likely sit.
|
|
1165
|
+
Review M3 counted 18 of 76 "written again" across all projects; if those are real
|
|
1166
|
+
user-entry twins with some other `promptSource`, they would count twice — check before
|
|
1167
|
+
widening the rule.
|
|
1168
|
+
|
|
1169
|
+
**Deploy note.** The capture cursor is an index. A session open across this deploy has
|
|
1170
|
+
a cursor from the old list; queued prompts before it now occupy slots, so the next
|
|
1171
|
+
boundary starts k turns early and re-captures the last k already-captured turns once
|
|
1172
|
+
(k = queued prompts before the cursor). Nothing is lost, but queued prompts from before
|
|
1173
|
+
the deploy are mostly not captured after the fact. A cursor that survives inserted turns
|
|
1174
|
+
is `INTERFACE-GAPS.md` §14's first ask.
|
|
1175
|
+
|
|
1176
|
+
Pacing moves once too. Turns only rise, so `rebasedWatermark` does not fire, but
|
|
1177
|
+
`sinceTurns` (`self/episodes.ts#askDue`, typed turns minus the watermark) jumps by the
|
|
1178
|
+
queued prompts from before the last ask, which the watermark never counted. A session
|
|
1179
|
+
open across the deploy may be re-asked at its next Stop. One time only: the next ask
|
|
1180
|
+
sets the watermark on the new count.
|
|
1181
|
+
|
|
1126
1182
|
### The Stop ask's shapes
|
|
1127
1183
|
|
|
1128
1184
|
**2026-09-24: ONE shape — `hookSpecificOutput.additionalContext` on Stop.**
|
|
@@ -383,6 +383,8 @@ export function toHookInput(
|
|
|
383
383
|
// (`hooks.ts#checkWakeArrival`), and a parsed turn list cannot answer for
|
|
384
384
|
// what the host injected.
|
|
385
385
|
...(transcriptPath === undefined ? {} : { transcriptPath }),
|
|
386
|
+
// The model that last answered, for the session record (and so the chapter).
|
|
387
|
+
...(transcript.model === undefined ? {} : { model: transcript.model }),
|
|
386
388
|
// The host's re-fire of a blocked Stop, carried INTO the adapter and not
|
|
387
389
|
// only handled at delivery: the pass that says nothing must also advance
|
|
388
390
|
// nothing (`hooks.ts#askAtStop`).
|
|
@@ -326,6 +326,7 @@ export async function runOnce(input: {
|
|
|
326
326
|
|
|
327
327
|
const counterpart = Counterpart.open({
|
|
328
328
|
dir: config.dataDir,
|
|
329
|
+
...(config.snapshots?.dir === undefined ? {} : { snapshotsDir: config.snapshots.dir }),
|
|
329
330
|
...(embedder === null ? {} : { embed: embedder.embed, vectors: embedder }),
|
|
330
331
|
...(config.injectionBudgetBytes === undefined
|
|
331
332
|
? {}
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
* nobody needed).
|
|
33
33
|
*/
|
|
34
34
|
import { spawnSync } from "node:child_process";
|
|
35
|
-
import { existsSync, statSync } from "node:fs";
|
|
35
|
+
import { existsSync, mkdirSync, rmSync, statSync } from "node:fs";
|
|
36
36
|
import { homedir } from "node:os";
|
|
37
37
|
import { dirname, join } from "node:path";
|
|
38
38
|
import { fileURLToPath } from "node:url";
|
|
@@ -53,7 +53,16 @@ import {
|
|
|
53
53
|
SWEEP_GATE_EVENT,
|
|
54
54
|
} from "../../core/counterpart.js";
|
|
55
55
|
import { Counterpart } from "../../core/counterpart.js";
|
|
56
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
STORE_CREATED_KEY,
|
|
58
|
+
Store,
|
|
59
|
+
assertPreMigrationTarget,
|
|
60
|
+
dateOf,
|
|
61
|
+
isStoreError,
|
|
62
|
+
paths,
|
|
63
|
+
pendingMigration,
|
|
64
|
+
preMigrationDir,
|
|
65
|
+
} from "../../core/store/index.js";
|
|
57
66
|
import { BUSY_TIMEOUT_MS, journalModeOf } from "../../core/store/db.js";
|
|
58
67
|
import type { EventRow } from "../../core/store/index.js";
|
|
59
68
|
// The ask allowance the amber hint names, read rather than retyped: a number in
|
|
@@ -553,6 +562,46 @@ export interface OpenReading {
|
|
|
553
562
|
* `MEMORY_BODY_MISSING` carries one and no path, because on this floor the
|
|
554
563
|
* words are the row and there is no file to restore (review B, MAJOR-3). */
|
|
555
564
|
readonly id: string | null;
|
|
565
|
+
/**
|
|
566
|
+
* The schema upgrade the next session will run, when the store is behind —
|
|
567
|
+
* and whether the copy it takes first can be made. An observer never
|
|
568
|
+
* migrates, so without this the open reads fine (or merely "behind") while
|
|
569
|
+
* every hook refuses `MIGRATION_SNAPSHOT_FAILED`. Absent: not behind.
|
|
570
|
+
*/
|
|
571
|
+
readonly migration?: MigrationReading;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
export interface MigrationReading {
|
|
575
|
+
readonly found: string;
|
|
576
|
+
readonly expected: number;
|
|
577
|
+
/** Where the copy would go; null when there is nowhere. */
|
|
578
|
+
readonly dir: string | null;
|
|
579
|
+
/** Why the copy could not be made, or null when the dry run passed. */
|
|
580
|
+
readonly problem: string | null;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* The pre-migration copy's preconditions, tried without taking it: the
|
|
585
|
+
* destination passes the store's own checks, and a probe directory can be
|
|
586
|
+
* made there and removed again (only what the probe itself created goes). The
|
|
587
|
+
* probe's name is a `.partial-…` one, so if its removal failed the daily sweep
|
|
588
|
+
* would take it.
|
|
589
|
+
*/
|
|
590
|
+
export function probePreMigration(storeDir: string, snapshotsDir?: string): MigrationReading | null {
|
|
591
|
+
const dbPath = paths.operational(storeDir);
|
|
592
|
+
const pending = pendingMigration(dbPath);
|
|
593
|
+
if (pending === null) return null;
|
|
594
|
+
const dir = preMigrationDir(dbPath, snapshotsDir);
|
|
595
|
+
try {
|
|
596
|
+
const real = assertPreMigrationTarget(dbPath, dir);
|
|
597
|
+
const instant = new Date().toISOString().replace(/[:.]/g, "-");
|
|
598
|
+
const probe = join(real, `.partial-${instant}-${String(process.pid)}`);
|
|
599
|
+
const first = mkdirSync(probe, { recursive: true });
|
|
600
|
+
rmSync(first ?? probe, { recursive: true, force: true });
|
|
601
|
+
return { ...pending, dir, problem: null };
|
|
602
|
+
} catch (err) {
|
|
603
|
+
return { ...pending, dir, problem: err instanceof Error ? err.message : String(err) };
|
|
604
|
+
}
|
|
556
605
|
}
|
|
557
606
|
|
|
558
607
|
/**
|
|
@@ -568,13 +617,18 @@ export function readCounterpartOpen(
|
|
|
568
617
|
/** Injectable so the failure branches are provable without a broken fixture;
|
|
569
618
|
* the fixture test is still the one that proves the real path. */
|
|
570
619
|
open: (d: string) => { close: () => void } = (d) => Counterpart.open({ dir: d, observer: true }),
|
|
620
|
+
/** The host configuration's `snapshots.dir`, for the pre-migration dry run. */
|
|
621
|
+
snapshotsDir?: string,
|
|
571
622
|
): OpenReading {
|
|
572
623
|
let opened: { close: () => void } | null = null;
|
|
624
|
+
const migration = probePreMigration(dir, snapshotsDir);
|
|
625
|
+
const behind = migration === null ? {} : { migration };
|
|
573
626
|
try {
|
|
574
627
|
// OBSERVER, because `doctor` is an instrument: it reads and never writes,
|
|
575
628
|
// and an owner open of a store that is not there would MINT one.
|
|
576
629
|
opened = open(dir);
|
|
577
630
|
return {
|
|
631
|
+
...behind,
|
|
578
632
|
dir,
|
|
579
633
|
ok: true,
|
|
580
634
|
code: null,
|
|
@@ -587,6 +641,7 @@ export function readCounterpartOpen(
|
|
|
587
641
|
} catch (err) {
|
|
588
642
|
const fault = describeFault(err);
|
|
589
643
|
return {
|
|
644
|
+
...behind,
|
|
590
645
|
dir,
|
|
591
646
|
ok: false,
|
|
592
647
|
code: fault.code,
|
|
@@ -609,6 +664,18 @@ export function readCounterpartOpen(
|
|
|
609
664
|
|
|
610
665
|
// ── the groups ──────────────────────────────────────────────────────────────
|
|
611
666
|
|
|
667
|
+
/** The Memory line for a store this build reads only after its upgrade. */
|
|
668
|
+
function behindFinding(dir: string, m: MigrationReading): Finding {
|
|
669
|
+
return finding(
|
|
670
|
+
"store",
|
|
671
|
+
"amber",
|
|
672
|
+
MEMORY_TITLE,
|
|
673
|
+
`${tilde(dir)} is on schema v${m.found}; this build reads it once a session has upgraded it (see Store open)`,
|
|
674
|
+
"",
|
|
675
|
+
{ dir, exists: true, found: m.found, expected: m.expected },
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
|
|
612
679
|
/** A finding, with `data` defaulted so each group below stays one expression. */
|
|
613
680
|
function finding(
|
|
614
681
|
key: string,
|
|
@@ -792,8 +859,11 @@ function configFindings(input: DoctorInput): Finding[] {
|
|
|
792
859
|
// same number because it is the same number, and rule 3 of this module —
|
|
793
860
|
// it is on the hot path, so it is bounded — is kept by not asking twice.
|
|
794
861
|
const held = input.store === null ? null : memoryCount(input.store);
|
|
862
|
+
const behind = input.store === null ? input.open?.migration : undefined;
|
|
795
863
|
out.push(
|
|
796
|
-
|
|
864
|
+
behind !== undefined
|
|
865
|
+
? behindFinding(input.dir, behind)
|
|
866
|
+
: input.store === null
|
|
797
867
|
? finding("store", "red", MEMORY_TITLE, `no store at ${tilde(input.dir)}`, "Check the path you gave --dir.", {
|
|
798
868
|
dir: input.dir,
|
|
799
869
|
exists: false,
|
|
@@ -859,7 +929,9 @@ function configFindings(input: DoctorInput): Finding[] {
|
|
|
859
929
|
// shape: the hooks and another entry point named different stores and nothing
|
|
860
930
|
// noticed, because each was internally consistent.
|
|
861
931
|
const named = input.config.dataDir;
|
|
862
|
-
if (input.store === null) {
|
|
932
|
+
if (input.store === null && input.open?.migration !== undefined) {
|
|
933
|
+
out.push(behindFinding(input.dir, input.open.migration));
|
|
934
|
+
} else if (input.store === null) {
|
|
863
935
|
out.push(
|
|
864
936
|
finding("store", "red", MEMORY_TITLE, `no store at ${tilde(input.dir)}`, "Run: counterparts install, or name the store with --dir.", {
|
|
865
937
|
dir: input.dir,
|
|
@@ -2023,6 +2095,31 @@ function openFindings(reading: OpenReading): Finding[] {
|
|
|
2023
2095
|
busy: reading.busy,
|
|
2024
2096
|
path: reading.path,
|
|
2025
2097
|
};
|
|
2098
|
+
// A STORE BEHIND THIS BUILD is graded on what a SESSION will meet, not on
|
|
2099
|
+
// what this observer open met: the session copies it, then upgrades it.
|
|
2100
|
+
const m = reading.migration;
|
|
2101
|
+
if (m !== undefined) {
|
|
2102
|
+
const upgrade = { ...data, found: m.found, expected: m.expected, snapshotsDir: m.dir, problem: m.problem };
|
|
2103
|
+
return [
|
|
2104
|
+
m.problem !== null
|
|
2105
|
+
? finding(
|
|
2106
|
+
"store-open",
|
|
2107
|
+
"red",
|
|
2108
|
+
"Store open",
|
|
2109
|
+
`${reading.dir} is on schema v${m.found} and this build needs v${m.expected}; the copy taken before the upgrade cannot be made (${m.problem}), so every hook stands down with MIGRATION_SNAPSHOT_FAILED`,
|
|
2110
|
+
`Make ${m.dir ?? "a snapshots directory"} writable${m.dir === null ? " and name it in snapshots.dir" : " (or point snapshots.dir at one outside the store)"}; the store is unchanged, and the previous build still opens it.`,
|
|
2111
|
+
upgrade,
|
|
2112
|
+
)
|
|
2113
|
+
: finding(
|
|
2114
|
+
"store-open",
|
|
2115
|
+
"amber",
|
|
2116
|
+
"Store open",
|
|
2117
|
+
`${reading.dir} is on schema v${m.found}; the next session copies it to ${m.dir ?? "?"} and upgrades it to v${m.expected}`,
|
|
2118
|
+
"Nothing to do: start a session, then run counterparts doctor again.",
|
|
2119
|
+
upgrade,
|
|
2120
|
+
),
|
|
2121
|
+
];
|
|
2122
|
+
}
|
|
2026
2123
|
if (reading.ok) {
|
|
2027
2124
|
return [
|
|
2028
2125
|
finding("store-open", "green", "Store open", `${reading.dir} opens as a session opens it`, "", data),
|
|
@@ -2544,6 +2641,10 @@ function snapshotFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
2544
2641
|
disk.preRows.length === 0
|
|
2545
2642
|
? ""
|
|
2546
2643
|
: `; ${String(disk.preRows.length)} older-format cop${disk.preRows.length === 1 ? "y" : "ies"} this build cannot open — kept, never rotated, read by the build tagged floor/v5-last: ${disk.preRows.slice(0, 3).join(", ")}${disk.preRows.length > 3 ? ` and ${String(disk.preRows.length - 3)} more` : ""}`;
|
|
2644
|
+
// The newest copy the store took before a schema migration, when there is
|
|
2645
|
+
// one: a clause, not a grade — it is the copy to roll an upgrade back to.
|
|
2646
|
+
const lastUpgrade = disk.preMigration[disk.preMigration.length - 1] ?? null;
|
|
2647
|
+
const upgrade = lastUpgrade === null ? "" : `; before the last schema upgrade: ${lastUpgrade}`;
|
|
2547
2648
|
const held = {
|
|
2548
2649
|
...data,
|
|
2549
2650
|
onDisk,
|
|
@@ -2553,6 +2654,7 @@ function snapshotFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
2553
2654
|
future,
|
|
2554
2655
|
unrecognised: disk.unrecognised.length,
|
|
2555
2656
|
preRows: disk.preRows.length,
|
|
2657
|
+
preMigration: lastUpgrade,
|
|
2556
2658
|
};
|
|
2557
2659
|
|
|
2558
2660
|
const read = newestRows(store, SNAPSHOT_TAKEN_EVENT, 1, livedDay);
|
|
@@ -2567,7 +2669,7 @@ function snapshotFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
2567
2669
|
"snapshot",
|
|
2568
2670
|
"amber",
|
|
2569
2671
|
"Snapshots",
|
|
2570
|
-
`${disk.readable ? "the snapshots directory is empty" : "the snapshots directory is missing or unreadable"} — but a snapshot.taken row says one was made${rowDated === null ? "" : ` on ${rowDated}`}. There is nothing to restore from.${strange}`,
|
|
2672
|
+
`${disk.readable ? "the snapshots directory is empty" : "the snapshots directory is missing or unreadable"} — but a snapshot.taken row says one was made${rowDated === null ? "" : ` on ${rowDated}`}. There is nothing to restore from.${strange}${upgrade}`,
|
|
2571
2673
|
RESTORE_STEPS,
|
|
2572
2674
|
{ ...held, rows: 1 },
|
|
2573
2675
|
),
|
|
@@ -2592,7 +2694,7 @@ function snapshotFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
2592
2694
|
"snapshot",
|
|
2593
2695
|
"amber",
|
|
2594
2696
|
"Snapshots",
|
|
2595
|
-
`no snapshot has ever been taken here${why}${strange}${misread}`,
|
|
2697
|
+
`no snapshot has ever been taken here${why}${strange}${upgrade}${misread}`,
|
|
2596
2698
|
"The worker takes one after the sleep cycle; the next boundary should leave a snapshot.taken row.",
|
|
2597
2699
|
{ ...held, rows: 0 },
|
|
2598
2700
|
)
|
|
@@ -2600,7 +2702,7 @@ function snapshotFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
2600
2702
|
"snapshot",
|
|
2601
2703
|
"green",
|
|
2602
2704
|
"Snapshots",
|
|
2603
|
-
`no snapshot yet — and no boundary has been reached here yet${strange}${misread}`,
|
|
2705
|
+
`no snapshot yet — and no boundary has been reached here yet${strange}${upgrade}${misread}`,
|
|
2604
2706
|
"",
|
|
2605
2707
|
{ ...held, rows: 0 },
|
|
2606
2708
|
),
|
|
@@ -2623,6 +2725,7 @@ function snapshotFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
2623
2725
|
: "") +
|
|
2624
2726
|
strange +
|
|
2625
2727
|
older +
|
|
2728
|
+
upgrade +
|
|
2626
2729
|
misread;
|
|
2627
2730
|
// Two or more calendar days back is a daily mechanism that has missed one, so
|
|
2628
2731
|
// the boundary day itself is already amber.
|
|
@@ -162,6 +162,8 @@ export interface HookInput {
|
|
|
162
162
|
* file read for the one thing that parse deliberately skips.
|
|
163
163
|
*/
|
|
164
164
|
readonly transcriptPath?: string;
|
|
165
|
+
/** The model that wrote the transcript's last assistant entry, when known. */
|
|
166
|
+
readonly model?: string;
|
|
165
167
|
/** Today's calendar date, for the temporal channel and the horizon lane. */
|
|
166
168
|
readonly at?: string;
|
|
167
169
|
/**
|
|
@@ -1848,6 +1850,9 @@ export class ClaudeCodeAdapter {
|
|
|
1848
1850
|
...(this.configPath === undefined || this.configPath.length === 0
|
|
1849
1851
|
? {}
|
|
1850
1852
|
: { config: this.configPath }),
|
|
1853
|
+
// Which model answered last. A Stop writes this before its ask goes out,
|
|
1854
|
+
// so the chapter that answers the ask finds it on the record.
|
|
1855
|
+
...(input.model === undefined ? {} : { model: input.model }),
|
|
1851
1856
|
});
|
|
1852
1857
|
this.emit("adapter.session.registry", { phase, ok: record !== null });
|
|
1853
1858
|
// Bounded growth, once per session rather than once per turn — and never on
|
|
@@ -159,6 +159,7 @@ export function openAdapter(
|
|
|
159
159
|
// and the LIVE face the novelty seam and the sweep's warm call use.
|
|
160
160
|
...(embedder === null ? {} : { embed: embedder.embed, vectors: embedder }),
|
|
161
161
|
...(config.dataDir === undefined ? {} : { dir: config.dataDir }),
|
|
162
|
+
...(config.snapshots?.dir === undefined ? {} : { snapshotsDir: config.snapshots.dir }),
|
|
162
163
|
...(config.injectionBudgetBytes === undefined
|
|
163
164
|
? {}
|
|
164
165
|
: { budgetBytes: config.injectionBudgetBytes }),
|
|
@@ -132,6 +132,7 @@ const PLAIN_WORDS: Partial<Record<StoreErrorCode, string>> = {
|
|
|
132
132
|
// out (review A, NIT-2). It fits the 200-character reason cap with room.
|
|
133
133
|
STORE_PRE_ROWS:
|
|
134
134
|
"this store keeps its memories in files, which this build does not read — it was written before the floor changed; the build that reads it is the tag floor/v5-last",
|
|
135
|
+
MIGRATION_SNAPSHOT_FAILED: "upgrade not run — the copy taken first failed; the store is unchanged",
|
|
135
136
|
SQLITE_UNAVAILABLE: "this runtime has no SQLite binding",
|
|
136
137
|
DATA_DIR_FORBIDDEN: "the configured data dir is one this build refuses to open",
|
|
137
138
|
STORE_UNINITIALIZED: "there is no store here yet, or it is a schema behind",
|
|
@@ -167,6 +168,16 @@ function preRowsReason(err: unknown): string | null {
|
|
|
167
168
|
);
|
|
168
169
|
}
|
|
169
170
|
|
|
171
|
+
/** The failed pre-migration copy, with what stopped it — doctor opens as an
|
|
172
|
+
* observer and never migrates, so this is the one place the why is said. */
|
|
173
|
+
function migrationReason(err: unknown): string | null {
|
|
174
|
+
if (!isStoreError(err, "MIGRATION_SNAPSHOT_FAILED")) return null;
|
|
175
|
+
const why = err.detail["reason"];
|
|
176
|
+
const base = PLAIN_WORDS.MIGRATION_SNAPSHOT_FAILED ?? OPEN_FAILED_WORDS;
|
|
177
|
+
// The reason first, so the 200-character cap trims the preamble, not the why.
|
|
178
|
+
return typeof why === "string" && why.length > 0 ? `${why} (${base})` : base;
|
|
179
|
+
}
|
|
180
|
+
|
|
170
181
|
export function describeFault(err: unknown): StandDownFault {
|
|
171
182
|
// TOTAL, and the reason is not theoretical politeness: this runs inside the
|
|
172
183
|
// handler that exists so a hook never fails the host, and everything below
|
|
@@ -190,7 +201,7 @@ function readFault(err: unknown): StandDownFault {
|
|
|
190
201
|
if (isStoreError(err)) {
|
|
191
202
|
return {
|
|
192
203
|
code: err.code,
|
|
193
|
-
reason: preRowsReason(err) ?? PLAIN_WORDS[err.code] ?? OPEN_FAILED_WORDS,
|
|
204
|
+
reason: preRowsReason(err) ?? migrationReason(err) ?? PLAIN_WORDS[err.code] ?? OPEN_FAILED_WORDS,
|
|
194
205
|
kind,
|
|
195
206
|
};
|
|
196
207
|
}
|
|
@@ -65,13 +65,19 @@
|
|
|
65
65
|
* and the text markers above only decide for an entry that carries none. The
|
|
66
66
|
* refusals (`foreign`, `ritual`) still come first, whatever the metadata says.
|
|
67
67
|
*
|
|
68
|
+
* **Prompts typed mid-turn are the person too** (2026-09-24). The host writes
|
|
69
|
+
* a prompt typed while the model works as an `attachment` entry
|
|
70
|
+
* (`queued_command`, `commandMode: "prompt"`, `origin.kind: "human"`), not a
|
|
71
|
+
* user entry. It is read as a typed turn where it stands; every other
|
|
72
|
+
* attachment is still skipped. NOTES §"What the host writes user-role".
|
|
73
|
+
*
|
|
68
74
|
* Nothing here throws. A transcript we cannot read yields no turns, which costs
|
|
69
75
|
* a boundary's capture; a transcript that throws would cost the session.
|
|
70
76
|
*
|
|
71
77
|
* The file also holds the WAKE-ARRIVAL READER (bottom of this file), which reads
|
|
72
78
|
* the same transcript for a different question and keeps its own, bounded, pass:
|
|
73
|
-
* capture wants conversation and skips attachments
|
|
74
|
-
* attachment and skips conversation.
|
|
79
|
+
* capture wants conversation and skips attachments (queued prompts aside),
|
|
80
|
+
* delivery wants exactly the hook's attachment and skips conversation.
|
|
75
81
|
*/
|
|
76
82
|
import {
|
|
77
83
|
closeSync,
|
|
@@ -370,6 +376,9 @@ export interface TranscriptRead {
|
|
|
370
376
|
readonly corrupt: number;
|
|
371
377
|
/** Deliberate-recall calls, in order, positioned against `turns`. */
|
|
372
378
|
readonly expansions: Expansion[];
|
|
379
|
+
/** `message.model` of the last assistant entry the model wrote (not a host
|
|
380
|
+
* stand-in, not a sidechain). Absent when none carried one. */
|
|
381
|
+
readonly model?: string;
|
|
373
382
|
}
|
|
374
383
|
|
|
375
384
|
/**
|
|
@@ -416,6 +425,10 @@ export function parseTranscript(raw: string): TranscriptRead {
|
|
|
416
425
|
const expansions: Expansion[] = [];
|
|
417
426
|
let corrupt = 0;
|
|
418
427
|
let ordinal = -1;
|
|
428
|
+
// Queued prompts already emitted, by their text. Open until a twin consumes
|
|
429
|
+
// one or the person sends anything else.
|
|
430
|
+
let pending: string[] = [];
|
|
431
|
+
let model: string | undefined;
|
|
419
432
|
for (const line of raw.split("\n")) {
|
|
420
433
|
if (line.trim().length === 0) continue;
|
|
421
434
|
let entry: Record<string, unknown>;
|
|
@@ -433,13 +446,47 @@ export function parseTranscript(raw: string): TranscriptRead {
|
|
|
433
446
|
corrupt += 1;
|
|
434
447
|
continue;
|
|
435
448
|
}
|
|
449
|
+
// A prompt typed while the model worked: a turn of its own, where it
|
|
450
|
+
// stands in the file. A twin written later is skipped below, so the first
|
|
451
|
+
// appearance is the one kept and the list only grows.
|
|
452
|
+
if (entry["type"] === "attachment") {
|
|
453
|
+
const queued = queuedPromptOf(entry);
|
|
454
|
+
if (queued === undefined) continue;
|
|
455
|
+
ordinal += 1;
|
|
456
|
+
const pieces = blocksOf(queued, "user", "human");
|
|
457
|
+
const said = typedText(pieces);
|
|
458
|
+
if (said.length > 0) pending.push(said);
|
|
459
|
+
for (const piece of pieces) {
|
|
460
|
+
if (piece.text.trim().length === 0) continue;
|
|
461
|
+
turns.push({ role: "user", text: piece.text, source: piece.source, entry: ordinal });
|
|
462
|
+
}
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
436
465
|
const message = entry["message"] as Record<string, unknown> | undefined;
|
|
437
466
|
const role = (message?.["role"] ?? entry["role"]) as unknown;
|
|
438
467
|
if (role !== "user" && role !== "assistant") continue;
|
|
439
468
|
const content = message?.["content"] ?? entry["content"];
|
|
440
469
|
const author = entryAuthor(entry, role);
|
|
470
|
+
// Which model answered: the newest real assistant entry wins, so a
|
|
471
|
+
// mid-session /model switch shows up at the next read.
|
|
472
|
+
if (role === "assistant" && author !== "host" && entry["isSidechain"] !== true) {
|
|
473
|
+
const said = message?.["model"];
|
|
474
|
+
if (typeof said === "string" && said.length > 0) model = said;
|
|
475
|
+
}
|
|
476
|
+
const pieces = blocksOf(content, role, author);
|
|
477
|
+
// A twin, if the host ever writes one, is the person's NEXT sent entry: the
|
|
478
|
+
// same words, marked queued. Anything else the person sends closes the
|
|
479
|
+
// window. Assistant lines do not: the turn goes on after the attachment.
|
|
480
|
+
if (role === "user" && author === "human" && pending.length > 0) {
|
|
481
|
+
const twin = entry["promptSource"] === "queued" ? pending.indexOf(typedText(pieces)) : -1;
|
|
482
|
+
if (twin !== -1) {
|
|
483
|
+
pending.splice(twin, 1);
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
pending = [];
|
|
487
|
+
}
|
|
441
488
|
ordinal += 1;
|
|
442
|
-
for (const piece of
|
|
489
|
+
for (const piece of pieces) {
|
|
443
490
|
// A recall call is the assistant's turn, kept as EVIDENCE beside the
|
|
444
491
|
// turn list rather than in it (see `Expansion`). Only the assistant
|
|
445
492
|
// calls tools; a user-role block never carries one.
|
|
@@ -450,7 +497,33 @@ export function parseTranscript(raw: string): TranscriptRead {
|
|
|
450
497
|
turns.push({ role, text: piece.text, source: piece.source, entry: ordinal });
|
|
451
498
|
}
|
|
452
499
|
}
|
|
453
|
-
return { turns, ok: true, reason: "read", corrupt, expansions };
|
|
500
|
+
return { turns, ok: true, reason: "read", corrupt, expansions, ...(model === undefined ? {} : { model }) };
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* The prompt of a `queued_command` attachment the PERSON typed mid-turn, or
|
|
505
|
+
* undefined. Host-queued work (task notifications, hand-backs, anything
|
|
506
|
+
* `isMeta`) and other modes (`bash`, …) are not the person speaking to the
|
|
507
|
+
* model. `prompt` is a string, or content blocks when an image was pasted.
|
|
508
|
+
*/
|
|
509
|
+
function queuedPromptOf(entry: Record<string, unknown>): unknown {
|
|
510
|
+
const att = entry["attachment"];
|
|
511
|
+
if (!isEntry(att) || att["type"] !== "queued_command" || att["commandMode"] !== "prompt") return undefined;
|
|
512
|
+
if (att["isMeta"] === true || entry["isMeta"] === true) return undefined;
|
|
513
|
+
const origin = att["origin"];
|
|
514
|
+
if (!isEntry(origin) || origin["kind"] !== "human") return undefined;
|
|
515
|
+
const prompt = att["prompt"];
|
|
516
|
+
return typeof prompt === "string" || Array.isArray(prompt) ? prompt : undefined;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/** What the person said in one entry, whitespace collapsed, for matching a queued prompt to its twin. */
|
|
520
|
+
function typedText(pieces: readonly Piece[]): string {
|
|
521
|
+
return pieces
|
|
522
|
+
.filter((p) => p.source === "conversation")
|
|
523
|
+
.map((p) => p.text)
|
|
524
|
+
.join(" ")
|
|
525
|
+
.replace(/\s+/g, " ")
|
|
526
|
+
.trim();
|
|
454
527
|
}
|
|
455
528
|
|
|
456
529
|
type Piece = { text: string; source: TurnSource; expansion?: string[] };
|
|
@@ -546,8 +619,8 @@ function blocksOf(content: unknown, role: "user" | "assistant", author: EntryAut
|
|
|
546
619
|
// `parseTranscript` refuses to answer: did the wake this system printed at
|
|
547
620
|
// SessionStart actually reach the session's context?
|
|
548
621
|
//
|
|
549
|
-
// `parseTranscript` skips
|
|
550
|
-
// conversation
|
|
622
|
+
// `parseTranscript` skips hook attachments because injected context is not
|
|
623
|
+
// conversation (it reads only the person's queued prompts). The check below wants the
|
|
551
624
|
// opposite half of the file: the host records a SessionStart hook's output as an
|
|
552
625
|
// entry of its own (`type: "attachment"`, `attachment.type: "hook_success"`),
|
|
553
626
|
// carrying what the hook PRINTED (`stdout`) beside what the host says it
|
|
@@ -111,6 +111,8 @@ database, not the store's abstraction of it.
|
|
|
111
111
|
|
|
112
112
|
## 6. The CLI CONTRACT §5 G6 and the store's LAYOUT disagree about `versions/`
|
|
113
113
|
|
|
114
|
+
**Closed 2026-09-24** — the floor (store schema v6) removed the `versions/` directory; versions are rows in `counterparts.sqlite`, and CLI CONTRACT §5 says so.
|
|
115
|
+
|
|
114
116
|
**G6:** "the archive tree is deliberately excluded from snapshots — archive-on-
|
|
115
117
|
overwrite history is itself the redundancy layer, and snapshotting it copies an
|
|
116
118
|
unbounded, already-redundant tree into every snapshot."
|
|
@@ -149,6 +151,8 @@ answered before opening.
|
|
|
149
151
|
|
|
150
152
|
## 8. Entity birth (`schemas.mention`) has no adapter path at all
|
|
151
153
|
|
|
154
|
+
**Closed 2026-09-24** — `counterpart.ts#mentionFromProposal` calls `schemas.mention` when an authored or swept entity/person/place proposal lands.
|
|
155
|
+
|
|
152
156
|
**Filed 2026-08-25** from the live-verification run, for the coordinator. Neither
|
|
153
157
|
`adapters/mcp/` nor `adapters/cli/` calls `Schemas.mention()`; grep finds it only
|
|
154
158
|
in `src/core/` and `test/`. Birth-by-mention is a core primitive whose only live
|