counterparts 0.3.1 → 0.3.3
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 +121 -1
- package/docs/module-map.md +2 -0
- package/package.json +1 -1
- package/src/adapters/claude-code/NOTES.md +44 -0
- package/src/adapters/claude-code/bin/hook.ts +100 -24
- package/src/adapters/claude-code/bin/runner.ts +3 -1
- package/src/adapters/claude-code/config.ts +30 -0
- package/src/adapters/claude-code/doctor.ts +59 -24
- package/src/adapters/claude-code/hooks.ts +185 -14
- package/src/adapters/claude-code/index.ts +4 -0
- package/src/adapters/cli/commands.ts +189 -59
- 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 +320 -0
- package/src/adapters/cli/repair-dates.ts +3 -1
- package/src/adapters/dashboard/CONTRACT.md +13 -9
- 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/registries.ts +4 -0
- package/src/adapters/dashboard/upgrade.ts +23 -0
- package/src/adapters/dashboard/web/README.md +161 -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/flow.ts +2 -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 +19 -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 +18 -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 +18 -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 +188 -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 +82 -0
- package/src/adapters/dashboard/web/pages/self/markdown.js +61 -0
- package/src/adapters/dashboard/web/pages/self/sections/journal.js +88 -0
- package/src/adapters/dashboard/web/pages/self/sections/page.js +192 -0
- package/src/adapters/dashboard/web/pages/self/sections/settling.js +145 -0
- package/src/adapters/dashboard/web/pages/self/sections/stories.js +47 -0
- package/src/adapters/dashboard/web/pages/self/sections/wake.js +90 -0
- package/src/adapters/dashboard/web/pages/self/self.css +242 -0
- package/src/adapters/dashboard/web/pages/self/state.js +23 -0
- package/src/adapters/dashboard/web/pages/self/tips.js +50 -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 +133 -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 +373 -0
- package/src/adapters/dashboard/web/views/memories.ts +342 -0
- package/src/adapters/dashboard/web/views/memory.ts +224 -0
- package/src/adapters/dashboard/web/views/meta.ts +64 -0
- package/src/adapters/dashboard/web/views/mind.ts +853 -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/feelings-line.ts +74 -0
- package/src/adapters/fired.ts +106 -35
- package/src/adapters/mcp/CONTRACT.md +8 -0
- package/src/adapters/mcp/NOTES.md +88 -0
- package/src/adapters/mcp/bin/serve.ts +5 -1
- package/src/adapters/mcp/index.ts +3 -0
- package/src/adapters/mcp/server.ts +322 -6
- package/src/adapters/mcp/tools.ts +89 -0
- package/src/adapters/mcp/write-up.ts +1 -1
- package/src/core/bridge.ts +21 -16
- package/src/core/counterpart.ts +337 -5
- package/src/core/encode/CONTRACT.md +7 -1
- package/src/core/feelings-wheel.ts +376 -0
- package/src/core/mint.ts +23 -2
- package/src/core/physics/CONTRACT.md +43 -0
- package/src/core/physics/NOTES.md +94 -0
- package/src/core/physics/index.ts +98 -6
- package/src/core/prospective/CONTRACT.md +35 -6
- package/src/core/prospective/INTERFACE-GAPS.md +16 -1
- package/src/core/prospective/NOTES.md +175 -4
- package/src/core/prospective/derive.ts +32 -3
- package/src/core/prospective/index.ts +362 -39
- package/src/core/prospective/tunables.ts +18 -1
- package/src/core/prospective/windows.ts +110 -90
- package/src/core/recall/CONTRACT.md +28 -0
- package/src/core/recall/NOTES.md +39 -0
- package/src/core/recall/activate.ts +32 -5
- package/src/core/recall/gate.ts +7 -1
- package/src/core/recall/index.ts +19 -0
- package/src/core/recall/mood.ts +106 -0
- package/src/core/recall/tunables.ts +26 -0
- package/src/core/remember/index.ts +1 -0
- package/src/core/remember/proposals.ts +86 -3
- package/src/core/self/NOTES.md +17 -0
- package/src/core/self/calendar.ts +7 -78
- package/src/core/self/episodes.ts +7 -8
- package/src/core/self/identity.ts +20 -1
- package/src/core/self/index.ts +32 -11
- package/src/core/self/writer.ts +22 -22
- package/src/core/sleep/cycle.ts +8 -2
- package/src/core/store/CONTRACT.md +33 -7
- package/src/core/store/NOTES.md +162 -0
- package/src/core/store/errors.ts +15 -0
- package/src/core/store/feelings.ts +199 -0
- package/src/core/store/index.ts +397 -48
- package/src/core/store/operational.ts +148 -12
- package/src/core/store/owner-op-seam.ts +13 -3
- package/src/core/store/pre-migration.ts +3 -1
- 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 +22 -0
- package/src/adapters/dashboard/web/brain.html +0 -463
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
* nobody needed).
|
|
33
33
|
*/
|
|
34
34
|
import { spawnSync } from "node:child_process";
|
|
35
|
+
import { addDays, isDay, localDate, resolveZone } from "../../core/time.js";
|
|
35
36
|
import { existsSync, mkdirSync, rmSync, statSync } from "node:fs";
|
|
36
37
|
import { homedir } from "node:os";
|
|
37
38
|
import { dirname, join } from "node:path";
|
|
@@ -57,7 +58,6 @@ import {
|
|
|
57
58
|
STORE_CREATED_KEY,
|
|
58
59
|
Store,
|
|
59
60
|
assertPreMigrationTarget,
|
|
60
|
-
dateOf,
|
|
61
61
|
isStoreError,
|
|
62
62
|
paths,
|
|
63
63
|
pendingMigration,
|
|
@@ -209,7 +209,8 @@ export interface DoctorInput {
|
|
|
209
209
|
readonly dir: string;
|
|
210
210
|
/** Null when there is no store at `dir` — the store findings then say so. */
|
|
211
211
|
readonly store: Store | null;
|
|
212
|
-
/** Today
|
|
212
|
+
/** Today in the person's zone, `YYYY-MM-DD` — the same spelling every `date`
|
|
213
|
+
* field uses (UTC until 2026-09-25; docs/time.md). */
|
|
213
214
|
readonly today: string;
|
|
214
215
|
/**
|
|
215
216
|
* The persisted spawn-refusal counters, `reason -> count`
|
|
@@ -779,10 +780,17 @@ function payloadOf(row: EventRow | undefined): Record<string, unknown> {
|
|
|
779
780
|
|
|
780
781
|
/** The CALENDAR date a row is about: its own field, else the wall clock it was
|
|
781
782
|
* written at. `day` is the lived-day column and answers a different question. */
|
|
783
|
+
/**
|
|
784
|
+
* The zone this reading names days in — the config's `timeZone`, else the
|
|
785
|
+
* machine's — set once at the top of `doctorFindings` (which is synchronous)
|
|
786
|
+
* so the dozen `rowDate` calls below need no extra argument.
|
|
787
|
+
*/
|
|
788
|
+
let readingZone: string = resolveZone(undefined);
|
|
789
|
+
|
|
782
790
|
function rowDate(row: EventRow | undefined): string | null {
|
|
783
791
|
if (row === undefined) return null;
|
|
784
792
|
const p = payloadOf(row);
|
|
785
|
-
return typeof p["date"] === "string" && p["date"].length > 0 ? p["date"] :
|
|
793
|
+
return typeof p["date"] === "string" && p["date"].length > 0 ? p["date"] : localDate(row.at, readingZone);
|
|
786
794
|
}
|
|
787
795
|
|
|
788
796
|
function num(p: Record<string, unknown>, key: string): number | null {
|
|
@@ -1312,6 +1320,18 @@ function retentionFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
1312
1320
|
return [finding("retention", "green", TITLE, `${policy} · ${counts}`, "", data)];
|
|
1313
1321
|
}
|
|
1314
1322
|
|
|
1323
|
+
/**
|
|
1324
|
+
* THE ZONE IN USE, on the Clock line (docs/time.md, 2026-09-25): `(America/Denver)`,
|
|
1325
|
+
* and when the config names a zone this machine does not know, that too — it
|
|
1326
|
+
* was ignored, and this is where the owner sees it.
|
|
1327
|
+
*/
|
|
1328
|
+
function zoneNote(input: DoctorInput): string {
|
|
1329
|
+
const unknown = input.config.timeZoneUnknown;
|
|
1330
|
+
return unknown === undefined
|
|
1331
|
+
? `(${readingZone})`
|
|
1332
|
+
: `(${readingZone}; timeZone "${unknown}" in the config is not a zone this machine knows, so it was ignored)`;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1315
1335
|
/** The two clocks, and the gap that IS I32's signature. */
|
|
1316
1336
|
function clockFindings(input: DoctorInput, store: Store): Finding[] {
|
|
1317
1337
|
const livedDay = store.livedDay();
|
|
@@ -1327,13 +1347,13 @@ function clockFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
1327
1347
|
// the clock, so the comparison is not made and the line says why.
|
|
1328
1348
|
if (read.unknown) {
|
|
1329
1349
|
const facts =
|
|
1330
|
-
`lived day ${livedDay}, lastActiveDate ${lastActive ?? "(unset)"}, today ${input.today} (
|
|
1350
|
+
`lived day ${livedDay}, lastActiveDate ${lastActive ?? "(unset)"}, today ${input.today} ${zoneNote(input)} — ` +
|
|
1331
1351
|
undetermined(BOUNDARY_EVENT);
|
|
1332
1352
|
return [finding("clock", "green", "Clock", facts, "", data)];
|
|
1333
1353
|
}
|
|
1334
1354
|
const facts =
|
|
1335
1355
|
`lived day ${livedDay}, lastActiveDate ${lastActive ?? "(unset)"}, ` +
|
|
1336
|
-
`newest boundary ${boundary ?? "(none)"}, today ${input.today} (
|
|
1356
|
+
`newest boundary ${boundary ?? "(none)"}, today ${input.today} ${zoneNote(input)}`;
|
|
1337
1357
|
if (boundary !== null && (lastActive === null || lastActive < boundary)) {
|
|
1338
1358
|
return [
|
|
1339
1359
|
finding(
|
|
@@ -1631,25 +1651,25 @@ function storeFirstDay(store: Store): string | null {
|
|
|
1631
1651
|
return readings.length === 0 ? null : readings.reduce((a, b) => (b < a ? b : a));
|
|
1632
1652
|
}
|
|
1633
1653
|
|
|
1634
|
-
/** The calendar day (
|
|
1635
|
-
* or null when it has none, or none that can be read. */
|
|
1654
|
+
/** The calendar day (the person's zone) of the EARLIEST `at` among the store's
|
|
1655
|
+
* event rows, or null when it has none, or none that can be read. */
|
|
1636
1656
|
function oldestEventDay(store: Store): string | null {
|
|
1637
1657
|
try {
|
|
1638
1658
|
const at = store.eventLogCensus().oldestAt;
|
|
1639
|
-
return typeof at === "number" && Number.isFinite(at) && at > 0 ?
|
|
1659
|
+
return typeof at === "number" && Number.isFinite(at) && at > 0 ? localDate(at, readingZone) : null;
|
|
1640
1660
|
} catch {
|
|
1641
1661
|
return null;
|
|
1642
1662
|
}
|
|
1643
1663
|
}
|
|
1644
1664
|
|
|
1645
|
-
/** The calendar day (
|
|
1665
|
+
/** The calendar day (the person's zone) the store's database file was born, or null when the
|
|
1646
1666
|
* filesystem keeps no birth time — zero, or a "birth" no earlier than the last
|
|
1647
1667
|
* change, which is what a filesystem without one may report instead. */
|
|
1648
1668
|
function databaseBirthDay(dir: string): string | null {
|
|
1649
1669
|
try {
|
|
1650
1670
|
const stat = statSync(paths.operational(dir));
|
|
1651
1671
|
const born = stat.birthtimeMs;
|
|
1652
|
-
return Number.isFinite(born) && born > 0 && born < stat.ctimeMs ?
|
|
1672
|
+
return Number.isFinite(born) && born > 0 && born < stat.ctimeMs ? localDate(born, readingZone) : null;
|
|
1653
1673
|
} catch {
|
|
1654
1674
|
return null;
|
|
1655
1675
|
}
|
|
@@ -1677,11 +1697,9 @@ function windowPhrase(shown: string, today: string): string {
|
|
|
1677
1697
|
return shown === today ? `since ${today}` : `${shown}→${today}`;
|
|
1678
1698
|
}
|
|
1679
1699
|
|
|
1680
|
-
/** `YYYY-MM-DD`, `back` days before `today
|
|
1700
|
+
/** `YYYY-MM-DD`, `back` days before `today` — label arithmetic (`time.ts`). */
|
|
1681
1701
|
function daysBefore(today: string, back: number): string {
|
|
1682
|
-
|
|
1683
|
-
if (Number.isNaN(at)) return today;
|
|
1684
|
-
return new Date(at - back * 86_400_000).toISOString().slice(0, 10);
|
|
1702
|
+
return isDay(today) ? addDays(today, -back) : today;
|
|
1685
1703
|
}
|
|
1686
1704
|
|
|
1687
1705
|
/** Every row of one name whose CALENDAR date is on or after `from`. */
|
|
@@ -1901,7 +1919,7 @@ function firedFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
1901
1919
|
`this store is on lived day ${String(report.livedDay)} — too new to grade; nothing has fired ` +
|
|
1902
1920
|
`because nothing has happened yet` +
|
|
1903
1921
|
(c.blocked === 0 ? "" : `, though ${String(c.blocked)} was already stopped by something`),
|
|
1904
|
-
c.blocked === 0 ? "" : "Run: counterparts
|
|
1922
|
+
c.blocked === 0 ? "" : "Run: counterparts mechanisms --all — the blocked rows say by what.",
|
|
1905
1923
|
data,
|
|
1906
1924
|
),
|
|
1907
1925
|
];
|
|
@@ -1938,8 +1956,8 @@ function firedFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
1938
1956
|
"Fired",
|
|
1939
1957
|
`${roll}. ${changed.join(". ")}`,
|
|
1940
1958
|
report.wentBlocked.length > 0
|
|
1941
|
-
? `Run: counterparts
|
|
1942
|
-
: `Run: counterparts
|
|
1959
|
+
? `Run: counterparts mechanisms --all — ${STATE_MEANING.blocked}, and the reason on the row names what to fix.`
|
|
1960
|
+
: `Run: counterparts mechanisms --all — ${STATE_MEANING.quiet}, which is a wiring fault more often than a verdict.`,
|
|
1943
1961
|
data,
|
|
1944
1962
|
),
|
|
1945
1963
|
];
|
|
@@ -2354,11 +2372,21 @@ export function selfPageFindings(store: Store): Finding[] {
|
|
|
2354
2372
|
),
|
|
2355
2373
|
];
|
|
2356
2374
|
}
|
|
2357
|
-
const stale = pageStaleOn(page.revisedOn,
|
|
2375
|
+
const stale = pageStaleOn(page.revisedOn, store.today(), SELF_TUNABLES.PAGE_STALE_DAYS);
|
|
2358
2376
|
const detail =
|
|
2359
2377
|
`${page.bytes} bytes, version ${page.version}, last revised ${page.revisedOn === "" ? "(unrecorded)" : page.revisedOn}` +
|
|
2360
2378
|
`${page.by === null ? "" : ` by ${page.by}`}`;
|
|
2361
|
-
|
|
2379
|
+
// The day count and the limit ride along so a surface can say it in words
|
|
2380
|
+
// ("not rewritten in 16 days") without re-deriving either (dashboard health).
|
|
2381
|
+
const data = {
|
|
2382
|
+
present: true,
|
|
2383
|
+
bytes: page.bytes,
|
|
2384
|
+
version: page.version,
|
|
2385
|
+
revisedOn: page.revisedOn,
|
|
2386
|
+
stale,
|
|
2387
|
+
daysSince: calendarDaysSince(page.revisedOn, store.today()),
|
|
2388
|
+
staleAfter: SELF_TUNABLES.PAGE_STALE_DAYS,
|
|
2389
|
+
};
|
|
2362
2390
|
return [
|
|
2363
2391
|
stale
|
|
2364
2392
|
? finding(
|
|
@@ -2493,7 +2521,7 @@ export function pageWriterFindings(store: Store, config: AdapterConfig): Finding
|
|
|
2493
2521
|
"Page writer",
|
|
2494
2522
|
detail,
|
|
2495
2523
|
bad || overdue
|
|
2496
|
-
? "counterparts
|
|
2524
|
+
? "counterparts mechanisms --all --dir <store> --observer shows the run's own row. A night that is owed but never delivered is usually the host's injection ceiling: the block is deferred rather than truncated, so raise injectionBudgetBytes or run the writer in host mode. counterparts self-page --write amends the page by hand meanwhile."
|
|
2497
2525
|
: "",
|
|
2498
2526
|
{
|
|
2499
2527
|
...data,
|
|
@@ -2543,12 +2571,18 @@ function clearedPage(
|
|
|
2543
2571
|
* two are asserted to agree.
|
|
2544
2572
|
*/
|
|
2545
2573
|
function pageStaleOn(revisedOn: string, today: string, limit: number): boolean {
|
|
2574
|
+
const days = calendarDaysSince(revisedOn, today);
|
|
2575
|
+
return days === null ? true : days > limit;
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2578
|
+
/** Calendar days from `revisedOn` to `today`; null when either does not read. */
|
|
2579
|
+
function calendarDaysSince(revisedOn: string, today: string): number | null {
|
|
2546
2580
|
const on = revisedOn.trim();
|
|
2547
|
-
if (!/^\d{4}-\d{2}-\d{2}$/.test(on) || !/^\d{4}-\d{2}-\d{2}$/.test(today)) return
|
|
2581
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(on) || !/^\d{4}-\d{2}-\d{2}$/.test(today)) return null;
|
|
2548
2582
|
const a = Date.parse(`${on}T00:00:00Z`);
|
|
2549
2583
|
const b = Date.parse(`${today}T00:00:00Z`);
|
|
2550
|
-
if (!Number.isFinite(a) || !Number.isFinite(b)) return
|
|
2551
|
-
return Math.round((b - a) / 86_400_000)
|
|
2584
|
+
if (!Number.isFinite(a) || !Number.isFinite(b)) return null;
|
|
2585
|
+
return Math.round((b - a) / 86_400_000);
|
|
2552
2586
|
}
|
|
2553
2587
|
|
|
2554
2588
|
/**
|
|
@@ -2980,6 +3014,7 @@ export function summaryLine(t: Record<Lowercase<GradeWord>, number>): string {
|
|
|
2980
3014
|
* I32's own signature.
|
|
2981
3015
|
*/
|
|
2982
3016
|
export function doctorFindings(input: DoctorInput): Finding[] {
|
|
3017
|
+
readingZone = resolveZone(input.config.timeZone);
|
|
2983
3018
|
const now = input.now ?? ((): number => Date.now());
|
|
2984
3019
|
const deadline = input.budgetMs === undefined ? null : now() + input.budgetMs;
|
|
2985
3020
|
const unread = input.configReason === "not-read";
|
|
@@ -3249,7 +3284,7 @@ const TITLE_COLUMN = 20;
|
|
|
3249
3284
|
* not green. */
|
|
3250
3285
|
export function reportLines(findings: readonly Finding[], today: string): string[] {
|
|
3251
3286
|
const ordered = worstFirst(findings);
|
|
3252
|
-
const lines = [`counterparts doctor — ${today}
|
|
3287
|
+
const lines = [`counterparts doctor — ${today}`, ""];
|
|
3253
3288
|
for (const f of ordered) lines.push(...findingLines(f));
|
|
3254
3289
|
lines.push("");
|
|
3255
3290
|
lines.push(summaryLine(tally(ordered)));
|
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
WAKE_DELIVERED_EVENT,
|
|
52
52
|
WAKE_INJECTED_EVENT,
|
|
53
53
|
} from "../../core/counterpart.js";
|
|
54
|
-
import type { AdapterDurableEventName } from "../../core/counterpart.js";
|
|
54
|
+
import type { AdapterDurableEventName, PlainReminder } from "../../core/counterpart.js";
|
|
55
55
|
import type {
|
|
56
56
|
BoundaryKind,
|
|
57
57
|
CaptureResult,
|
|
@@ -98,6 +98,7 @@ import {
|
|
|
98
98
|
writerInstruction,
|
|
99
99
|
writerInstructionOverhead,
|
|
100
100
|
} from "../../core/self/index.js";
|
|
101
|
+
import { localClock, localDate, readableDate } from "../../core/time.js";
|
|
101
102
|
import { capabilities, pageWriterMode } from "./config.js";
|
|
102
103
|
import { TUNABLES } from "./config.js";
|
|
103
104
|
import type { AdapterConfig, CapabilityReport } from "./config.js";
|
|
@@ -166,6 +167,13 @@ export interface HookInput {
|
|
|
166
167
|
readonly model?: string;
|
|
167
168
|
/** Today's calendar date, for the temporal channel and the horizon lane. */
|
|
168
169
|
readonly at?: string;
|
|
170
|
+
/**
|
|
171
|
+
* This session is the host-mode NIGHTLY PAGE WRITER this package started
|
|
172
|
+
* (`page-writer.ts`, `COUNTERPARTS_PAGE_WRITER` in its environment): a
|
|
173
|
+
* headless `claude -p` nobody watches. A plain reminder is never claimed in
|
|
174
|
+
* it — its beat would be spent on a terminal no one reads (2026-09-26 review).
|
|
175
|
+
*/
|
|
176
|
+
readonly pageWriter?: boolean;
|
|
169
177
|
/**
|
|
170
178
|
* THE HOST'S RE-FIRE. A blocked Stop comes back with `stop_hook_active`, and
|
|
171
179
|
* that pass must ask nothing — v1's anti-loop, kept for the same reason. It is
|
|
@@ -219,6 +227,21 @@ export interface HookResult {
|
|
|
219
227
|
readonly spansAppended: number;
|
|
220
228
|
readonly spawn: SpawnOutcome | null;
|
|
221
229
|
readonly observer: boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Lines for the PERSON — the host's `systemMessage`, which their terminal
|
|
232
|
+
* shows (`bin/hook.ts#hostDelivery`). Today only plain reminders
|
|
233
|
+
* (`Counterpart.plainDueToday`, 2026-09-26), at SessionStart and at a
|
|
234
|
+
* prompt; absent when there are none. The same lines also ride in
|
|
235
|
+
* `injection` (`plainContextLine`), for the model, so it can raise them.
|
|
236
|
+
*
|
|
237
|
+
* NOT YET CLAIMED (2026-09-26 review): `plain` is the records behind these
|
|
238
|
+
* lines, in the same order, and the delivery claims them only once it knows
|
|
239
|
+
* the envelope carries them (`bin/hook.ts#deliverTurn` → `claimPlain`); what
|
|
240
|
+
* it cannot carry, or loses the race for, is stripped (`withoutPlain`) and
|
|
241
|
+
* waits for the next prompt.
|
|
242
|
+
*/
|
|
243
|
+
readonly notices?: readonly string[];
|
|
244
|
+
readonly plain?: readonly PlainReminder[];
|
|
222
245
|
}
|
|
223
246
|
|
|
224
247
|
export interface AdapterEvent {
|
|
@@ -690,10 +713,25 @@ export class ClaudeCodeAdapter {
|
|
|
690
713
|
// running (mechanism inventory 2026-09-17, S2).
|
|
691
714
|
this.noteWakeExpectation(input, woke.sentinel);
|
|
692
715
|
|
|
693
|
-
|
|
716
|
+
// THE PERSON'S CLOCK, as the wake's first line (docs/time.md rule 5,
|
|
717
|
+
// 2026-09-25): `Now: Fri 25 Sep 2026, 1:40 pm MDT`, in the store's zone.
|
|
718
|
+
// OUTSIDE the wake block, above its opening comment, so the block's own
|
|
719
|
+
// byte count, both sentinels and the preface's reserve are untouched —
|
|
720
|
+
// the delivery check finds its sentinels by prefix, not by line number.
|
|
721
|
+
// It is counted wherever the host's ceiling is: the over-budget event
|
|
722
|
+
// and the room an ask may take both measure `sent`, not `woke.bytes`.
|
|
723
|
+
// PLAIN REMINDERS DUE TODAY (2026-09-26) ride right under the clock, outside
|
|
724
|
+
// the wake block like the clock itself, and go to the person too
|
|
725
|
+
// (`notices`). NOT claimed here: the delivery claims them once it knows
|
|
726
|
+
// the envelope carries them, and a full wake that leaves no room sends
|
|
727
|
+
// them to the first prompt instead (`bin/hook.ts#deliverTurn`).
|
|
728
|
+
const plain = this.plainFor(input);
|
|
729
|
+
const lead = `${woke.text.length === 0 && plain.context.length === 0 ? "" : `${this.nowLine()}\n`}${plain.context}`;
|
|
730
|
+
const sent = woke.bytes + Buffer.byteLength(lead, "utf8");
|
|
731
|
+
if (budget !== undefined && sent > budget) {
|
|
694
732
|
// Exceeding a reported limit is an EVENT, never silent degradation. The
|
|
695
733
|
// bundle still goes: truncated-and-detectable beats absent.
|
|
696
|
-
this.emit("adapter.injection.overbudget", { bytes:
|
|
734
|
+
this.emit("adapter.injection.overbudget", { bytes: sent, budget });
|
|
697
735
|
}
|
|
698
736
|
this.record(WAKE_INJECTED_EVENT, input, {
|
|
699
737
|
ok: woke.ok,
|
|
@@ -738,25 +776,26 @@ export class ClaudeCodeAdapter {
|
|
|
738
776
|
// question is advisory and returns at the next session; a night that
|
|
739
777
|
// passes is a day missing from the page for good (S2 review, MINOR-5).
|
|
740
778
|
const scopeFirst = wantsAsk && !this.writerStarvedByScope();
|
|
741
|
-
const ask = scopeFirst ? this.deliverScopeAsk(input,
|
|
779
|
+
const ask = scopeFirst ? this.deliverScopeAsk(input, sent, budget) : "";
|
|
742
780
|
const chosen =
|
|
743
|
-
ask.length > 0 ? ask : this.deliverPageWriterAsk(input,
|
|
744
|
-
if (ask.length > 0) this.deliverPageWriterAsk(input,
|
|
781
|
+
ask.length > 0 ? ask : this.deliverPageWriterAsk(input, sent, budget, false);
|
|
782
|
+
if (ask.length > 0) this.deliverPageWriterAsk(input, sent, budget, true);
|
|
745
783
|
// THE WRITE-UP POINTER RIDES AFTER WHICHEVER ASK TOOK THE FIELD, never
|
|
746
784
|
// instead of it (C2): it may coincide with either, it is measured against
|
|
747
785
|
// the room BOTH of them left, and it is fail-open by construction — a
|
|
748
786
|
// throw inside it costs the pointer and never the wake or the other ask.
|
|
749
787
|
const chosenBytes = chosen.length === 0 ? 0 : Buffer.byteLength(`\n\n${chosen}`, "utf8");
|
|
750
|
-
const writeUp = this.deliverWriteUpAsk(input,
|
|
788
|
+
const writeUp = this.deliverWriteUpAsk(input, sent + chosenBytes);
|
|
751
789
|
const asks = [chosen, writeUp].filter((a) => a.length > 0).join("\n\n");
|
|
752
790
|
return {
|
|
753
791
|
...out,
|
|
754
792
|
ok: woke.ok,
|
|
755
793
|
reason: woke.reason,
|
|
756
|
-
injection: woke.text
|
|
794
|
+
injection: `${lead}${woke.text}`,
|
|
757
795
|
bytes: woke.bytes,
|
|
758
796
|
sentinel: woke.sentinel,
|
|
759
797
|
ask: asks.length === 0 ? null : asks,
|
|
798
|
+
...(plain.due.length === 0 ? {} : { notices: plain.notices, plain: plain.due }),
|
|
760
799
|
};
|
|
761
800
|
});
|
|
762
801
|
}
|
|
@@ -1112,7 +1151,7 @@ export class ClaudeCodeAdapter {
|
|
|
1112
1151
|
const text = writeUpPointer({
|
|
1113
1152
|
waiting: owed.length,
|
|
1114
1153
|
ended: held.session,
|
|
1115
|
-
endedOn: calendarDate(held.clockFrom),
|
|
1154
|
+
endedOn: calendarDate(held.clockFrom, this.counterpart.store.zone()),
|
|
1116
1155
|
bytes: cut.slice(done).reduce((n, p) => n + Buffer.byteLength(p, "utf8"), 0),
|
|
1117
1156
|
part: Math.min(done + 1, partsCount),
|
|
1118
1157
|
of: partsCount,
|
|
@@ -1198,9 +1237,14 @@ export class ClaudeCodeAdapter {
|
|
|
1198
1237
|
return { ...out, ok: true, reason: "primacy-standdown" };
|
|
1199
1238
|
}
|
|
1200
1239
|
this.checkWakeArrival(input);
|
|
1240
|
+
// A plain reminder whose day began while this session was already open —
|
|
1241
|
+
// the session that runs past midnight — or that SessionStart had no room
|
|
1242
|
+
// for, is said at the next prompt, once (claimed at delivery).
|
|
1243
|
+
const plain = this.plainFor(input);
|
|
1244
|
+
const told = plain.due.length === 0 ? {} : { notices: plain.notices, plain: plain.due };
|
|
1201
1245
|
const text = input.prompt ?? "";
|
|
1202
1246
|
if (text.trim().length === 0) {
|
|
1203
|
-
return { ...out, ok: true, reason: "empty-prompt" };
|
|
1247
|
+
return { ...out, ok: true, reason: "empty-prompt", injection: `${this.nowLine()}${plain.context.length === 0 ? "" : `\n${plain.context.trimEnd()}`}`, ...told };
|
|
1204
1248
|
}
|
|
1205
1249
|
const result = this.counterpart.recallForTurn(
|
|
1206
1250
|
{
|
|
@@ -1210,7 +1254,11 @@ export class ClaudeCodeAdapter {
|
|
|
1210
1254
|
? {}
|
|
1211
1255
|
: { budgetBytes: this.config.injectionBudgetBytes }),
|
|
1212
1256
|
},
|
|
1213
|
-
{
|
|
1257
|
+
{
|
|
1258
|
+
...(input.at === undefined ? {} : { at: input.at }),
|
|
1259
|
+
// Said outright this turn, so not ALSO handed over as a quiet cue.
|
|
1260
|
+
...(plain.due.length === 0 ? {} : { withhold: new Set(plain.due.map((r) => r.memoryId)) }),
|
|
1261
|
+
},
|
|
1214
1262
|
);
|
|
1215
1263
|
const decision = result.decision;
|
|
1216
1264
|
// The recall block states its own sentinel too, and nothing checks it: the
|
|
@@ -1236,17 +1284,83 @@ export class ClaudeCodeAdapter {
|
|
|
1236
1284
|
...out,
|
|
1237
1285
|
ok: true,
|
|
1238
1286
|
reason: decision.reason,
|
|
1239
|
-
|
|
1287
|
+
// The current local time, EVERY turn (docs/time.md rule 5; the owner
|
|
1288
|
+
// asked for it on quiet turns too, 2026-09-25 — ~40 bytes), because a
|
|
1289
|
+
// session can run for hours. One line ABOVE the recall note when there
|
|
1290
|
+
// is one, outside it like the wake's, so the note's byte count and
|
|
1291
|
+
// sentinel stand; alone when recall surfaced nothing.
|
|
1292
|
+
injection:
|
|
1293
|
+
result.injection.length === 0
|
|
1294
|
+
? `${this.nowLine()}${plain.context.length === 0 ? "" : `\n${plain.context.trimEnd()}`}`
|
|
1295
|
+
: `${this.nowLine()}\n${plain.context}${result.injection}`,
|
|
1240
1296
|
bytes: decision.bytes,
|
|
1241
1297
|
sentinel: decision.sentinel,
|
|
1242
1298
|
// The footnote tier is carried SEPARATELY from the loud one, because the
|
|
1243
1299
|
// two mean different things to reinforcement: a footnote trains nothing.
|
|
1244
1300
|
surfaced: decision.surfaced,
|
|
1245
1301
|
footnotes: decision.footnotes,
|
|
1302
|
+
...told,
|
|
1246
1303
|
};
|
|
1247
1304
|
});
|
|
1248
1305
|
}
|
|
1249
1306
|
|
|
1307
|
+
/** `Now: Fri 25 Sep 2026, 1:40 pm MDT` — this adapter's clock, in the store's zone. */
|
|
1308
|
+
private nowLine(): string {
|
|
1309
|
+
return `Now: ${localClock(this.nowFn(), this.counterpart.store.zone())}`;
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
/**
|
|
1313
|
+
* PLAIN REMINDERS, in words (owner decision 2026-09-25/26): "Today: pay your
|
|
1314
|
+
* taxes". Two renderings of each, from the same record —
|
|
1315
|
+
*
|
|
1316
|
+
* - `notices`, for the PERSON, bare: the host shows them as the hook's
|
|
1317
|
+
* `systemMessage` in the terminal (`bin/hook.ts#hostDelivery`);
|
|
1318
|
+
* - `context`, for the MODEL, one line each ending in a newline, saying it
|
|
1319
|
+
* was asked for and naming the memory, so it can raise it and look it up.
|
|
1320
|
+
*
|
|
1321
|
+
* A READ (2026-09-26 review): nothing is claimed here. The delivery claims
|
|
1322
|
+
* what its envelope will certainly carry (`claimPlain`, from
|
|
1323
|
+
* `bin/hook.ts#deliverTurn`) and strips the rest, so a beat is never spent
|
|
1324
|
+
* on a line the person did not get. No date (`input.at` absent) means no
|
|
1325
|
+
* calendar, and so nothing; the host-mode page writer's headless child is
|
|
1326
|
+
* told nothing (`HookInput.pageWriter`). Never throws.
|
|
1327
|
+
*/
|
|
1328
|
+
private plainFor(input: HookInput): { context: string; notices: string[]; due: PlainReminder[] } {
|
|
1329
|
+
const none = { context: "", notices: [], due: [] };
|
|
1330
|
+
if (input.at === undefined || input.pageWriter === true) return none;
|
|
1331
|
+
try {
|
|
1332
|
+
const due = this.counterpart.plainDueToday({ at: input.at });
|
|
1333
|
+
return {
|
|
1334
|
+
context: due.map((r) => `${plainContextLine(r)}\n`).join(""),
|
|
1335
|
+
notices: due.map(plainLine),
|
|
1336
|
+
due,
|
|
1337
|
+
};
|
|
1338
|
+
} catch {
|
|
1339
|
+
return none;
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
/**
|
|
1344
|
+
* CLAIM plain reminders the delivery is certainly about to show — the latch
|
|
1345
|
+
* (`Counterpart.claimPlainReminder`) decides, so of two processes racing for
|
|
1346
|
+
* one beat exactly one gets it back. Returns the ones this call claimed, in
|
|
1347
|
+
* order; the caller shows only those. Never throws.
|
|
1348
|
+
*/
|
|
1349
|
+
claimPlain(input: HookInput, due: readonly PlainReminder[]): PlainReminder[] {
|
|
1350
|
+
if (input.at === undefined || due.length === 0) return [];
|
|
1351
|
+
const at = input.at;
|
|
1352
|
+
const claimed = due.filter((r) => {
|
|
1353
|
+
try {
|
|
1354
|
+
return this.counterpart.claimPlainReminder(r, { at });
|
|
1355
|
+
} catch {
|
|
1356
|
+
return false;
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
1359
|
+
if (claimed.length > 0) this.emit("adapter.plain.told", { count: claimed.length });
|
|
1360
|
+
if (claimed.length < due.length) this.emit("adapter.plain.lost", { count: due.length - claimed.length });
|
|
1361
|
+
return claimed;
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1250
1364
|
/**
|
|
1251
1365
|
* "COUNTERPARTS WAS UPDATED" — the line this session's terminal gets, once,
|
|
1252
1366
|
* when the MCP server it is talking to runs an older build than the one
|
|
@@ -2118,7 +2232,7 @@ export class ClaudeCodeAdapter {
|
|
|
2118
2232
|
*/
|
|
2119
2233
|
private noteSpawnStart(input?: HookInput): void {
|
|
2120
2234
|
if (this.observer) return;
|
|
2121
|
-
const date = input?.at ??
|
|
2235
|
+
const date = input?.at ?? localDate(this.nowFn(), this.counterpart.store.zone());
|
|
2122
2236
|
try {
|
|
2123
2237
|
this.bumpStart(date);
|
|
2124
2238
|
this.counterpart.noteAdapterEvent(
|
|
@@ -2254,7 +2368,7 @@ export class ClaudeCodeAdapter {
|
|
|
2254
2368
|
): string | null {
|
|
2255
2369
|
if (this.observer) return null;
|
|
2256
2370
|
try {
|
|
2257
|
-
const today = input.at ??
|
|
2371
|
+
const today = input.at ?? localDate(this.nowFn(), this.counterpart.store.zone());
|
|
2258
2372
|
// WHICH CODE IS LIVE, read before anything else and RECORDED. The reading
|
|
2259
2373
|
// is bounded and never throws (`readCheckout`); the row is the mechanized
|
|
2260
2374
|
// half — a day on master leaves one latched row, and a day the tree
|
|
@@ -2527,6 +2641,63 @@ export function wakeOutcome(expected: string | null, arrival: WakeArrival): Wake
|
|
|
2527
2641
|
return "truncated";
|
|
2528
2642
|
}
|
|
2529
2643
|
|
|
2644
|
+
/**
|
|
2645
|
+
* ONE PLAIN REMINDER, AS A PERSON READS IT (2026-09-26). The owner's example is
|
|
2646
|
+
* the whole spec — "Today: pay your taxes" — so each beat is the shortest
|
|
2647
|
+
* sentence that says when:
|
|
2648
|
+
*
|
|
2649
|
+
* day `Today: pay your taxes`
|
|
2650
|
+
* opens `This month: launch the beta` / `Until Sat 31 Oct 2026: book flights`
|
|
2651
|
+
* last-day `Last day today: file the extension`
|
|
2652
|
+
*
|
|
2653
|
+
* `what` is the memory's title or first line (`Counterpart.plainReminders`).
|
|
2654
|
+
*/
|
|
2655
|
+
export function plainLine(r: Pick<PlainReminder, "beat" | "precision" | "lastDay" | "what">): string {
|
|
2656
|
+
const max = TUNABLES.PLAIN_WHAT_MAX_CHARS;
|
|
2657
|
+
const what = r.what.length <= max ? r.what : `${r.what.slice(0, max - 1).trimEnd()}…`;
|
|
2658
|
+
if (r.beat === "day") return `Today: ${what}`;
|
|
2659
|
+
if (r.beat === "last-day") return `Last day today: ${what}`;
|
|
2660
|
+
if (r.precision === "month") return `This month: ${what}`;
|
|
2661
|
+
return `Until ${readableDate(r.lastDay)}: ${what}`;
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
/**
|
|
2665
|
+
* The MODEL's copy of one plain reminder: says it was asked for, and names the
|
|
2666
|
+
* memory so it can be looked up. One line, no newline — `what` is folded to
|
|
2667
|
+
* single spaces upstream — so `withoutPlain` can take it back out by line.
|
|
2668
|
+
*/
|
|
2669
|
+
export function plainContextLine(r: Pick<PlainReminder, "beat" | "precision" | "lastDay" | "what" | "memoryId">): string {
|
|
2670
|
+
return `Plain reminder (they asked to be told) — ${plainLine(r)} [${r.memoryId}]`;
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
/**
|
|
2674
|
+
* A hook result WITHOUT the given plain reminders — their terminal lines, their
|
|
2675
|
+
* records and their context lines — for a delivery that could not carry them or
|
|
2676
|
+
* lost the race to claim them (`bin/hook.ts#deliverTurn`). They are not spent:
|
|
2677
|
+
* the next prompt reads them again. Everything else is untouched.
|
|
2678
|
+
*/
|
|
2679
|
+
export function withoutPlain<R extends { injection: string | null; notices?: readonly string[]; plain?: readonly PlainReminder[] }>(
|
|
2680
|
+
result: R,
|
|
2681
|
+
drop: readonly PlainReminder[],
|
|
2682
|
+
): R {
|
|
2683
|
+
if (drop.length === 0) return result;
|
|
2684
|
+
const keyOf = (r: PlainReminder): string => `${r.memoryId} ${r.windowKey} ${r.beat}`;
|
|
2685
|
+
const gone = new Set(drop.map(keyOf));
|
|
2686
|
+
const lines = new Set(drop.map(plainContextLine));
|
|
2687
|
+
const plain = (result.plain ?? []).filter((r) => !gone.has(keyOf(r)));
|
|
2688
|
+
const injection =
|
|
2689
|
+
result.injection === null
|
|
2690
|
+
? null
|
|
2691
|
+
: result.injection
|
|
2692
|
+
.split("\n")
|
|
2693
|
+
.filter((l) => !lines.has(l))
|
|
2694
|
+
.join("\n");
|
|
2695
|
+
const rest: R = { ...result, injection };
|
|
2696
|
+
delete (rest as { notices?: unknown }).notices;
|
|
2697
|
+
delete (rest as { plain?: unknown }).plain;
|
|
2698
|
+
return plain.length === 0 ? rest : { ...rest, notices: plain.map(plainLine), plain };
|
|
2699
|
+
}
|
|
2700
|
+
|
|
2530
2701
|
function codeOf(err: unknown): string {
|
|
2531
2702
|
if (err !== null && typeof err === "object") {
|
|
2532
2703
|
const code = (err as { code?: unknown }).code;
|
|
@@ -59,8 +59,11 @@ export {
|
|
|
59
59
|
SPAWN_REFUSAL_PREFIX,
|
|
60
60
|
SPAWN_START_COUNT_KEY,
|
|
61
61
|
SPAWN_START_DATE_KEY,
|
|
62
|
+
plainContextLine,
|
|
63
|
+
plainLine,
|
|
62
64
|
substanceOf,
|
|
63
65
|
wakeOutcome,
|
|
66
|
+
withoutPlain,
|
|
64
67
|
} from "./hooks.js";
|
|
65
68
|
export type {
|
|
66
69
|
AdapterEvent,
|
|
@@ -165,6 +168,7 @@ export function openAdapter(
|
|
|
165
168
|
: { budgetBytes: config.injectionBudgetBytes }),
|
|
166
169
|
...(config.observer === undefined ? {} : { observer: config.observer }),
|
|
167
170
|
...(config.owner === undefined ? {} : { owner: config.owner }),
|
|
171
|
+
...(config.timeZone === undefined ? {} : { timeZone: config.timeZone }),
|
|
168
172
|
...(config.identity === undefined
|
|
169
173
|
? {}
|
|
170
174
|
: { identity: { name: config.identity.name, aliases: [...(config.identity.aliases ?? [])] } }),
|