counterparts 0.3.0 → 0.3.2
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 +76 -0
- package/docs/module-map.md +2 -0
- package/package.json +2 -1
- package/src/adapters/claude-code/CONTRACT.md +2 -1
- package/src/adapters/claude-code/NOTES.md +90 -2
- package/src/adapters/claude-code/bin/hook.ts +17 -2
- package/src/adapters/claude-code/bin/runner.ts +4 -1
- package/src/adapters/claude-code/config.ts +23 -0
- package/src/adapters/claude-code/doctor.ts +148 -26
- package/src/adapters/claude-code/hooks.ts +37 -12
- package/src/adapters/claude-code/index.ts +2 -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 +209 -61
- package/src/adapters/cli/export.ts +27 -3
- package/src/adapters/cli/help.ts +22 -8
- package/src/adapters/cli/install.ts +3 -5
- package/src/adapters/cli/mechanisms.ts +295 -0
- package/src/adapters/cli/repair-dates.ts +3 -1
- package/src/adapters/cli/snapshot.ts +4 -27
- package/src/adapters/dashboard/CONTRACT.md +13 -9
- package/src/adapters/dashboard/INTERFACE-GAPS.md +4 -0
- package/src/adapters/dashboard/NOTES.md +3 -2
- package/src/adapters/dashboard/activity.ts +2 -1
- package/src/adapters/dashboard/bin/dashboard.ts +18 -3
- package/src/adapters/dashboard/upgrade.ts +23 -0
- package/src/adapters/dashboard/web/README.md +153 -0
- package/src/adapters/dashboard/web/actions.ts +631 -0
- package/src/adapters/dashboard/web/app.html +40 -1703
- package/src/adapters/dashboard/web/app.js +55 -0
- package/src/adapters/dashboard/web/mechanisms/association/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/association/panel.js +17 -0
- package/src/adapters/dashboard/web/mechanisms/consolidation/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/consolidation/panel.js +23 -0
- package/src/adapters/dashboard/web/mechanisms/decay/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/decay/panel.js +45 -0
- package/src/adapters/dashboard/web/mechanisms/emotional/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/episodic-semantic/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/index.js +60 -0
- package/src/adapters/dashboard/web/mechanisms/interference/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/picture.js +28 -0
- package/src/adapters/dashboard/web/mechanisms/prospective/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/reconsolidation/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/reconsolidation/panel.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/regions.js +30 -0
- package/src/adapters/dashboard/web/mechanisms/retrieval/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/retrieval/panel.js +20 -0
- package/src/adapters/dashboard/web/mechanisms/salience/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/salience/panel.js +14 -0
- package/src/adapters/dashboard/web/mechanisms/schema/index.js +15 -0
- package/src/adapters/dashboard/web/narrate.ts +10 -10
- package/src/adapters/dashboard/web/pages/flow/flow.css +38 -0
- package/src/adapters/dashboard/web/pages/flow/index.js +117 -0
- package/src/adapters/dashboard/web/pages/flow/sections/blind.js +12 -0
- package/src/adapters/dashboard/web/pages/flow/sections/detail.js +45 -0
- package/src/adapters/dashboard/web/pages/flow/sections/diagram.js +291 -0
- package/src/adapters/dashboard/web/pages/flow/sections/feed.js +11 -0
- package/src/adapters/dashboard/web/pages/flow/sections/fired.js +41 -0
- package/src/adapters/dashboard/web/pages/flow/sections/heatmap.js +25 -0
- package/src/adapters/dashboard/web/pages/flow/sections/records.js +24 -0
- package/src/adapters/dashboard/web/pages/flow/sections/symmetry.js +17 -0
- package/src/adapters/dashboard/web/pages/flow/state.js +3 -0
- package/src/adapters/dashboard/web/pages/health/health.css +93 -0
- package/src/adapters/dashboard/web/pages/health/index.js +41 -0
- package/src/adapters/dashboard/web/pages/health/sections/archive.js +84 -0
- package/src/adapters/dashboard/web/pages/health/sections/checks.js +172 -0
- package/src/adapters/dashboard/web/pages/health/sections/cycle.js +37 -0
- package/src/adapters/dashboard/web/pages/health/sections/verify.js +54 -0
- package/src/adapters/dashboard/web/pages/home/brain.js +375 -0
- package/src/adapters/dashboard/web/pages/home/home.css +134 -0
- package/src/adapters/dashboard/web/pages/home/index.js +84 -0
- package/src/adapters/dashboard/web/pages/home/sections/explorer.js +206 -0
- package/src/adapters/dashboard/web/pages/home/sections/hero.js +22 -0
- package/src/adapters/dashboard/web/pages/home/sections/live-activity.js +25 -0
- package/src/adapters/dashboard/web/pages/home/sections/recent-chapters.js +13 -0
- package/src/adapters/dashboard/web/pages/home/sections/tiles.js +52 -0
- package/src/adapters/dashboard/web/pages/memories/index.js +75 -0
- package/src/adapters/dashboard/web/pages/memories/memories.css +143 -0
- package/src/adapters/dashboard/web/pages/memories/sections/constellation.js +178 -0
- package/src/adapters/dashboard/web/pages/memories/sections/kinds.js +42 -0
- package/src/adapters/dashboard/web/pages/memories/sections/list.js +114 -0
- package/src/adapters/dashboard/web/pages/memories/sections/search.js +102 -0
- package/src/adapters/dashboard/web/pages/memories/sections/tools.js +155 -0
- package/src/adapters/dashboard/web/pages/memories/state.js +22 -0
- package/src/adapters/dashboard/web/pages/self/diff.js +79 -0
- package/src/adapters/dashboard/web/pages/self/index.js +43 -0
- package/src/adapters/dashboard/web/pages/self/markdown.js +61 -0
- package/src/adapters/dashboard/web/pages/self/sections/journal.js +32 -0
- package/src/adapters/dashboard/web/pages/self/sections/page.js +149 -0
- package/src/adapters/dashboard/web/pages/self/sections/settling.js +150 -0
- package/src/adapters/dashboard/web/pages/self/sections/stories.js +47 -0
- package/src/adapters/dashboard/web/pages/self/sections/wake.js +74 -0
- package/src/adapters/dashboard/web/pages/self/self.css +182 -0
- package/src/adapters/dashboard/web/server.ts +305 -28
- package/src/adapters/dashboard/web/shared/absence.js +14 -0
- package/src/adapters/dashboard/web/shared/actions.js +48 -0
- package/src/adapters/dashboard/web/shared/api.js +17 -0
- package/src/adapters/dashboard/web/shared/base.css +34 -0
- package/src/adapters/dashboard/web/shared/canvas.js +68 -0
- package/src/adapters/dashboard/web/shared/colors.js +6 -0
- package/src/adapters/dashboard/web/shared/dom.js +4 -0
- package/src/adapters/dashboard/web/shared/event-modal.js +25 -0
- package/src/adapters/dashboard/web/shared/fonts/OFL-courier-prime.txt +93 -0
- package/src/adapters/dashboard/web/shared/fonts/OFL-outfit.txt +93 -0
- package/src/adapters/dashboard/web/shared/fonts/courier-prime-latin-400.woff2 +0 -0
- package/src/adapters/dashboard/web/shared/fonts/courier-prime-latin-700.woff2 +0 -0
- package/src/adapters/dashboard/web/shared/fonts/outfit-latin-wght.woff2 +0 -0
- package/src/adapters/dashboard/web/shared/format.js +31 -0
- package/src/adapters/dashboard/web/shared/layout.css +32 -0
- package/src/adapters/dashboard/web/shared/memory-modal.js +124 -0
- package/src/adapters/dashboard/web/shared/modal.css +24 -0
- package/src/adapters/dashboard/web/shared/modal.js +22 -0
- package/src/adapters/dashboard/web/shared/state.js +12 -0
- package/src/adapters/dashboard/web/shared/tip.css +4 -0
- package/src/adapters/dashboard/web/shared/tip.js +12 -0
- package/src/adapters/dashboard/web/shared/tokens.css +50 -0
- package/src/adapters/dashboard/web/shared/type.css +52 -0
- package/src/adapters/dashboard/web/shared/utilities.css +5 -0
- package/src/adapters/dashboard/web/shared/vendor/MIT-three.txt +21 -0
- package/src/adapters/dashboard/web/shared/vendor/three.module.min.js +6 -0
- package/src/adapters/dashboard/web/shared/widgets/bar.css +9 -0
- package/src/adapters/dashboard/web/shared/widgets/card.css +6 -0
- package/src/adapters/dashboard/web/shared/widgets/chapters.js +15 -0
- package/src/adapters/dashboard/web/shared/widgets/chart.css +4 -0
- package/src/adapters/dashboard/web/shared/widgets/confirm.css +31 -0
- package/src/adapters/dashboard/web/shared/widgets/confirm.js +52 -0
- package/src/adapters/dashboard/web/shared/widgets/feed.css +13 -0
- package/src/adapters/dashboard/web/shared/widgets/feed.js +41 -0
- package/src/adapters/dashboard/web/shared/widgets/light.css +4 -0
- package/src/adapters/dashboard/web/shared/widgets/light.js +15 -0
- package/src/adapters/dashboard/web/shared/widgets/rows.css +7 -0
- package/src/adapters/dashboard/web/shared/widgets/table.css +17 -0
- package/src/adapters/dashboard/web/shared/widgets/tiles.css +14 -0
- package/src/adapters/dashboard/web/shell/pages.js +15 -0
- package/src/adapters/dashboard/web/shell/pulse.js +86 -0
- package/src/adapters/dashboard/web/shell/tabs.js +49 -0
- package/src/adapters/dashboard/web/static.ts +76 -0
- package/src/adapters/dashboard/web/views/activity.ts +80 -0
- package/src/adapters/dashboard/web/views/archive-words.ts +57 -0
- package/src/adapters/dashboard/web/views/flow-view.ts +217 -0
- package/src/adapters/dashboard/web/views/health.ts +328 -0
- package/src/adapters/dashboard/web/views/mechanism-panel.ts +370 -0
- package/src/adapters/dashboard/web/views/mechanisms.ts +302 -0
- package/src/adapters/dashboard/web/views/memories.ts +342 -0
- package/src/adapters/dashboard/web/views/memory.ts +210 -0
- package/src/adapters/dashboard/web/views/meta.ts +64 -0
- package/src/adapters/dashboard/web/views/mind.ts +729 -0
- package/src/adapters/dashboard/web/views/overview.ts +282 -0
- package/src/adapters/dashboard/web/views/pulse.ts +19 -0
- package/src/adapters/dashboard/web/views/rows.ts +207 -0
- package/src/adapters/dashboard/web/views/search.ts +62 -0
- package/src/adapters/dashboard/web/views/shared.ts +161 -0
- package/src/adapters/dashboard/web/views.ts +34 -1724
- package/src/adapters/fired.ts +138 -31
- package/src/adapters/mcp/INTERFACE-GAPS.md +4 -1
- package/src/adapters/mcp/NOTES.md +43 -0
- package/src/adapters/mcp/bin/serve.ts +9 -1
- package/src/adapters/mcp/index.ts +7 -0
- package/src/adapters/mcp/server.ts +167 -6
- package/src/adapters/mcp/tools.ts +42 -0
- package/src/adapters/mcp/write-up.ts +1 -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 +86 -7
- package/src/core/encode/INTERFACE-GAPS.md +12 -0
- package/src/core/feelings-wheel.ts +218 -0
- package/src/core/handoff/INTERFACE-GAPS.md +2 -0
- package/src/core/mint.ts +14 -2
- package/src/core/prospective/INTERFACE-GAPS.md +14 -0
- package/src/core/prospective/windows.ts +10 -48
- 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 +33 -2
- package/src/core/self/calendar.ts +7 -78
- package/src/core/self/episodes.ts +52 -12
- package/src/core/self/index.ts +40 -12
- package/src/core/self/writer.ts +22 -22
- package/src/core/sleep/NOTES.md +36 -0
- package/src/core/sleep/cycle.ts +38 -3
- 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 +36 -7
- package/src/core/store/NOTES.md +197 -0
- package/src/core/store/errors.ts +22 -0
- package/src/core/store/feelings.ts +182 -0
- package/src/core/store/index.ts +339 -45
- package/src/core/store/operational.ts +240 -22
- package/src/core/store/owner-op-seam.ts +13 -3
- package/src/core/store/paths.ts +15 -1
- package/src/core/store/pre-migration.ts +258 -0
- package/src/core/store/prose.ts +8 -1
- package/src/core/store/render.ts +3 -0
- package/src/core/time.ts +374 -0
- package/src/core/types.ts +13 -0
- package/src/adapters/dashboard/web/brain.html +0 -463
|
@@ -44,10 +44,12 @@
|
|
|
44
44
|
* No body text, no question text, no note text ever reaches an event.
|
|
45
45
|
*/
|
|
46
46
|
import { MCP_RECALL_EVENT } from "../../core/counterpart.js";
|
|
47
|
+
import { localDate } from "../../core/time.js";
|
|
47
48
|
import type { ChapterResult, Counterpart, DepositResult } from "../../core/counterpart.js";
|
|
48
49
|
import type { SemanticSource } from "../../core/recall/index.js";
|
|
49
50
|
import { AUTHOR_DIMENSIONS } from "../../core/remember/index.js";
|
|
50
|
-
import { CACHE_SCHEMA_VERSION, SCHEMA_VERSION, StoreError, schemaAhead } from "../../core/store/index.js";
|
|
51
|
+
import { CACHE_SCHEMA_VERSION, SCHEMA_VERSION, StoreError, checkFeelings, isStoreError, schemaAhead } from "../../core/store/index.js";
|
|
52
|
+
import type { FeelingInput } from "../../core/store/index.js";
|
|
51
53
|
import { isLocked } from "../../core/store/db.js";
|
|
52
54
|
import type { Band, Kind } from "../../core/types.js";
|
|
53
55
|
import { recordHandleResolution } from "../expansions.js";
|
|
@@ -110,7 +112,7 @@ export const SERVER_NAME = "counterparts";
|
|
|
110
112
|
* host decides whether to trust what follows. Read from a constant rather than
|
|
111
113
|
* from disk so the server opens no file to answer its first message.
|
|
112
114
|
*/
|
|
113
|
-
export const SERVER_VERSION = "0.3.
|
|
115
|
+
export const SERVER_VERSION = "0.3.2";
|
|
114
116
|
|
|
115
117
|
/**
|
|
116
118
|
* THE ONE LINE EVERY TOOL ANSWERS WITH when the store on disk is a schema AHEAD
|
|
@@ -938,12 +940,18 @@ export class McpServer {
|
|
|
938
940
|
if (salience !== undefined) draft["claimed"] = salience;
|
|
939
941
|
if (Object.keys(dims).length > 0) draft["salience"] = dims;
|
|
940
942
|
|
|
943
|
+
const model = this.sessionModel();
|
|
944
|
+
const feelings = readFeelings(args["feelings"]);
|
|
945
|
+
if ("refused" in feelings) {
|
|
946
|
+
return this.refuse("note", "feelings-malformed", { detail: feelings.refused });
|
|
947
|
+
}
|
|
941
948
|
const deposit = await this.counterpart.submitJot(draft, {
|
|
942
949
|
session,
|
|
943
950
|
scope: this.scope,
|
|
944
951
|
ownSpanHash,
|
|
952
|
+
...(model === undefined ? {} : { model }),
|
|
945
953
|
});
|
|
946
|
-
return this.depositResult("note", deposit);
|
|
954
|
+
return this.depositResult("note", deposit, this.recordFeelings(deposit, feelings.inputs, model));
|
|
947
955
|
}
|
|
948
956
|
|
|
949
957
|
/**
|
|
@@ -1312,7 +1320,7 @@ export class McpServer {
|
|
|
1312
1320
|
for (const row of store.removalRecord()) {
|
|
1313
1321
|
if (row.stage !== "complete") continue;
|
|
1314
1322
|
removedIds.add(row.memory_id);
|
|
1315
|
-
dates.add(
|
|
1323
|
+
dates.add(localDate(row.at, store.zone()));
|
|
1316
1324
|
const kind = store.row(row.memory_id)?.kind ?? "unknown";
|
|
1317
1325
|
removedKinds[kind] = (removedKinds[kind] ?? 0) + 1;
|
|
1318
1326
|
}
|
|
@@ -1487,9 +1495,11 @@ export class McpServer {
|
|
|
1487
1495
|
cover?: false | { readonly session: string },
|
|
1488
1496
|
): Promise<{ outcomes: Record<string, unknown>[]; deposited: number; duplicates: number; entries: Record<string, unknown>[] }> {
|
|
1489
1497
|
const entries: Record<string, unknown>[] = [];
|
|
1498
|
+
const feelingsOf: FeelingsRead[] = [];
|
|
1490
1499
|
for (const item of raw) {
|
|
1491
1500
|
if (item === null || typeof item !== "object" || Array.isArray(item)) {
|
|
1492
1501
|
entries.push({ content: "" });
|
|
1502
|
+
feelingsOf.push({ inputs: [] });
|
|
1493
1503
|
continue;
|
|
1494
1504
|
}
|
|
1495
1505
|
const rec = item as Record<string, unknown>;
|
|
@@ -1504,18 +1514,28 @@ export class McpServer {
|
|
|
1504
1514
|
const entryDims = readDimensions(rec) ?? pickDimensions(rec);
|
|
1505
1515
|
if (Object.keys(entryDims).length > 0) draft["salience"] = entryDims;
|
|
1506
1516
|
entries.push(draft);
|
|
1517
|
+
feelingsOf.push(readFeelings(rec["feelings"]));
|
|
1507
1518
|
}
|
|
1508
1519
|
|
|
1509
1520
|
const outcomes: Record<string, unknown>[] = [];
|
|
1510
1521
|
let deposited = 0;
|
|
1511
1522
|
let duplicates = 0;
|
|
1512
|
-
|
|
1523
|
+
const model = this.sessionModel();
|
|
1524
|
+
for (const [n, draft] of entries.entries()) {
|
|
1525
|
+
// Feelings that cannot be stored refuse THEIR entry before it mints, so
|
|
1526
|
+
// no memory lands with its feelings silently dropped; siblings still run.
|
|
1527
|
+
const feelings = feelingsOf[n] ?? { inputs: [] };
|
|
1528
|
+
if ("refused" in feelings) {
|
|
1529
|
+
outcomes.push({ stored: false, reason: "feelings-malformed", detail: feelings.refused });
|
|
1530
|
+
continue;
|
|
1531
|
+
}
|
|
1513
1532
|
let result: DepositResult;
|
|
1514
1533
|
try {
|
|
1515
1534
|
result = await this.counterpart.submitSessionEnd(draft, {
|
|
1516
1535
|
session,
|
|
1517
1536
|
scope: this.scope,
|
|
1518
1537
|
...(cover === undefined ? {} : { cover }),
|
|
1538
|
+
...(model === undefined ? {} : { model }),
|
|
1519
1539
|
});
|
|
1520
1540
|
} catch (err) {
|
|
1521
1541
|
// Isolation, not a lost dump: this entry failed, the rest still run.
|
|
@@ -1536,6 +1556,7 @@ export class McpServer {
|
|
|
1536
1556
|
...(result.gate === null ? {} : { gate: result.gate }),
|
|
1537
1557
|
...(malformed === null ? {} : { malformed }),
|
|
1538
1558
|
...(malformed === "KIND_UNKNOWN" ? { kinds: [...MEMORY_KINDS] } : {}),
|
|
1559
|
+
...this.recordFeelings(result, feelings.inputs, model),
|
|
1539
1560
|
});
|
|
1540
1561
|
}
|
|
1541
1562
|
return { outcomes, deposited, duplicates, entries };
|
|
@@ -1657,10 +1678,14 @@ export class McpServer {
|
|
|
1657
1678
|
}
|
|
1658
1679
|
const session = this.session as string;
|
|
1659
1680
|
const title = args["title"];
|
|
1681
|
+
// The model the hooks last saw answer in this session. A Stop records it
|
|
1682
|
+
// before its ask goes out, so the chapter that answers the ask has it.
|
|
1683
|
+
const model = readSession(this.registryDir, session)?.model;
|
|
1660
1684
|
let written: ChapterResult;
|
|
1661
1685
|
try {
|
|
1662
1686
|
written = this.counterpart.appendEpisode(session, text, {
|
|
1663
1687
|
...(typeof title === "string" && title.length > 0 ? { title } : {}),
|
|
1688
|
+
...(model === undefined ? {} : { model }),
|
|
1664
1689
|
});
|
|
1665
1690
|
} catch (err) {
|
|
1666
1691
|
// A journal that throws must not look like a journal that refused.
|
|
@@ -1750,7 +1775,9 @@ export class McpServer {
|
|
|
1750
1775
|
// about 09-19 writes `writer` for that run and nothing else, and a stale
|
|
1751
1776
|
// mark cannot relabel a write made two days later (`adapters/sessions.ts`).
|
|
1752
1777
|
const writerFor = this.pageWriterMark(claimedSession);
|
|
1778
|
+
const model = this.sessionModel();
|
|
1753
1779
|
const written = this.counterpart.revisePage(body, {
|
|
1780
|
+
...(model === undefined ? {} : { model }),
|
|
1754
1781
|
reason: typeof reason === "string" && reason.trim().length > 0 ? reason.trim() : "amended",
|
|
1755
1782
|
by: writerFor === null ? "session" : "writer",
|
|
1756
1783
|
// WHICH SESSION, when this server has one. `note` resolves it the same
|
|
@@ -1919,6 +1946,24 @@ export class McpServer {
|
|
|
1919
1946
|
return claimed;
|
|
1920
1947
|
}
|
|
1921
1948
|
|
|
1949
|
+
/**
|
|
1950
|
+
* The model the hooks last saw answer in THIS server's bound session — the
|
|
1951
|
+
* relay a chapter's model takes (self NOTES §24), used since 2026-09-25 for
|
|
1952
|
+
* the `model` column on every row a tool writes (schema v7). Undefined when
|
|
1953
|
+
* no session is bound (`note` and `self_page` work unbound) or the record
|
|
1954
|
+
* names none; the row then records NULL rather than a guess. On the live
|
|
1955
|
+
* host the server is launched with no session, so a `note` before the first
|
|
1956
|
+
* `chapter` / `session_end` binds it records NULL — accepted (review N3).
|
|
1957
|
+
*/
|
|
1958
|
+
private sessionModel(): string | undefined {
|
|
1959
|
+
if (this.session === null) return undefined;
|
|
1960
|
+
try {
|
|
1961
|
+
return readSession(this.registryDir, this.session)?.model;
|
|
1962
|
+
} catch {
|
|
1963
|
+
return undefined;
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1922
1967
|
/** Known to the hooks' registry, live, and in THIS server's scope — the same
|
|
1923
1968
|
* three tests `requireBoundSession` makes, asked without the side effect. */
|
|
1924
1969
|
private corroborate(claimed: string): boolean {
|
|
@@ -2026,7 +2071,54 @@ export class McpServer {
|
|
|
2026
2071
|
|
|
2027
2072
|
// ── result shapes ──────────────────────────────────────────────────────────
|
|
2028
2073
|
|
|
2029
|
-
|
|
2074
|
+
/**
|
|
2075
|
+
* The feelings half of a deposit (schema v7): written onto the memory that
|
|
2076
|
+
* just minted, and answered as `feelings: { stored, other? }` — `other`
|
|
2077
|
+
* listing each emotion kept as `other` with the wheel keys nearest it, so the
|
|
2078
|
+
* caller can rewrite. Nothing when none were sent or nothing minted. A throw
|
|
2079
|
+
* here costs the feelings, never the memory, and says so.
|
|
2080
|
+
*/
|
|
2081
|
+
private recordFeelings(
|
|
2082
|
+
deposit: DepositResult,
|
|
2083
|
+
inputs: readonly FeelingInput[],
|
|
2084
|
+
model: string | undefined,
|
|
2085
|
+
): Record<string, unknown> {
|
|
2086
|
+
if (inputs.length === 0) return {};
|
|
2087
|
+
// A note that did not land (a duplicate, a gate) takes its feelings with it
|
|
2088
|
+
// — and SAYS so (review N6), rather than dropping them without a word.
|
|
2089
|
+
if (!deposit.deposited || deposit.memoryId === null) {
|
|
2090
|
+
return {
|
|
2091
|
+
feelings: {
|
|
2092
|
+
stored: 0,
|
|
2093
|
+
reason: "memory-not-stored",
|
|
2094
|
+
detail: `The memory was not stored (${deposit.reason}), so its ${String(inputs.length)} feeling${inputs.length === 1 ? " was" : "s were"} not stored either.`,
|
|
2095
|
+
},
|
|
2096
|
+
};
|
|
2097
|
+
}
|
|
2098
|
+
try {
|
|
2099
|
+
const added = this.counterpart.addFeelings(deposit.memoryId, inputs, model === undefined ? {} : { model });
|
|
2100
|
+
return {
|
|
2101
|
+
feelings: {
|
|
2102
|
+
stored: added.ids.length,
|
|
2103
|
+
...(added.notices.length === 0
|
|
2104
|
+
? {}
|
|
2105
|
+
: {
|
|
2106
|
+
other: added.notices.map((n) => ({
|
|
2107
|
+
index: n.index,
|
|
2108
|
+
word: n.word,
|
|
2109
|
+
core: n.core,
|
|
2110
|
+
closest: n.closest,
|
|
2111
|
+
note: `"${n.word}" is not on the feelings wheel, so it was kept as other. If you meant one of these, say it that way next time: ${n.closest.join(", ")}.`,
|
|
2112
|
+
})),
|
|
2113
|
+
}),
|
|
2114
|
+
},
|
|
2115
|
+
};
|
|
2116
|
+
} catch (err) {
|
|
2117
|
+
return { feelings: { stored: 0, reason: "threw", detail: String((err as Error).message ?? err) } };
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
private depositResult(tool: string, deposit: DepositResult, extra: Record<string, unknown> = {}): ToolResult {
|
|
2030
2122
|
this.emit(`mcp.${tool}`, deposit.memoryId ?? undefined, {
|
|
2031
2123
|
stored: deposit.deposited,
|
|
2032
2124
|
reason: deposit.reason,
|
|
@@ -2041,6 +2133,7 @@ export class McpServer {
|
|
|
2041
2133
|
...(deposit.memoryId === null ? {} : { id: deposit.memoryId }),
|
|
2042
2134
|
...(deposit.gate === null ? {} : { gate: deposit.gate }),
|
|
2043
2135
|
...(lifted ? { salienceLifted: true } : {}),
|
|
2136
|
+
...extra,
|
|
2044
2137
|
},
|
|
2045
2138
|
!deposit.deposited,
|
|
2046
2139
|
);
|
|
@@ -2155,3 +2248,71 @@ function pickDimensions(rec: Record<string, unknown>): Record<string, unknown> {
|
|
|
2155
2248
|
}
|
|
2156
2249
|
return out;
|
|
2157
2250
|
}
|
|
2251
|
+
|
|
2252
|
+
// ── feelings on a tool call (schema v7) ─────────────────────────────────────
|
|
2253
|
+
|
|
2254
|
+
type FeelingsRead = { inputs: FeelingInput[] } | { refused: string };
|
|
2255
|
+
|
|
2256
|
+
/**
|
|
2257
|
+
* `feelings: [{ whose, core, emotion, strength, carried_by, beneath?, other_word? }]`
|
|
2258
|
+
* off a `note` or a `session_end` entry, read and CHECKED before anything
|
|
2259
|
+
* mints (`store/feelings.ts#checkFeelings`, pure). `beneath` is another
|
|
2260
|
+
* feeling's index in the same list. Absent is no feelings; anything that will
|
|
2261
|
+
* not store is a refusal naming the item and the reason.
|
|
2262
|
+
*/
|
|
2263
|
+
function readFeelings(raw: unknown): FeelingsRead {
|
|
2264
|
+
// ANY throw is this entry's refusal, never the call's (review S2): a
|
|
2265
|
+
// `session_end` carries siblings that must still land.
|
|
2266
|
+
try {
|
|
2267
|
+
return readFeelingsOrThrow(raw);
|
|
2268
|
+
} catch (err) {
|
|
2269
|
+
return { refused: `feelings could not be read: ${String((err as Error).message ?? err)}` };
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
|
|
2273
|
+
function readFeelingsOrThrow(raw: unknown): FeelingsRead {
|
|
2274
|
+
if (raw === undefined || raw === null) return { inputs: [] };
|
|
2275
|
+
if (!Array.isArray(raw)) return { refused: "`feelings` is a list of objects." };
|
|
2276
|
+
const inputs: FeelingInput[] = [];
|
|
2277
|
+
for (const [i, item] of raw.entries()) {
|
|
2278
|
+
if (item === null || typeof item !== "object" || Array.isArray(item)) {
|
|
2279
|
+
return { refused: `feelings[${i}] is not an object.` };
|
|
2280
|
+
}
|
|
2281
|
+
const f = item as Record<string, unknown>;
|
|
2282
|
+
for (const key of ["whose", "core", "emotion"] as const) {
|
|
2283
|
+
if (typeof f[key] !== "string") return { refused: `feelings[${i}].${key} is a word.` };
|
|
2284
|
+
}
|
|
2285
|
+
const carried = f["carried_by"];
|
|
2286
|
+
const other = f["other_word"];
|
|
2287
|
+
if (carried !== undefined && typeof carried !== "string") return { refused: `feelings[${i}].carried_by is text.` };
|
|
2288
|
+
if (other !== undefined && typeof other !== "string") return { refused: `feelings[${i}].other_word is a word.` };
|
|
2289
|
+
// AT THE DOOR, `beneath` is an INDEX into this list and nothing else (review
|
|
2290
|
+
// S3): an id would only be checked after the memory minted, so feelings
|
|
2291
|
+
// would stop being all-or-nothing with their entry.
|
|
2292
|
+
const beneath = f["beneath"];
|
|
2293
|
+
if (beneath !== undefined && beneath !== null && !(typeof beneath === "number" && Number.isInteger(beneath))) {
|
|
2294
|
+
return { refused: `feelings[${i}].beneath is the index of another feeling in this list.` };
|
|
2295
|
+
}
|
|
2296
|
+
inputs.push({
|
|
2297
|
+
whose: f["whose"] as string,
|
|
2298
|
+
core: f["core"] as string,
|
|
2299
|
+
emotion: f["emotion"] as string,
|
|
2300
|
+
strength: f["strength"] as number,
|
|
2301
|
+
...(carried === undefined ? {} : { carriedBy: carried }),
|
|
2302
|
+
...(other === undefined ? {} : { otherWord: other }),
|
|
2303
|
+
...(beneath === undefined || beneath === null ? {} : { beneath: beneath as number }),
|
|
2304
|
+
});
|
|
2305
|
+
}
|
|
2306
|
+
try {
|
|
2307
|
+
checkFeelings(inputs);
|
|
2308
|
+
} catch (err) {
|
|
2309
|
+
if (isStoreError(err, "FEELING_INVALID")) {
|
|
2310
|
+
const d = (err as { detail?: Record<string, unknown> }).detail ?? {};
|
|
2311
|
+
const allowed = typeof d["allowed"] === "string" ? ` (one of ${d["allowed"]})` : "";
|
|
2312
|
+
return { refused: `feelings[${String(d["index"])}]: ${String(d["reason"])}${allowed}.` };
|
|
2313
|
+
}
|
|
2314
|
+
throw err;
|
|
2315
|
+
}
|
|
2316
|
+
return { inputs };
|
|
2317
|
+
}
|
|
2318
|
+
|
|
@@ -114,6 +114,46 @@ export interface ToolSpec {
|
|
|
114
114
|
readonly inputSchema: Record<string, unknown>;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/**
|
|
118
|
+
* `feelings` on a `note` or a `session_end` entry (schema v7, 2026-09-25): one
|
|
119
|
+
* object per feeling, spelled on the feelings wheel (`core/feelings-wheel.ts`).
|
|
120
|
+
* Stored beside the memory and read by nothing yet — salience still comes from
|
|
121
|
+
* `emotional`.
|
|
122
|
+
*/
|
|
123
|
+
const FEELINGS_PROPERTY = {
|
|
124
|
+
type: "array",
|
|
125
|
+
description:
|
|
126
|
+
"Optional: the feelings in this moment, one object each — mixed feelings are several, and yours and the owner's go side by side. Stored beside the memory; they change nothing about how it is held yet.",
|
|
127
|
+
items: {
|
|
128
|
+
type: "object",
|
|
129
|
+
properties: {
|
|
130
|
+
whose: { type: "string", enum: ["owner", "self"], description: "The owner's feeling, or yours." },
|
|
131
|
+
core: { type: "string", enum: ["happy", "sad", "fear", "anger", "surprise", "disgust"] },
|
|
132
|
+
emotion: {
|
|
133
|
+
type: "string",
|
|
134
|
+
description:
|
|
135
|
+
"The specific feeling on the wheel under that core (e.g. hopeful, anxious, frustrated), or your own word — kept as other, and the reply names the nearest wheel words.",
|
|
136
|
+
},
|
|
137
|
+
strength: { type: "number", minimum: 0, maximum: 1 },
|
|
138
|
+
carried_by: {
|
|
139
|
+
type: "string",
|
|
140
|
+
description: "Briefly, what in the moment carried it — the words, what happened. Not a statement of feeling.",
|
|
141
|
+
},
|
|
142
|
+
other_word: {
|
|
143
|
+
type: "string",
|
|
144
|
+
description: "Your own word, when emotion is \"other\" — or just put the word in emotion.",
|
|
145
|
+
},
|
|
146
|
+
beneath: {
|
|
147
|
+
type: "integer",
|
|
148
|
+
minimum: 0,
|
|
149
|
+
description: "The index of another feeling in this list that this one sits on top of (anger over fear).",
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
required: ["whose", "core", "emotion", "strength"],
|
|
153
|
+
additionalProperties: false,
|
|
154
|
+
},
|
|
155
|
+
} as const;
|
|
156
|
+
|
|
117
157
|
/**
|
|
118
158
|
* `note`'s privileges. Each one is a sentence v1 would have shipped in a prompt
|
|
119
159
|
* and left unenforced; each one names the file that enforces it here.
|
|
@@ -219,6 +259,7 @@ const NOTE: ToolSpec = {
|
|
|
219
259
|
description: "What sort of thing this is about. Defaults to fact.",
|
|
220
260
|
},
|
|
221
261
|
title: { type: "string", description: "Optional short handle for the memory." },
|
|
262
|
+
feelings: FEELINGS_PROPERTY,
|
|
222
263
|
},
|
|
223
264
|
required: ["text"],
|
|
224
265
|
additionalProperties: false,
|
|
@@ -500,6 +541,7 @@ const SESSION_END: ToolSpec = {
|
|
|
500
541
|
description:
|
|
501
542
|
"The id or handle of a memory this revises, if it revises one. A field — never written into `content`.",
|
|
502
543
|
},
|
|
544
|
+
feelings: FEELINGS_PROPERTY,
|
|
503
545
|
},
|
|
504
546
|
required: ["content"],
|
|
505
547
|
additionalProperties: false,
|
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
|
|
|
@@ -25,7 +25,9 @@
|
|
|
25
25
|
* taken; it never rotates at all after a copy that FAILED — losing the
|
|
26
26
|
* oldest good backup on the day you could not make a new one is the worst
|
|
27
27
|
* outcome available here; and a `keep` that is not a positive integer falls
|
|
28
|
-
* back to the default rather than meaning "delete everything".
|
|
28
|
+
* back to the default rather than meaning "delete everything". The copies
|
|
29
|
+
* the store takes before a schema migration (`PRE_MIGRATION_NAME_RE`) sit
|
|
30
|
+
* in the same directory on a rule of their own (`expiredPreMigration`).
|
|
29
31
|
*
|
|
30
32
|
* 2. *A half-copy must never count as a snapshot.* The worker runs under a
|
|
31
33
|
* watchdog and the copy is synchronous, so the process can be killed
|
|
@@ -50,7 +52,7 @@
|
|
|
50
52
|
* directory, a failed copy, a failed rename, an aborted run — is a
|
|
51
53
|
* `snapshot.failed` row carrying its `reason` and the `step` it died at.
|
|
52
54
|
*/
|
|
53
|
-
import { cpSync, readdirSync,
|
|
55
|
+
import { cpSync, readdirSync, renameSync, rmSync, statSync } from "node:fs";
|
|
54
56
|
import { homedir } from "node:os";
|
|
55
57
|
import { basename, dirname, join, parse, resolve } from "node:path";
|
|
56
58
|
|
|
@@ -61,8 +63,11 @@ import {
|
|
|
61
63
|
SNAPSHOT_TAKEN_EVENT,
|
|
62
64
|
} from "../core/counterpart.js";
|
|
63
65
|
import {
|
|
64
|
-
DEFAULT_STORE_SUBDIR,
|
|
65
66
|
LAYOUT,
|
|
67
|
+
PRE_MIGRATION_NAME_RE,
|
|
68
|
+
SNAPSHOTS_DIR_NAME,
|
|
69
|
+
defaultSnapshotsDir,
|
|
70
|
+
realpathDeep,
|
|
66
71
|
PRE_ROWS_MARKERS,
|
|
67
72
|
assertSafeDataDir,
|
|
68
73
|
dateOf,
|
|
@@ -83,7 +88,7 @@ import { assertSafeTarget, snapshot, snapshotName } from "./cli/snapshot.js";
|
|
|
83
88
|
const DATABASE_NAME = basename(paths.operational("."));
|
|
84
89
|
|
|
85
90
|
/** The directory the copies live in, beside the store rather than inside it. */
|
|
86
|
-
export
|
|
91
|
+
export { SNAPSHOTS_DIR_NAME };
|
|
87
92
|
|
|
88
93
|
/** How many copies are kept. Owner's ruling, 2026-09-18. */
|
|
89
94
|
export const DEFAULT_KEEP = 14;
|
|
@@ -132,6 +137,14 @@ export const MAX_ATTEMPTS_PER_DAY = 3;
|
|
|
132
137
|
*/
|
|
133
138
|
export const SNAPSHOT_NAME_RE = /^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}Z$/;
|
|
134
139
|
|
|
140
|
+
/**
|
|
141
|
+
* How long a copy taken before a schema migration is kept (the store takes it,
|
|
142
|
+
* `store/pre-migration.ts`). It is not counted toward `keep`, and rotation
|
|
143
|
+
* removes it only once it is this many days old AND `keep` daily copies newer
|
|
144
|
+
* than it exist — so a stretch of failed daily copies never takes it early.
|
|
145
|
+
*/
|
|
146
|
+
export const PRE_MIGRATION_KEEP_DAYS = 14;
|
|
147
|
+
|
|
135
148
|
export interface SnapshotsConfig {
|
|
136
149
|
/** Where the copies go. Absent ⇒ beside the store; see `resolveSnapshotsDir`. */
|
|
137
150
|
readonly dir?: string;
|
|
@@ -169,6 +182,8 @@ export interface RotationReport {
|
|
|
169
182
|
* Never deleted, never counted toward `keep`, and named so they are not a
|
|
170
183
|
* mystery sitting in the one directory he relies on (review B, MAJOR-2). */
|
|
171
184
|
readonly preRows: readonly string[];
|
|
185
|
+
/** Copies taken before a schema migration still on disk, oldest first. */
|
|
186
|
+
readonly preMigration: readonly string[];
|
|
172
187
|
readonly errors: readonly string[];
|
|
173
188
|
}
|
|
174
189
|
|
|
@@ -203,6 +218,7 @@ const EMPTY_ROTATION: RotationReport = {
|
|
|
203
218
|
future: 0,
|
|
204
219
|
unrecognised: [],
|
|
205
220
|
preRows: [],
|
|
221
|
+
preMigration: [],
|
|
206
222
|
errors: [],
|
|
207
223
|
};
|
|
208
224
|
|
|
@@ -234,11 +250,10 @@ export function resolveSnapshotsDir(
|
|
|
234
250
|
if (configured !== undefined && configured.trim().length > 0) {
|
|
235
251
|
return { dir: resolve(configured), reason: "configured" };
|
|
236
252
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
return { dir: join(dirname(store), SNAPSHOTS_DIR_NAME), reason: "beside-the-store" };
|
|
253
|
+
// The store's own rule, so the copy taken before a migration lands in the
|
|
254
|
+
// same directory as the daily ones.
|
|
255
|
+
const dir = defaultSnapshotsDir(dataDir);
|
|
256
|
+
return dir === null ? { dir: null, reason: "no-default-dir" } : { dir, reason: "beside-the-store" };
|
|
242
257
|
}
|
|
243
258
|
|
|
244
259
|
/**
|
|
@@ -300,35 +315,6 @@ export function assertRotatableDir(
|
|
|
300
315
|
return real;
|
|
301
316
|
}
|
|
302
317
|
|
|
303
|
-
/**
|
|
304
|
-
* The real path of a directory that may not exist yet.
|
|
305
|
-
*
|
|
306
|
-
* `resolve` does not follow symlinks and `realpathSync` throws on a path that is
|
|
307
|
-
* not there — and BOTH cases are ordinary here: the snapshots directory does not
|
|
308
|
-
* exist before the first run, and on macOS the directory a test or a `$TMPDIR`
|
|
309
|
-
* names is very often a symlink. Comparing one side realpathed against the other
|
|
310
|
-
* side merely resolved is how a containment check says "no" to a path that is
|
|
311
|
-
* the same directory. So: realpath the deepest ancestor that DOES exist, and put
|
|
312
|
-
* the rest back on.
|
|
313
|
-
*/
|
|
314
|
-
function realpathDeep(path: string): string {
|
|
315
|
-
const resolved = resolve(path);
|
|
316
|
-
let head = resolved;
|
|
317
|
-
const tail: string[] = [];
|
|
318
|
-
for (;;) {
|
|
319
|
-
try {
|
|
320
|
-
const real = realpathSync(head);
|
|
321
|
-
return tail.length === 0 ? real : join(real, ...tail);
|
|
322
|
-
} catch {
|
|
323
|
-
const parent = dirname(head);
|
|
324
|
-
// Nothing on this path exists. The resolved form is the whole answer.
|
|
325
|
-
if (parent === head) return resolved;
|
|
326
|
-
tail.unshift(basename(head));
|
|
327
|
-
head = parent;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
318
|
// ── the run ─────────────────────────────────────────────────────────────────
|
|
333
319
|
|
|
334
320
|
export interface SnapshotRunInput {
|
|
@@ -763,6 +749,19 @@ export function rotate(
|
|
|
763
749
|
}
|
|
764
750
|
}
|
|
765
751
|
const remaining = names.filter((n) => !deleted.includes(n));
|
|
752
|
+
// Pre-migration copies: past their days AND behind `keep` newer daily copies.
|
|
753
|
+
const preMigration: string[] = [];
|
|
754
|
+
for (const name of expiredPreMigration(read.preMigration, remaining, limit, now)) {
|
|
755
|
+
try {
|
|
756
|
+
rmSync(join(dir, name), { recursive: true, force: true });
|
|
757
|
+
deleted.push(name);
|
|
758
|
+
} catch (err) {
|
|
759
|
+
const why = `could not remove ${name}: ${messageOf(err)}`;
|
|
760
|
+
rotationErrors.push(why);
|
|
761
|
+
errors.push(why);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
for (const name of read.preMigration) if (!deleted.includes(name)) preMigration.push(name);
|
|
766
765
|
return {
|
|
767
766
|
deleted,
|
|
768
767
|
kept: remaining.length,
|
|
@@ -771,10 +770,31 @@ export function rotate(
|
|
|
771
770
|
future: futureNamesIn(remaining, now).length,
|
|
772
771
|
unrecognised: read.unrecognised,
|
|
773
772
|
preRows: read.preRows,
|
|
773
|
+
preMigration,
|
|
774
774
|
errors: rotationErrors,
|
|
775
775
|
};
|
|
776
776
|
}
|
|
777
777
|
|
|
778
|
+
/**
|
|
779
|
+
* The pre-migration copies rotation may remove: older than
|
|
780
|
+
* `PRE_MIGRATION_KEEP_DAYS` by the date in their name, with at least `keep`
|
|
781
|
+
* daily copies newer than them. Names sort by instant, so a string compare of
|
|
782
|
+
* the leading instant is a time compare.
|
|
783
|
+
*/
|
|
784
|
+
export function expiredPreMigration(
|
|
785
|
+
preMigration: readonly string[],
|
|
786
|
+
daily: readonly string[],
|
|
787
|
+
keep: number,
|
|
788
|
+
now: number,
|
|
789
|
+
): string[] {
|
|
790
|
+
const cutoff = dateOf(now - PRE_MIGRATION_KEEP_DAYS * 86_400_000);
|
|
791
|
+
return preMigration.filter((name) => {
|
|
792
|
+
if (name.slice(0, 10) >= cutoff) return false;
|
|
793
|
+
const instant = name.slice(0, 24);
|
|
794
|
+
return daily.filter((d) => d > instant).length >= keep;
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
|
|
778
798
|
/**
|
|
779
799
|
* The snapshots in a directory, sorted oldest first — and the one place that
|
|
780
800
|
* decides what COUNTS as a snapshot, which is the same decision as what rotation
|
|
@@ -801,13 +821,21 @@ export function readSnapshotsDir(dir: string): SnapshotsDirRead {
|
|
|
801
821
|
entries = readdirSync(dir, { withFileTypes: true });
|
|
802
822
|
} catch {
|
|
803
823
|
// A directory that does not exist yet holds no snapshots. Not an error.
|
|
804
|
-
return { names: [], readable: false, unrecognised: [], preRows: [] };
|
|
824
|
+
return { names: [], readable: false, unrecognised: [], preRows: [], preMigration: [] };
|
|
805
825
|
}
|
|
806
826
|
const names: string[] = [];
|
|
807
827
|
const unrecognised: string[] = [];
|
|
808
828
|
const preRows: string[] = [];
|
|
829
|
+
const preMigration: string[] = [];
|
|
809
830
|
for (const entry of entries) {
|
|
810
831
|
if (!entry.isDirectory()) continue;
|
|
832
|
+
// A copy the store took before a migration: its own channel, never counted
|
|
833
|
+
// toward `keep` and never "today's". Only one that looks like a copy.
|
|
834
|
+
if (PRE_MIGRATION_NAME_RE.test(entry.name)) {
|
|
835
|
+
if (copyKind(join(dir, entry.name)) === "ours") preMigration.push(entry.name);
|
|
836
|
+
else unrecognised.push(entry.name);
|
|
837
|
+
continue;
|
|
838
|
+
}
|
|
811
839
|
if (!SNAPSHOT_NAME_RE.test(entry.name)) continue;
|
|
812
840
|
// AND IT HAS TO LOOK LIKE ONE WE WROTE (F2 review, MINOR-7). Inside the
|
|
813
841
|
// default directory this is belt and braces — the package made every entry
|
|
@@ -843,6 +871,7 @@ export function readSnapshotsDir(dir: string): SnapshotsDirRead {
|
|
|
843
871
|
readable: true,
|
|
844
872
|
unrecognised: unrecognised.sort(),
|
|
845
873
|
preRows: preRows.sort(),
|
|
874
|
+
preMigration: preMigration.sort(),
|
|
846
875
|
};
|
|
847
876
|
}
|
|
848
877
|
|
|
@@ -858,6 +887,9 @@ export interface SnapshotsDirRead {
|
|
|
858
887
|
* never counted toward `keep`, and named rather than left a mystery in the
|
|
859
888
|
* one directory the owner relies on (review B, MAJOR-2). */
|
|
860
889
|
readonly preRows: string[];
|
|
890
|
+
/** Copies the store took before a schema migration, oldest first. Kept apart
|
|
891
|
+
* from `names`: rotation removes one only by `expiredPreMigration`'s rule. */
|
|
892
|
+
readonly preMigration: string[];
|
|
861
893
|
}
|
|
862
894
|
|
|
863
895
|
/** How many files a finished copy holds — the mirror's input to `verifyCopy`,
|
|
@@ -15,6 +15,8 @@ redefined here.
|
|
|
15
15
|
|
|
16
16
|
## 1. `recall/` has no fourth channel yet — the traversal is exported, not wired
|
|
17
17
|
|
|
18
|
+
**Closed 2026-09-24** — hops modulate only (answer a): `recall/activate.ts` adds `spread(seeds, day)` contributions to existing candidates; wired by `core/retrieval.ts#composeTurn`.
|
|
19
|
+
|
|
18
20
|
**Owner:** `recall/` (its NOTES.md §7 already names the seam: "when `associate/`
|
|
19
21
|
ships, its hops feed a fourth channel and the gate does not change").
|
|
20
22
|
**Have:** `spread(input, tunables)` — a pure function — and `Associate.spreadFrom()`,
|
|
@@ -107,6 +109,8 @@ counts and ids sitting in `sessions/association/claims/`.
|
|
|
107
109
|
|
|
108
110
|
## 4. Nobody calls `retargetOnSupersede` — supersede does not know about edges
|
|
109
111
|
|
|
112
|
+
**Closed 2026-09-24** — `counterpart.ts` injects `retargetOnSupersede` into both `supersede` callers (`Schemas.open`'s `retarget`, and `applyRevision` in `core/revision.ts`).
|
|
113
|
+
|
|
110
114
|
**Owner:** `store/` and whoever owns revision (scar §2.2: "supersede retargets edges
|
|
111
115
|
too — v1's `gist.merge` set `merged_into` and nothing re-pointed the edges, so
|
|
112
116
|
successors started cold").
|
|
@@ -121,6 +125,8 @@ successor cold**, which is the scar, live again.
|
|
|
121
125
|
|
|
122
126
|
## 5. The credit tiers arrive from a reference-resolution step that has no home
|
|
123
127
|
|
|
128
|
+
**Closed 2026-09-24** — `Counterpart.creditReferences` (tiers from `recall/reference.ts`) feeds `coactivate`; the flush crosses processes via `pending.ts`.
|
|
129
|
+
|
|
124
130
|
**Owner:** the boundary adapter (`recall/INTERFACE-GAPS.md` §5 records the same gap
|
|
125
131
|
from the other side).
|
|
126
132
|
**Needed:** `coactivate(members)` takes `{id, tier}` — the tier being §9.2's
|
|
@@ -167,6 +173,8 @@ be a second vocabulary for a concept another module owns.
|
|
|
167
173
|
|
|
168
174
|
## 8. The observer predicate still lives in `store/`
|
|
169
175
|
|
|
176
|
+
**Closed 2026-09-24** — the predicate lives in `src/core/observer.ts` (hoisted 2026-08-25).
|
|
177
|
+
|
|
170
178
|
Not a defect, and recorded so nobody "fixes" it: `Associate.observer` reads
|
|
171
179
|
`store.observer` and never re-derives it. `docs/SEAMS.md` queued item 4 already says
|
|
172
180
|
the hoist to `src/core/observer.ts` is a MOVE, not a rewrite; associate is now the
|