counterparts 0.3.7 → 0.3.8
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 +142 -0
- package/docs/module-map.md +4 -1
- package/package.json +1 -1
- package/src/adapters/claude-code/CONTRACT.md +73 -52
- package/src/adapters/claude-code/INTERFACE-GAPS.md +8 -3
- package/src/adapters/claude-code/NOTES.md +119 -0
- package/src/adapters/claude-code/bin/hook.ts +95 -33
- package/src/adapters/claude-code/bin/nightly.ts +21 -2
- package/src/adapters/claude-code/bin/runner.ts +55 -44
- package/src/adapters/claude-code/child.ts +203 -0
- package/src/adapters/claude-code/config.ts +66 -69
- package/src/adapters/claude-code/doctor.ts +249 -68
- package/src/adapters/claude-code/envelope.ts +38 -0
- package/src/adapters/claude-code/hooks.ts +206 -42
- package/src/adapters/claude-code/index.ts +7 -20
- package/src/adapters/claude-code/night-run.ts +19 -8
- package/src/adapters/cli/CONTRACT.md +9 -0
- package/src/adapters/cli/commands.ts +282 -4
- package/src/adapters/cli/coverage.ts +100 -0
- package/src/adapters/cli/dream-core.ts +11 -0
- package/src/adapters/cli/help.ts +6 -0
- package/src/adapters/cli/mechanisms.ts +23 -6
- package/src/adapters/cli/self-page.ts +4 -4
- package/src/adapters/cli/settle.ts +63 -0
- package/src/adapters/dashboard/registries.ts +29 -1
- package/src/adapters/dashboard/web/README.md +41 -11
- package/src/adapters/dashboard/web/flow.ts +12 -0
- package/src/adapters/dashboard/web/lanes.ts +11 -0
- package/src/adapters/dashboard/web/mechanisms/dreaming/panel.js +2 -1
- package/src/adapters/dashboard/web/mechanisms/emotional/panel.js +2 -2
- package/src/adapters/dashboard/web/mechanisms/episodic-semantic/panel.js +2 -1
- package/src/adapters/dashboard/web/mechanisms/index.js +2 -0
- package/src/adapters/dashboard/web/mechanisms/interference/index.js +8 -4
- package/src/adapters/dashboard/web/mechanisms/interference/panel.js +13 -0
- package/src/adapters/dashboard/web/mechanisms/prospective/panel.js +2 -1
- package/src/adapters/dashboard/web/narrate.ts +62 -4
- package/src/adapters/dashboard/web/pages/health/sections/cycle.js +2 -4
- package/src/adapters/dashboard/web/pages/memories/index.js +6 -1
- package/src/adapters/dashboard/web/pages/memories/memories.css +43 -26
- package/src/adapters/dashboard/web/pages/memories/row.js +52 -15
- package/src/adapters/dashboard/web/pages/memories/sections/hold.js +112 -24
- package/src/adapters/dashboard/web/pages/memories/sections/list.js +3 -3
- package/src/adapters/dashboard/web/pages/memories/sections/search.js +75 -15
- package/src/adapters/dashboard/web/pages/memories/state.js +3 -2
- package/src/adapters/dashboard/web/pages/self/sections/dreams.js +2 -2
- package/src/adapters/dashboard/web/pages/self/sections/journal.js +7 -11
- package/src/adapters/dashboard/web/pages/self/sections/page.js +47 -17
- package/src/adapters/dashboard/web/pages/self/sections/wake.js +16 -5
- package/src/adapters/dashboard/web/shared/dates.js +55 -0
- package/src/adapters/dashboard/web/shared/memory-marks.css +1 -0
- package/src/adapters/dashboard/web/shared/memory-marks.js +23 -12
- package/src/adapters/dashboard/web/shared/memory-modal.js +15 -11
- package/src/adapters/dashboard/web/shared/widgets/feel-radar.js +8 -5
- package/src/adapters/dashboard/web/views/mechanism-panel.ts +39 -0
- package/src/adapters/dashboard/web/views/mechanisms.ts +9 -1
- package/src/adapters/dashboard/web/views/mind.ts +57 -17
- package/src/adapters/dashboard/web/views/search.ts +170 -58
- package/src/adapters/fired.ts +28 -0
- package/src/adapters/log/CONTRACT.md +70 -0
- package/src/adapters/log/INTERFACE-GAPS.md +15 -0
- package/src/adapters/log/NOTES.md +49 -0
- package/src/adapters/log/index.ts +420 -0
- package/src/adapters/mcp/CONTRACT.md +11 -0
- package/src/adapters/mcp/INTERFACE-GAPS.md +8 -0
- package/src/adapters/mcp/NOTES.md +34 -0
- package/src/adapters/mcp/bin/serve.ts +23 -1
- package/src/adapters/mcp/deliberate.ts +39 -2
- package/src/adapters/mcp/index.ts +5 -2
- package/src/adapters/mcp/server.ts +181 -43
- package/src/adapters/mcp/tools.ts +78 -11
- package/src/adapters/mcp/write-up.ts +5 -9
- package/src/adapters/mechanism-evidence.ts +28 -9
- package/src/adapters/sessions.ts +158 -172
- package/src/core/contradictions.ts +607 -0
- package/src/core/counterpart.ts +273 -26
- package/src/core/coverage/CONTRACT.md +77 -0
- package/src/core/coverage/INTERFACE-GAPS.md +46 -0
- package/src/core/coverage/NOTES.md +100 -0
- package/src/core/coverage/index.ts +660 -0
- package/src/core/coverage/tunables.ts +29 -0
- package/src/core/dream/CONTRACT.md +14 -8
- package/src/core/dream/INTERFACE-GAPS.md +6 -0
- package/src/core/dream/NOTES.md +27 -0
- package/src/core/dream/index.ts +90 -29
- package/src/core/dream/mind.ts +14 -13
- package/src/core/dream/reflect.ts +29 -0
- package/src/core/dream/tunables.ts +3 -0
- package/src/core/handoff/CONTRACT.md +8 -2
- package/src/core/handoff/NOTES.md +2 -0
- package/src/core/handoff/index.ts +100 -14
- package/src/core/physics/CONTRACT.md +23 -1
- package/src/core/physics/NOTES.md +10 -0
- package/src/core/physics/index.ts +78 -1
- package/src/core/prospective/CONTRACT.md +4 -1
- package/src/core/prospective/NOTES.md +16 -1
- package/src/core/prospective/index.ts +21 -2
- package/src/core/recall/CONTRACT.md +10 -0
- package/src/core/recall/INTERFACE-GAPS.md +7 -0
- package/src/core/recall/NOTES.md +11 -0
- package/src/core/recall/index.ts +20 -1
- package/src/core/recall/render.ts +15 -3
- package/src/core/recall/standing.ts +124 -0
- package/src/core/remember/CONTRACT.md +8 -8
- package/src/core/remember/NOTES.md +41 -0
- package/src/core/remember/index.ts +2 -5
- package/src/core/remember/owes.ts +80 -217
- package/src/core/remember/proposals.ts +31 -2
- package/src/core/revision.ts +60 -3
- package/src/core/schemas/CONTRACT.md +6 -3
- package/src/core/schemas/NOTES.md +15 -0
- package/src/core/self/CONTRACT.md +28 -13
- package/src/core/self/NOTES.md +86 -0
- package/src/core/self/behind.ts +89 -0
- package/src/core/self/briefing.ts +136 -5
- package/src/core/self/episodes.ts +43 -48
- package/src/core/self/identity.ts +42 -6
- package/src/core/self/index.ts +20 -2
- package/src/core/self/writer.ts +26 -26
- package/src/core/store/CONTRACT.md +12 -0
- package/src/core/store/NOTES.md +52 -0
- package/src/core/store/errors.ts +6 -0
- package/src/core/store/index.ts +339 -0
- package/src/core/store/operational.ts +248 -3
- package/src/core/store/owner-op-seam.ts +65 -1
- package/src/core/time.ts +60 -3
- package/src/core/types.ts +25 -0
- package/src/adapters/claude-code/page-writer.ts +0 -516
|
@@ -108,8 +108,11 @@ import { heldExits } from "../../core/store/index.js";
|
|
|
108
108
|
// promise a different number from the job that does the deleting. READ-ONLY:
|
|
109
109
|
// `remember/index.ts` re-exports the plan and the readers, never the deleter.
|
|
110
110
|
import { SpanBuffer, TUNABLES as REMEMBER_TUNABLES, lastRetentionRun } from "../../core/remember/index.js";
|
|
111
|
+
import { lapsesSince, ledger } from "../../core/coverage/index.js";
|
|
112
|
+
import type { LedgerEntry } from "../../core/coverage/index.js";
|
|
111
113
|
import {
|
|
112
|
-
|
|
114
|
+
hostSessionEvidence,
|
|
115
|
+
pointable,
|
|
113
116
|
progressKey,
|
|
114
117
|
readWriteUpPointer,
|
|
115
118
|
readWriteUpProgress,
|
|
@@ -121,6 +124,7 @@ import type { AdapterConfig } from "./config.js";
|
|
|
121
124
|
// The same vocabulary the hook's stand-down uses, so the terminal and the
|
|
122
125
|
// console cannot end up with two answers to "why did it not open".
|
|
123
126
|
import { describeFault, faultId, faultPath } from "./standdown.js";
|
|
127
|
+
import { LOG_DAYS, logReading } from "../log/index.js";
|
|
124
128
|
|
|
125
129
|
/** Worst first. The order of this array IS the report's order. */
|
|
126
130
|
export const SEVERITIES = ["red", "amber", "green"] as const;
|
|
@@ -1556,9 +1560,9 @@ function rowFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
1556
1560
|
* session wrote itself, against those the fallback sweep wrote for it.
|
|
1557
1561
|
*
|
|
1558
1562
|
* GREEN, with counts: cap refusals and the sweep's share are not losses, and
|
|
1559
|
-
* the one loss it could name — a session that owes a write-up
|
|
1560
|
-
*
|
|
1561
|
-
*
|
|
1563
|
+
* the one loss it could name — a session that owes a write-up
|
|
1564
|
+
* (`core/coverage/`) from yesterday or earlier — is the `Write-ups` line's
|
|
1565
|
+
* amber. This line carries that count as detail, or says "unknown"
|
|
1562
1566
|
* when it could not be read. The session-start reading does not read the owed
|
|
1563
1567
|
* sessions (it walks every scope's words), so there the line omits them.
|
|
1564
1568
|
*
|
|
@@ -1797,7 +1801,7 @@ function authorshipFindings(input: DoctorInput, store: Store, owedReading: OwedS
|
|
|
1797
1801
|
: owed.waiting === 0
|
|
1798
1802
|
? ""
|
|
1799
1803
|
: `; ${plural(owed.waiting, "session", "sessions")} awaiting a write-up` +
|
|
1800
|
-
(owed.stale === 0 ? "" : `, ${String(owed.stale)}
|
|
1804
|
+
(owed.stale === 0 ? "" : `, ${String(owed.stale)} from yesterday or earlier`);
|
|
1801
1805
|
const detail =
|
|
1802
1806
|
`${windowPhrase(shown, input.today)}: invited to write ${plural(asked, "time", "times")}, ` +
|
|
1803
1807
|
`${plural(paced, "Stop", "Stops")} paced out, ${String(capped)} over the day's allowance` +
|
|
@@ -1829,8 +1833,8 @@ function authorshipFindings(input: DoctorInput, store: Store, owedReading: OwedS
|
|
|
1829
1833
|
livedDay,
|
|
1830
1834
|
};
|
|
1831
1835
|
// Green, always: a session waiting too long for its write-up is the one
|
|
1832
|
-
// loss this line could name, and the
|
|
1833
|
-
//
|
|
1836
|
+
// loss this line could name, and the Write-ups line already turns amber on
|
|
1837
|
+
// it — one loss, one amber line.
|
|
1834
1838
|
return [finding("authorship", "green", "Authorship", detail, "", data)];
|
|
1835
1839
|
}
|
|
1836
1840
|
|
|
@@ -2328,6 +2332,29 @@ export function journalCopyFindings(store: Store): Finding[] {
|
|
|
2328
2332
|
];
|
|
2329
2333
|
}
|
|
2330
2334
|
|
|
2335
|
+
/**
|
|
2336
|
+
* THE PROCESS LOG (`adapters/log/`, 2026-09-30) — where it is, how many days it
|
|
2337
|
+
* holds, and how many failures it recorded today. Green whatever the count: the
|
|
2338
|
+
* failures are each some other line's to grade, and this one says where to read
|
|
2339
|
+
* them (`counterparts log`). Folds into `Background` like the other greens.
|
|
2340
|
+
*/
|
|
2341
|
+
export function logFindings(input: DoctorInput): Finding[] {
|
|
2342
|
+
const r = logReading(input.dir, input.today);
|
|
2343
|
+
const failures = `${String(r.failuresToday)} failure${r.failuresToday === 1 ? "" : "s"} today`;
|
|
2344
|
+
const detail =
|
|
2345
|
+
r.days === 0
|
|
2346
|
+
? `${tilde(r.dir)} · nothing written yet`
|
|
2347
|
+
: `${tilde(r.dir)} · holds ${String(r.days)} day${r.days === 1 ? "" : "s"} (kept ${String(LOG_DAYS)}) · ${failures}`;
|
|
2348
|
+
return [
|
|
2349
|
+
finding("log", "green", "Log", detail, r.failuresToday > 0 ? "Read them: counterparts log" : "", {
|
|
2350
|
+
dir: r.dir,
|
|
2351
|
+
days: r.days,
|
|
2352
|
+
failuresToday: r.failuresToday,
|
|
2353
|
+
linesToday: r.linesToday,
|
|
2354
|
+
}),
|
|
2355
|
+
];
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2331
2358
|
/**
|
|
2332
2359
|
* THE SELF PAGE (2026-09-18, S1) — one line: is there one, how big, how old.
|
|
2333
2360
|
*
|
|
@@ -2492,6 +2519,107 @@ export function upgradeV9Findings(store: Store): Finding[] {
|
|
|
2492
2519
|
];
|
|
2493
2520
|
}
|
|
2494
2521
|
|
|
2522
|
+
/** The meta row the v10 upgrade writes (`store/operational.ts#V10_UPGRADE_KEY`). */
|
|
2523
|
+
const V10_UPGRADE_META = "contradictions.v10.upgrade";
|
|
2524
|
+
|
|
2525
|
+
/**
|
|
2526
|
+
* WHAT THE v10 UPGRADE CARRIED (2026-09-29, contradictions), informational:
|
|
2527
|
+
* every dream flag that stood became an unsettled pair, raised and habituated
|
|
2528
|
+
* as it was. Silent on a store born at v10.
|
|
2529
|
+
*/
|
|
2530
|
+
export function upgradeV10Findings(store: Store): Finding[] {
|
|
2531
|
+
const upgrade = metaJson(store, V10_UPGRADE_META);
|
|
2532
|
+
if (upgrade === null) return [];
|
|
2533
|
+
const flags = metaNum(upgrade["flags"]);
|
|
2534
|
+
const pairs = metaNum(upgrade["pairs"]);
|
|
2535
|
+
const raised = metaNum(upgrade["raised"]);
|
|
2536
|
+
const standing = metaNum(upgrade["standing"]);
|
|
2537
|
+
return [
|
|
2538
|
+
finding(
|
|
2539
|
+
"upgrade-v10",
|
|
2540
|
+
"green",
|
|
2541
|
+
"Upgrade",
|
|
2542
|
+
`Upgrade to v10: a contradiction is a pair now, settled changed, corrected or open, with its record — ${String(flags)} dream ${flags === 1 ? "flag" : "flags"} carried as ${String(pairs)} unsettled ${pairs === 1 ? "pair" : "pairs"} (${String(raised)} already raised awake, ${String(standing)} with both memories still standing)`,
|
|
2543
|
+
"",
|
|
2544
|
+
{ flags, pairs, raised, standing },
|
|
2545
|
+
),
|
|
2546
|
+
];
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
/** The lived days the Contradictions line covers. */
|
|
2550
|
+
export const CONTRADICTION_WINDOW_DAYS = 7;
|
|
2551
|
+
|
|
2552
|
+
/**
|
|
2553
|
+
* CONTRADICTIONS, informational (2026-09-29): over the last
|
|
2554
|
+
* `CONTRADICTION_WINDOW_DAYS` lived days, how many pairs were flagged, how
|
|
2555
|
+
* many settled and how (changed, corrected, open), how many undone, and who
|
|
2556
|
+
* settled them; and, standing now, how many are open and how many unsettled
|
|
2557
|
+
* (both memories still live). Read off `contradictions` and its trail — ids
|
|
2558
|
+
* and counts only.
|
|
2559
|
+
*/
|
|
2560
|
+
export function contradictionFindings(store: Store): Finding[] {
|
|
2561
|
+
let pairs: ReturnType<Store["contradictions"]>;
|
|
2562
|
+
let trail: ReturnType<Store["contradictionSettles"]>;
|
|
2563
|
+
let today: number;
|
|
2564
|
+
try {
|
|
2565
|
+
pairs = store.contradictions({ limit: 100_000 });
|
|
2566
|
+
trail = store.contradictionSettles({ limit: 100_000 });
|
|
2567
|
+
today = store.livedDay();
|
|
2568
|
+
} catch {
|
|
2569
|
+
return [];
|
|
2570
|
+
}
|
|
2571
|
+
const since = today - CONTRADICTION_WINDOW_DAYS + 1;
|
|
2572
|
+
const flagged = pairs.filter((p) => (p.source === "dream" || p.source === "pressure") && p.flagged_day >= since).length;
|
|
2573
|
+
const settles = trail.filter((s) => s.action === "settle" && s.day >= since);
|
|
2574
|
+
const kept = settles.filter((s) => s.undone === 0);
|
|
2575
|
+
const by = (list: readonly { how?: string | null; actor?: string }[], key: "how" | "actor"): Record<string, number> => {
|
|
2576
|
+
const out: Record<string, number> = {};
|
|
2577
|
+
for (const x of list) {
|
|
2578
|
+
const k = String(x[key] ?? "?");
|
|
2579
|
+
out[k] = (out[k] ?? 0) + 1;
|
|
2580
|
+
}
|
|
2581
|
+
return out;
|
|
2582
|
+
};
|
|
2583
|
+
const how = by(kept, "how");
|
|
2584
|
+
const who = by(kept, "actor");
|
|
2585
|
+
const undone = trail.filter((s) => s.action === "undo" && s.day >= since).length;
|
|
2586
|
+
const live = (id: string): boolean => {
|
|
2587
|
+
const r = store.row(id);
|
|
2588
|
+
return r !== undefined && r.archived === 0 && r.superseded_by === null && r.body !== "";
|
|
2589
|
+
};
|
|
2590
|
+
const open = pairs.filter((p) => p.state === "settled" && p.how === "open" && p.via === null).length;
|
|
2591
|
+
const unsettled = pairs.filter((p) => p.state === "unsettled" && live(p.a) && live(p.b)).length;
|
|
2592
|
+
const kinds = ["changed", "corrected", "open"].map((k) => `${String(how[k] ?? 0)} ${k}`).join(", ");
|
|
2593
|
+
const whoWords = Object.entries(who)
|
|
2594
|
+
.sort((a, b) => b[1] - a[1])
|
|
2595
|
+
.map(([k, n]) => `${k === "owner" ? "you" : k} ${String(n)}`)
|
|
2596
|
+
.join(", ");
|
|
2597
|
+
return [
|
|
2598
|
+
finding(
|
|
2599
|
+
"contradictions",
|
|
2600
|
+
"green",
|
|
2601
|
+
"Contradictions",
|
|
2602
|
+
`last ${String(CONTRADICTION_WINDOW_DAYS)} lived days: ${String(flagged)} flagged, ${String(kept.length)} settled (${kinds})${kept.length > 0 ? ` by ${whoWords}` : ""}${undone > 0 ? `, ${String(undone)} undone` : ""}; standing: ${String(open)} open, ${String(unsettled)} unsettled${unsettled > 0 ? " (counterparts settle lists them)" : ""}`,
|
|
2603
|
+
"",
|
|
2604
|
+
{
|
|
2605
|
+
flagged,
|
|
2606
|
+
settled: kept.length,
|
|
2607
|
+
changed: how["changed"] ?? 0,
|
|
2608
|
+
corrected: how["corrected"] ?? 0,
|
|
2609
|
+
open: how["open"] ?? 0,
|
|
2610
|
+
undone,
|
|
2611
|
+
bySession: who["session"] ?? 0,
|
|
2612
|
+
byDream: who["dream"] ?? 0,
|
|
2613
|
+
byReflection: who["reflection"] ?? 0,
|
|
2614
|
+
byPageWriter: who["page-writer"] ?? 0,
|
|
2615
|
+
byOwner: who["owner"] ?? 0,
|
|
2616
|
+
standingOpen: open,
|
|
2617
|
+
standingUnsettled: unsettled,
|
|
2618
|
+
},
|
|
2619
|
+
),
|
|
2620
|
+
];
|
|
2621
|
+
}
|
|
2622
|
+
|
|
2495
2623
|
/** How many `band.promoted` rows the reflection finding reads, newest first. */
|
|
2496
2624
|
export const PROMOTED_ROWS = 5000;
|
|
2497
2625
|
|
|
@@ -3023,7 +3151,7 @@ export function pageWriterFindings(store: Store, config: AdapterConfig): Finding
|
|
|
3023
3151
|
const mode = pageWriterMode(config);
|
|
3024
3152
|
// THE MECHANISM'S OWN NIGHT, not one this line derives (PR #189 review, M2):
|
|
3025
3153
|
// the local calendar day, held back east of UTC to a provenance date that has
|
|
3026
|
-
// closed — the one function `Self`,
|
|
3154
|
+
// closed — the one function `Self`, the nightly run and this line all read, so the
|
|
3027
3155
|
// claim's local `on` is never compared with a UTC `today`.
|
|
3028
3156
|
const { today, about } = pageWriterNight(store);
|
|
3029
3157
|
const last = lastPageWriterRun(store);
|
|
@@ -3081,9 +3209,7 @@ export function pageWriterFindings(store: Store, config: AdapterConfig): Finding
|
|
|
3081
3209
|
"Page writer",
|
|
3082
3210
|
young
|
|
3083
3211
|
? `${mode} mode; never run — this store has no day before ${today} yet`
|
|
3084
|
-
: mode === "
|
|
3085
|
-
? `${mode} mode; never run — it is the first part of the next nightly run, before the dream (${about})${dreamingSetting(store) === "off" ? "; dreaming is off, so the nightly run does not start" : ""}`
|
|
3086
|
-
: `${mode} mode; never run — the next boundary's worker starts it (${about})`,
|
|
3212
|
+
: `${mode} mode; never run — it is the first part of the next nightly run, before the dream (${about})${dreamingSetting(store) === "off" ? "; dreaming is off, so the nightly run does not start" : ""}`,
|
|
3087
3213
|
"",
|
|
3088
3214
|
{ ...data, young },
|
|
3089
3215
|
),
|
|
@@ -3111,8 +3237,8 @@ export function pageWriterFindings(store: Store, config: AdapterConfig): Finding
|
|
|
3111
3237
|
// state of a quiet week. It is amber only when nightly runs HAPPENED since
|
|
3112
3238
|
// (a dream dated after the writer's last row, before today) and the writer
|
|
3113
3239
|
// still left nothing: the run is going without it.
|
|
3114
|
-
const ranSince =
|
|
3115
|
-
const overdue = owed.due && staleFor > PAGE_WRITER_STALE_DAYS &&
|
|
3240
|
+
const ranSince = last.on !== "" ? dreamsBetween(store, last.on, today) : 0;
|
|
3241
|
+
const overdue = owed.due && staleFor > PAGE_WRITER_STALE_DAYS && ranSince > 0;
|
|
3116
3242
|
const bad = status.outcome === "failed" || status.outcome === "refused";
|
|
3117
3243
|
const detail =
|
|
3118
3244
|
`${mode} mode; ${when} — ${status.outcome}` +
|
|
@@ -3129,9 +3255,7 @@ export function pageWriterFindings(store: Store, config: AdapterConfig): Finding
|
|
|
3129
3255
|
"Page writer",
|
|
3130
3256
|
detail,
|
|
3131
3257
|
bad || overdue
|
|
3132
|
-
?
|
|
3133
|
-
? "counterparts mechanisms --all --dir <store> --observer shows the run's own row. The page writer is the first part of the nightly run, before the dream: counterparts dream shows whether the runs are happening and how each ended. counterparts self-page --write amends the page by hand meanwhile."
|
|
3134
|
-
: "counterparts mechanisms --all --dir <store> --observer shows the run's own row. In host mode the boundary's worker starts a windowless session for the writer; a night that is owed but never delivered usually means that session could not start. counterparts self-page --write amends the page by hand meanwhile."
|
|
3258
|
+
? "counterparts mechanisms --all --dir <store> --observer shows the run's own row. The page writer is the first part of the nightly run, before the dream: counterparts dream shows whether the runs are happening and how each ended. counterparts self-page --write amends the page by hand meanwhile."
|
|
3135
3259
|
: "",
|
|
3136
3260
|
{
|
|
3137
3261
|
...data,
|
|
@@ -3670,7 +3794,7 @@ export function doctorFindings(input: DoctorInput): Finding[] {
|
|
|
3670
3794
|
let owedCache: { value: OwedReading | "failed" } | null = null;
|
|
3671
3795
|
const owedReading: OwedSource = () => {
|
|
3672
3796
|
if (!owedAllowed) return null;
|
|
3673
|
-
owedCache ??= { value: readOwed(store) };
|
|
3797
|
+
owedCache ??= { value: readOwed(store, input.today) };
|
|
3674
3798
|
return owedCache.value;
|
|
3675
3799
|
};
|
|
3676
3800
|
const groups: (readonly [string, () => Finding[]])[] = [
|
|
@@ -3685,13 +3809,17 @@ export function doctorFindings(input: DoctorInput): Finding[] {
|
|
|
3685
3809
|
...(unread ? [] : [["snapshot", (): Finding[] => snapshotFindings(input, store)] as const]),
|
|
3686
3810
|
["self-page", () => selfPageFindings(store)],
|
|
3687
3811
|
["page-writer", () => pageWriterFindings(store, input.config)],
|
|
3688
|
-
// C2's one line. Not in the session-start
|
|
3689
|
-
// is all that notice prints, and it reads
|
|
3812
|
+
// C2's one line, `Write-ups` since 2026-09-30. Not in the session-start
|
|
3813
|
+
// reading: it is never red, which is all that notice prints, and it reads
|
|
3814
|
+
// every scope's captured words.
|
|
3690
3815
|
...(unread || input.budgetMs !== undefined
|
|
3691
3816
|
? []
|
|
3692
3817
|
: [["crash-write-up", (): Finding[] => crashWriteUpFindings(input, store, owedReading)] as const]),
|
|
3693
3818
|
// F6: silent unless a copy failure is standing. Two bounded event reads.
|
|
3694
3819
|
["journal-copy", () => journalCopyFindings(store)],
|
|
3820
|
+
// The process log (2026-09-30): one directory listing and today's file.
|
|
3821
|
+
// Not in the session-start reading: it is never red, and it reads a file.
|
|
3822
|
+
...(input.budgetMs !== undefined ? [] : [["log", (): Finding[] => logFindings(input)] as const]),
|
|
3695
3823
|
// B3's week: one bounded read of the newest `remember.prune` row. Folds into
|
|
3696
3824
|
// `Background` while green.
|
|
3697
3825
|
["retention", () => retentionFindings(input, store)],
|
|
@@ -3705,6 +3833,9 @@ export function doctorFindings(input: DoctorInput): Finding[] {
|
|
|
3705
3833
|
// v9 (2026-09-27): what the upgrade carried, and the reflection.
|
|
3706
3834
|
["upgrade-v9", () => upgradeV9Findings(store)],
|
|
3707
3835
|
["reflection", () => reflectionFindings(input, store)],
|
|
3836
|
+
// v10 (2026-09-29): what the upgrade carried, and the week's contradictions.
|
|
3837
|
+
["upgrade-v10", () => upgradeV10Findings(store)],
|
|
3838
|
+
["contradictions", () => contradictionFindings(store)],
|
|
3708
3839
|
// Build B (2026-09-28): does anyone read what an index offers in part?
|
|
3709
3840
|
["lookups", () => lookupFindings(store)],
|
|
3710
3841
|
// Association build 1 (2026-09-28): what spreading did, and the edges.
|
|
@@ -3741,54 +3872,55 @@ export function doctorFindings(input: DoctorInput): Finding[] {
|
|
|
3741
3872
|
|
|
3742
3873
|
// ── rendering ───────────────────────────────────────────────────────────────
|
|
3743
3874
|
|
|
3744
|
-
/** How
|
|
3745
|
-
export const
|
|
3875
|
+
/** How far back the line counts lapses, in days. */
|
|
3876
|
+
export const WRITE_UP_LAPSE_WINDOW_DAYS = 7;
|
|
3746
3877
|
|
|
3747
3878
|
/**
|
|
3748
|
-
*
|
|
3749
|
-
*
|
|
3750
|
-
*
|
|
3751
|
-
*
|
|
3752
|
-
*
|
|
3753
|
-
*
|
|
3754
|
-
*
|
|
3755
|
-
*
|
|
3756
|
-
*
|
|
3757
|
-
*
|
|
3758
|
-
*
|
|
3879
|
+
* WRITE-UPS (2026-09-30; before it, #192's `Crash write-up`, whose key it
|
|
3880
|
+
* keeps) — what is not written up, read off `core/coverage/`'s ledger.
|
|
3881
|
+
*
|
|
3882
|
+
* It says yesterday's state: how many sessions captured something that date
|
|
3883
|
+
* and how much of it is written up; how many sessions owe a write-up now; and
|
|
3884
|
+
* how many stretches lapsed in the last week. AMBER when a stretch from
|
|
3885
|
+
* yesterday or earlier is owed — the next session in that project is pointed
|
|
3886
|
+
* at it, so one still owed the morning after is one whose project nobody has
|
|
3887
|
+
* opened. Never red: nothing is deleted while a stretch is owed, and a lapse
|
|
3888
|
+
* deletes nothing either. The two ambers #192 added for the pointer itself —
|
|
3889
|
+
* deferred for room, and a session finished here waiting on another project —
|
|
3890
|
+
* are kept as they were.
|
|
3759
3891
|
*/
|
|
3760
|
-
/** The
|
|
3761
|
-
* `
|
|
3892
|
+
/** The ledger and the plan, read once per reading and shared by the
|
|
3893
|
+
* `Write-ups` and `Authorship` lines. */
|
|
3762
3894
|
interface OwedReading {
|
|
3763
3895
|
readonly spans: SpanBuffer;
|
|
3764
3896
|
readonly plan: ReturnType<typeof writeUpPlan>;
|
|
3897
|
+
readonly entries: readonly LedgerEntry[];
|
|
3765
3898
|
readonly now: number;
|
|
3766
|
-
/** Sessions
|
|
3899
|
+
/** Sessions that owe a write-up the pointer can offer (`coverage/`'s rule). */
|
|
3767
3900
|
readonly waiting: number;
|
|
3768
|
-
/** ...of which
|
|
3901
|
+
/** ...of which the stretch is from yesterday or earlier. */
|
|
3769
3902
|
readonly stale: number;
|
|
3903
|
+
/** Small debts the pointer never offers (no registry record, or not a
|
|
3904
|
+
* person's session): they owe, and lapse with their days of use. */
|
|
3905
|
+
readonly unpointed: number;
|
|
3770
3906
|
}
|
|
3771
3907
|
|
|
3772
3908
|
/** `failed` when it cannot be read. It reads every scope's captured words, so
|
|
3773
3909
|
* the budgeted session-start reading never calls it. */
|
|
3774
|
-
function readOwed(store: Store): OwedReading | "failed" {
|
|
3910
|
+
function readOwed(store: Store, today: string): OwedReading | "failed" {
|
|
3775
3911
|
try {
|
|
3776
3912
|
const now = store.now();
|
|
3777
3913
|
// READ-ONLY by construction: an observer buffer writes nothing, and it
|
|
3778
|
-
// is
|
|
3914
|
+
// is the ledger's own reader that opens the files.
|
|
3779
3915
|
const spans = new SpanBuffer({ dir: store.dir, observer: true, now: () => now });
|
|
3780
|
-
const plan = writeUpPlan({
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
}
|
|
3788
|
-
// The same eligibility the pointer uses.
|
|
3789
|
-
const owed = awaitingWriteUp(plan, store.dir, now);
|
|
3790
|
-
const stale = owed.filter((h) => now - h.clockFrom >= WRITE_UP_WAIT_DAYS * 86_400_000).length;
|
|
3791
|
-
return { spans, plan, now, waiting: owed.length, stale };
|
|
3916
|
+
const plan = writeUpPlan({ store, spans });
|
|
3917
|
+
const zone = store.zone();
|
|
3918
|
+
const host = hostSessionEvidence(store);
|
|
3919
|
+
const entries = ledger(spans, { now, zone, host: (s) => ({ endedAt: host(s).endedAt }) });
|
|
3920
|
+
const all = entries.filter((e) => e.owed);
|
|
3921
|
+
const owed = all.filter((e) => pointable(e, store.dir));
|
|
3922
|
+
const stale = owed.filter((e) => e.stretch !== null && localDate(e.stretch.lastAt, zone) < today).length;
|
|
3923
|
+
return { spans, plan, entries, now, waiting: owed.length, stale, unpointed: all.length - owed.length };
|
|
3792
3924
|
} catch {
|
|
3793
3925
|
return "failed";
|
|
3794
3926
|
}
|
|
@@ -3799,18 +3931,37 @@ function readOwed(store: Store): OwedReading | "failed" {
|
|
|
3799
3931
|
type OwedSource = () => OwedReading | "failed" | null;
|
|
3800
3932
|
|
|
3801
3933
|
function crashWriteUpFindings(input: DoctorInput, store: Store, owedReading: OwedSource): Finding[] {
|
|
3802
|
-
const
|
|
3934
|
+
const title = "Write-ups";
|
|
3935
|
+
const yesterday = isDay(input.today) ? addDays(input.today, -1) : input.today;
|
|
3803
3936
|
let waiting: number | null = null;
|
|
3804
3937
|
let stale = 0;
|
|
3938
|
+
let unpointed = 0;
|
|
3939
|
+
let yesterdayWords = "";
|
|
3940
|
+
let yesterdayData: { sessions: number; pieces: number; written: number } | null = null;
|
|
3805
3941
|
/** Sessions FINISHED in one project and waiting on words they left in
|
|
3806
3942
|
* another (the door's `written-up-here`), stale ones first. */
|
|
3807
3943
|
const shares: { session: string; here: string; elsewhere: string[]; stale: boolean }[] = [];
|
|
3808
3944
|
try {
|
|
3809
3945
|
const reading = owedReading();
|
|
3810
3946
|
if (reading === null || reading === "failed") throw new Error("owed reading unavailable");
|
|
3811
|
-
const { spans, plan,
|
|
3947
|
+
const { spans, plan, entries } = reading;
|
|
3812
3948
|
waiting = reading.waiting;
|
|
3813
3949
|
stale = reading.stale;
|
|
3950
|
+
unpointed = reading.unpointed;
|
|
3951
|
+
// YESTERDAY, keyed on the pieces' own dates in the store's zone.
|
|
3952
|
+
const day = entries
|
|
3953
|
+
.map((e) => e.perDate[yesterday])
|
|
3954
|
+
.filter((c): c is { pieces: number; written: number } => c !== undefined);
|
|
3955
|
+
yesterdayData = {
|
|
3956
|
+
sessions: day.length,
|
|
3957
|
+
pieces: day.reduce((n, c) => n + c.pieces, 0),
|
|
3958
|
+
written: day.reduce((n, c) => n + c.written, 0),
|
|
3959
|
+
};
|
|
3960
|
+
yesterdayWords =
|
|
3961
|
+
day.length === 0
|
|
3962
|
+
? `yesterday (${yesterday}): nothing captured`
|
|
3963
|
+
: `yesterday (${yesterday}): ${String(day.length)} session${day.length === 1 ? "" : "s"}, ` +
|
|
3964
|
+
`${String(yesterdayData.written)} of ${String(yesterdayData.pieces)} pieces written up`;
|
|
3814
3965
|
const progress = readWriteUpProgress(store);
|
|
3815
3966
|
for (const [key, p] of Object.entries(progress)) {
|
|
3816
3967
|
if (p.waiting !== true) continue;
|
|
@@ -3826,24 +3977,42 @@ function crashWriteUpFindings(input: DoctorInput, store: Store, owedReading: Owe
|
|
|
3826
3977
|
writeUpEntries(spans, { session, scopes: [scope] }).length > 0,
|
|
3827
3978
|
);
|
|
3828
3979
|
if (elsewhere.length === 0) continue;
|
|
3829
|
-
|
|
3980
|
+
const e = entries.find((x) => x.session === session);
|
|
3981
|
+
const from = e?.stretch === null || e === undefined ? input.today : localDate(e.stretch.lastAt, store.zone());
|
|
3982
|
+
shares.push({ session, here, elsewhere, stale: from < input.today });
|
|
3830
3983
|
}
|
|
3831
3984
|
shares.sort((a, b) => Number(b.stale) - Number(a.stale));
|
|
3832
3985
|
} catch {
|
|
3833
3986
|
waiting = null;
|
|
3834
3987
|
}
|
|
3835
|
-
const
|
|
3988
|
+
const lapses = lapsesSince(store, store.now() - WRITE_UP_LAPSE_WINDOW_DAYS * 86_400_000).length;
|
|
3989
|
+
const owedWords =
|
|
3836
3990
|
waiting === null
|
|
3837
|
-
? "
|
|
3991
|
+
? "could not read what is written up"
|
|
3838
3992
|
: waiting === 0
|
|
3839
|
-
? ""
|
|
3840
|
-
:
|
|
3841
|
-
(stale === 0 ? "" : `, ${String(stale)}
|
|
3993
|
+
? "nothing owed"
|
|
3994
|
+
: `${String(waiting)} session${waiting === 1 ? " owes" : "s owe"} a write-up` +
|
|
3995
|
+
(stale === 0 ? "" : `, ${String(stale)} from yesterday or earlier`);
|
|
3996
|
+
const detail =
|
|
3997
|
+
[
|
|
3998
|
+
yesterdayWords,
|
|
3999
|
+
owedWords,
|
|
4000
|
+
unpointed === 0 ? "" : `${String(unpointed)} small, not a person's session: left to lapse`,
|
|
4001
|
+
lapses === 0 ? "" : `${String(lapses)} lapsed this week`,
|
|
4002
|
+
]
|
|
4003
|
+
.filter((w) => w.length > 0)
|
|
4004
|
+
.join("; ");
|
|
3842
4005
|
const pointer = readWriteUpPointer(store);
|
|
3843
4006
|
const data = {
|
|
3844
4007
|
mode: "next-session",
|
|
3845
4008
|
waiting,
|
|
3846
4009
|
stale,
|
|
4010
|
+
unpointed,
|
|
4011
|
+
lapsedWeek: lapses,
|
|
4012
|
+
yesterday,
|
|
4013
|
+
yesterdaySessions: yesterdayData?.sessions ?? null,
|
|
4014
|
+
yesterdayPieces: yesterdayData?.pieces ?? null,
|
|
4015
|
+
yesterdayWritten: yesterdayData?.written ?? null,
|
|
3847
4016
|
pointer: pointer?.outcome ?? null,
|
|
3848
4017
|
pointerDate: pointer?.date ?? null,
|
|
3849
4018
|
};
|
|
@@ -3851,18 +4020,30 @@ function crashWriteUpFindings(input: DoctorInput, store: Store, owedReading: Owe
|
|
|
3851
4020
|
// session there would only defer again, so the advice says why and by how much.
|
|
3852
4021
|
if (pointer !== null && pointer.outcome === "deferred" && (waiting ?? 0) > 0) {
|
|
3853
4022
|
const short = Math.max(0, pointer.need - pointer.room);
|
|
4023
|
+
// WHAT TOOK THE ROOM, named (review of #285, M3): beside a full wake the
|
|
4024
|
+
// first-launch question or a plain reminder can be what left the pointer
|
|
4025
|
+
// no room — and then the wake's budget is not the thing to lower.
|
|
4026
|
+
const beside = pointer.beside ?? "";
|
|
4027
|
+
const cap =
|
|
4028
|
+
pointer.limit !== undefined && pointer.limit !== TUNABLES.HOST_OUTPUT_CHARS
|
|
4029
|
+
? `the ${pointer.limit.toLocaleString("en-US")}-character envelope that carries today's reminders`
|
|
4030
|
+
: "the host's 10,000-character cap";
|
|
3854
4031
|
const why =
|
|
3855
4032
|
pointer.reason === "host-cap"
|
|
3856
|
-
? `the pointer did not fit on ${pointer.date}: it needs ${String(pointer.need)} bytes and the wake left ${String(Math.max(0, pointer.room))} under
|
|
4033
|
+
? `the pointer did not fit on ${pointer.date}: it needs ${String(pointer.need)} bytes and the wake${beside.length === 0 ? "" : ` and ${beside}`} left ${String(Math.max(0, pointer.room))} under ${cap} (${String(short)} short)`
|
|
3857
4034
|
: `the pointer could not be recorded on ${pointer.date} (${pointer.reason ?? "unknown"})`;
|
|
4035
|
+
const hostCapFix =
|
|
4036
|
+
beside.length === 0
|
|
4037
|
+
? `The wake is too full: lower "injectionBudgetBytes" in ${tilde(input.configPath)} by ${String(short)} or more.`
|
|
4038
|
+
: `It was ${beside} beside the wake that took the room that morning, not the wake alone; the pointer is offered again at the next session start with room. If it keeps deferring, lower "injectionBudgetBytes" in ${tilde(input.configPath)} by ${String(short)} or more.`;
|
|
3858
4039
|
return [
|
|
3859
4040
|
finding(
|
|
3860
4041
|
"crash-write-up",
|
|
3861
4042
|
"amber",
|
|
3862
|
-
|
|
3863
|
-
`${
|
|
4043
|
+
title,
|
|
4044
|
+
`${detail} — ${why}`,
|
|
3864
4045
|
pointer.reason === "host-cap"
|
|
3865
|
-
?
|
|
4046
|
+
? hostCapFix
|
|
3866
4047
|
: "The session registry under the store could not be written; read the Store line.",
|
|
3867
4048
|
data,
|
|
3868
4049
|
),
|
|
@@ -3877,8 +4058,8 @@ function crashWriteUpFindings(input: DoctorInput, store: Store, owedReading: Owe
|
|
|
3877
4058
|
finding(
|
|
3878
4059
|
"crash-write-up",
|
|
3879
4060
|
"amber",
|
|
3880
|
-
|
|
3881
|
-
`${
|
|
4061
|
+
title,
|
|
4062
|
+
`${detail} — session ${share.session} is finished in ${tilde(share.here)} and waiting on words it left in ${where}` +
|
|
3882
4063
|
(shares.length > 1 ? ` (${String(shares.length)} such sessions)` : ""),
|
|
3883
4064
|
`Open a session in ${where}: its start points at the rest. A directory set off never will, and there is no command yet to close a session by hand.`,
|
|
3884
4065
|
{ ...data, sharesWaiting: shares.length },
|
|
@@ -3890,14 +4071,14 @@ function crashWriteUpFindings(input: DoctorInput, store: Store, owedReading: Owe
|
|
|
3890
4071
|
finding(
|
|
3891
4072
|
"crash-write-up",
|
|
3892
4073
|
"amber",
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
"Open a session in the project each one
|
|
4074
|
+
title,
|
|
4075
|
+
detail,
|
|
4076
|
+
"Open a session in the project each one is in: its start points at the oldest. counterparts coverage says which. A stretch nobody writes up lapses after two more days of use — nothing is deleted, it stops being owed.",
|
|
3896
4077
|
data,
|
|
3897
4078
|
),
|
|
3898
4079
|
];
|
|
3899
4080
|
}
|
|
3900
|
-
return [finding("crash-write-up", "green",
|
|
4081
|
+
return [finding("crash-write-up", "green", title, detail, "", data)];
|
|
3901
4082
|
}
|
|
3902
4083
|
|
|
3903
4084
|
/**
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE HOOK ENVELOPE'S SHAPE, in one place (2026-09-29, review of #285, S2).
|
|
3
|
+
*
|
|
4
|
+
* `bin/hook.ts#hostDelivery` prints it, and `hooks.ts` measures it BEFORE it
|
|
5
|
+
* decides which asks go beside the wake — so the two cannot disagree about how
|
|
6
|
+
* big the JSON form of an envelope is. A person-facing line (a plain reminder,
|
|
7
|
+
* a doctor notice) reaches the terminal only inside this JSON form, whose
|
|
8
|
+
* budget is `TUNABLES.ENVELOPE_CHARS`; everything else is measured as plain
|
|
9
|
+
* stdout against `TUNABLES.HOST_OUTPUT_CHARS`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The host's own spelling of the event that carries a notice at a session's
|
|
14
|
+
* start. It appears twice — as a key in the hook's event map, and as
|
|
15
|
+
* `hookSpecificOutput.hookEventName` in the JSON form — and the host matches
|
|
16
|
+
* that field against its own name, so the two spellings must be one constant.
|
|
17
|
+
*/
|
|
18
|
+
export const HOST_SESSION_START = "SessionStart";
|
|
19
|
+
|
|
20
|
+
/** The same, for a prompt (the update notice, plain reminders, the dream offer). */
|
|
21
|
+
export const HOST_USER_PROMPT_SUBMIT = "UserPromptSubmit";
|
|
22
|
+
|
|
23
|
+
/** The JSON form of an envelope: the person's line(s) and the model's context. */
|
|
24
|
+
export function envelopeJson(hookEventName: string, systemMessage: string, additionalContext: string): string {
|
|
25
|
+
return JSON.stringify({
|
|
26
|
+
systemMessage,
|
|
27
|
+
hookSpecificOutput: { hookEventName, additionalContext },
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* What `text` costs inside the JSON form, in bytes: its escaped length (a
|
|
33
|
+
* newline is two characters, a quote two). Bytes, so the count is never under
|
|
34
|
+
* the characters the host measures.
|
|
35
|
+
*/
|
|
36
|
+
export function escapedBytes(text: string): number {
|
|
37
|
+
return Buffer.byteLength(JSON.stringify(text), "utf8") - 2;
|
|
38
|
+
}
|