counterparts 0.1.0
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/CONSTITUTION.md +68 -0
- package/LICENSE +21 -0
- package/README.md +348 -0
- package/docs/ELI5.md +84 -0
- package/docs/QUICKSTART.md +1258 -0
- package/docs/module-map.md +81 -0
- package/package.json +63 -0
- package/src/adapters/claude-code/CONTRACT.md +606 -0
- package/src/adapters/claude-code/INTERFACE-GAPS.md +655 -0
- package/src/adapters/claude-code/NOTES.md +1055 -0
- package/src/adapters/claude-code/bin/hook.ts +820 -0
- package/src/adapters/claude-code/bin/runner.ts +522 -0
- package/src/adapters/claude-code/config.ts +778 -0
- package/src/adapters/claude-code/credentials.ts +199 -0
- package/src/adapters/claude-code/doctor.ts +2557 -0
- package/src/adapters/claude-code/embed-client.ts +617 -0
- package/src/adapters/claude-code/hooks.ts +2240 -0
- package/src/adapters/claude-code/index.ts +224 -0
- package/src/adapters/claude-code/interpret-client.ts +395 -0
- package/src/adapters/claude-code/page-writer.ts +462 -0
- package/src/adapters/claude-code/primacy.ts +162 -0
- package/src/adapters/claude-code/spawn.ts +241 -0
- package/src/adapters/claude-code/standdown.ts +536 -0
- package/src/adapters/claude-code/transcript.ts +661 -0
- package/src/adapters/claude-code/vectors.ts +415 -0
- package/src/adapters/cli/CONTRACT.md +255 -0
- package/src/adapters/cli/INTERFACE-GAPS.md +350 -0
- package/src/adapters/cli/NOTES.md +936 -0
- package/src/adapters/cli/bin/counterparts.ts +74 -0
- package/src/adapters/cli/commands.ts +6095 -0
- package/src/adapters/cli/export.ts +766 -0
- package/src/adapters/cli/index.ts +103 -0
- package/src/adapters/cli/install.ts +670 -0
- package/src/adapters/cli/removal.ts +1186 -0
- package/src/adapters/cli/repair-dates.ts +659 -0
- package/src/adapters/cli/self-page.ts +229 -0
- package/src/adapters/cli/snapshot.ts +279 -0
- package/src/adapters/cli/start-fresh.ts +1228 -0
- package/src/adapters/config-path.ts +342 -0
- package/src/adapters/dashboard/CONTRACT.md +67 -0
- package/src/adapters/dashboard/INTERFACE-GAPS.md +139 -0
- package/src/adapters/dashboard/NOTES.md +474 -0
- package/src/adapters/dashboard/activity.ts +121 -0
- package/src/adapters/dashboard/ansi.ts +82 -0
- package/src/adapters/dashboard/bin/dashboard.ts +479 -0
- package/src/adapters/dashboard/browse.ts +298 -0
- package/src/adapters/dashboard/identity.ts +182 -0
- package/src/adapters/dashboard/index.ts +183 -0
- package/src/adapters/dashboard/layout.ts +149 -0
- package/src/adapters/dashboard/registries.ts +291 -0
- package/src/adapters/dashboard/resolve.ts +206 -0
- package/src/adapters/dashboard/source.ts +48 -0
- package/src/adapters/dashboard/status.ts +327 -0
- package/src/adapters/dashboard/stories.ts +194 -0
- package/src/adapters/dashboard/web/app.html +1731 -0
- package/src/adapters/dashboard/web/brain.html +463 -0
- package/src/adapters/dashboard/web/fired.ts +31 -0
- package/src/adapters/dashboard/web/flow.ts +457 -0
- package/src/adapters/dashboard/web/narrate.ts +1042 -0
- package/src/adapters/dashboard/web/reveal.ts +135 -0
- package/src/adapters/dashboard/web/server.ts +287 -0
- package/src/adapters/dashboard/web/views.ts +1744 -0
- package/src/adapters/expansions.ts +569 -0
- package/src/adapters/fired.ts +1580 -0
- package/src/adapters/mcp/CONTRACT.md +240 -0
- package/src/adapters/mcp/INTERFACE-GAPS.md +271 -0
- package/src/adapters/mcp/NOTES.md +205 -0
- package/src/adapters/mcp/bin/serve.ts +349 -0
- package/src/adapters/mcp/deliberate.ts +619 -0
- package/src/adapters/mcp/index.ts +101 -0
- package/src/adapters/mcp/protocol.ts +170 -0
- package/src/adapters/mcp/server.ts +1740 -0
- package/src/adapters/mcp/stdio.ts +56 -0
- package/src/adapters/mcp/tools.ts +779 -0
- package/src/adapters/scopes.ts +657 -0
- package/src/adapters/sessions.ts +402 -0
- package/src/adapters/snapshots.ts +1069 -0
- package/src/adapters/stance-env.ts +137 -0
- package/src/core/associate/CONTRACT.md +118 -0
- package/src/core/associate/INTERFACE-GAPS.md +173 -0
- package/src/core/associate/NOTES.md +194 -0
- package/src/core/associate/buffer.ts +66 -0
- package/src/core/associate/edges.ts +188 -0
- package/src/core/associate/index.ts +570 -0
- package/src/core/associate/pending.ts +383 -0
- package/src/core/associate/spread.ts +149 -0
- package/src/core/associate/tunables.ts +123 -0
- package/src/core/bridge.ts +272 -0
- package/src/core/briefing.ts +67 -0
- package/src/core/counterpart.ts +3855 -0
- package/src/core/encode/CONTRACT.md +151 -0
- package/src/core/encode/INTERFACE-GAPS.md +135 -0
- package/src/core/encode/NOTES.md +146 -0
- package/src/core/encode/aliases.ts +71 -0
- package/src/core/encode/battery.ts +284 -0
- package/src/core/encode/chunk.ts +265 -0
- package/src/core/encode/emotion.ts +119 -0
- package/src/core/encode/floor.ts +76 -0
- package/src/core/encode/index.ts +100 -0
- package/src/core/encode/precision.ts +162 -0
- package/src/core/encode/preselect.ts +269 -0
- package/src/core/encode/salience.ts +108 -0
- package/src/core/encode/secrets.ts +265 -0
- package/src/core/encode/tunables.ts +99 -0
- package/src/core/encode/types.ts +286 -0
- package/src/core/encode/words.ts +75 -0
- package/src/core/handoff/CONTRACT.md +199 -0
- package/src/core/handoff/INTERFACE-GAPS.md +166 -0
- package/src/core/handoff/NOTES.md +206 -0
- package/src/core/handoff/index.ts +957 -0
- package/src/core/mint.ts +279 -0
- package/src/core/observer.ts +28 -0
- package/src/core/physics/CONTRACT.md +341 -0
- package/src/core/physics/NOTES.md +155 -0
- package/src/core/physics/clock.ts +51 -0
- package/src/core/physics/index.ts +1054 -0
- package/src/core/prospective/CONTRACT.md +137 -0
- package/src/core/prospective/INTERFACE-GAPS.md +112 -0
- package/src/core/prospective/NOTES.md +160 -0
- package/src/core/prospective/derive.ts +188 -0
- package/src/core/prospective/index.ts +1030 -0
- package/src/core/prospective/tunables.ts +72 -0
- package/src/core/prospective/windows.ts +187 -0
- package/src/core/recall/CONTRACT.md +326 -0
- package/src/core/recall/INTERFACE-GAPS.md +163 -0
- package/src/core/recall/NOTES.md +472 -0
- package/src/core/recall/activate.ts +521 -0
- package/src/core/recall/cues.ts +275 -0
- package/src/core/recall/gate.ts +441 -0
- package/src/core/recall/index.ts +692 -0
- package/src/core/recall/probe.ts +239 -0
- package/src/core/recall/reference.ts +201 -0
- package/src/core/recall/render.ts +285 -0
- package/src/core/recall/session.ts +403 -0
- package/src/core/recall/tunables.ts +329 -0
- package/src/core/remember/CONTRACT.md +293 -0
- package/src/core/remember/INTERFACE-GAPS.md +189 -0
- package/src/core/remember/NOTES.md +373 -0
- package/src/core/remember/fallback.ts +452 -0
- package/src/core/remember/index.ts +103 -0
- package/src/core/remember/owner-strike-seam.ts +479 -0
- package/src/core/remember/proposals.ts +609 -0
- package/src/core/remember/spans.ts +1310 -0
- package/src/core/remember/tunables.ts +111 -0
- package/src/core/remember/updates.ts +198 -0
- package/src/core/retrieval.ts +96 -0
- package/src/core/revision.ts +441 -0
- package/src/core/schemas/CONTRACT.md +190 -0
- package/src/core/schemas/INTERFACE-GAPS.md +172 -0
- package/src/core/schemas/NOTES.md +260 -0
- package/src/core/schemas/aliases.ts +160 -0
- package/src/core/schemas/index.ts +1459 -0
- package/src/core/schemas/tunables.ts +44 -0
- package/src/core/schemas/types.ts +387 -0
- package/src/core/self/CONTRACT.md +459 -0
- package/src/core/self/INTERFACE-GAPS.md +284 -0
- package/src/core/self/NOTES.md +1057 -0
- package/src/core/self/briefing.ts +980 -0
- package/src/core/self/episodes.ts +483 -0
- package/src/core/self/freeze.ts +103 -0
- package/src/core/self/identity.ts +604 -0
- package/src/core/self/index.ts +2130 -0
- package/src/core/self/journal-file.ts +760 -0
- package/src/core/self/page.ts +404 -0
- package/src/core/self/tunables.ts +244 -0
- package/src/core/self/writer.ts +714 -0
- package/src/core/sleep/CONTRACT.md +298 -0
- package/src/core/sleep/INTERFACE-GAPS.md +262 -0
- package/src/core/sleep/NOTES.md +770 -0
- package/src/core/sleep/briefing.ts +86 -0
- package/src/core/sleep/consolidate.ts +241 -0
- package/src/core/sleep/cycle.ts +598 -0
- package/src/core/sleep/decay.ts +237 -0
- package/src/core/sleep/dedup.ts +373 -0
- package/src/core/sleep/index.ts +112 -0
- package/src/core/sleep/log.ts +116 -0
- package/src/core/sleep/markers.ts +164 -0
- package/src/core/sleep/prune.ts +170 -0
- package/src/core/sleep/strength-cache.ts +176 -0
- package/src/core/sleep/tunables.ts +135 -0
- package/src/core/sleep/types.ts +542 -0
- package/src/core/store/CONTRACT.md +446 -0
- package/src/core/store/NOTES.md +1068 -0
- package/src/core/store/cache.ts +709 -0
- package/src/core/store/db.ts +275 -0
- package/src/core/store/errors.ts +134 -0
- package/src/core/store/index.ts +2450 -0
- package/src/core/store/operational.ts +610 -0
- package/src/core/store/owner-op-seam.ts +428 -0
- package/src/core/store/paths.ts +494 -0
- package/src/core/store/prose.ts +165 -0
- package/src/core/store/render.ts +87 -0
- package/src/core/store/walk-seam.ts +78 -0
- package/src/core/types.ts +68 -0
- package/tools/install-loop/run.sh +1063 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dashboard's READ SURFACE, named in one place.
|
|
3
|
+
*
|
|
4
|
+
* Every view takes a `DashboardSource` rather than a `Counterpart`, for one
|
|
5
|
+
* reason: this interface is the complete list of what an instrument touches, so
|
|
6
|
+
* "what could the dashboard possibly reach?" is answerable by reading nine lines
|
|
7
|
+
* instead of auditing five view files. The stance travels with it — a source is
|
|
8
|
+
* constructed only from a Counterpart that is already in observer mode, and
|
|
9
|
+
* `sourceOf` refuses otherwise (CONTRACT §5 [M]: observer BY CONSTRUCTION, not
|
|
10
|
+
* by the store standing down at the last moment; `docs/observer-mode.md` G4).
|
|
11
|
+
*
|
|
12
|
+
* This is NOT a defensive wrapper. The three modules below are the real objects
|
|
13
|
+
* and their write methods are still on them; the enforcement that matters is the
|
|
14
|
+
* refusal here plus the source scan in `test/dashboard.test.ts`, which fails on
|
|
15
|
+
* any `WRITE_METHOD` call or filesystem write appearing anywhere in this
|
|
16
|
+
* directory. Types are documentation; the scan is the mechanism.
|
|
17
|
+
*/
|
|
18
|
+
import type { Counterpart } from "../../core/counterpart.js";
|
|
19
|
+
import type { Schemas } from "../../core/schemas/index.js";
|
|
20
|
+
import type { Self } from "../../core/self/index.js";
|
|
21
|
+
import type { Store } from "../../core/store/index.js";
|
|
22
|
+
|
|
23
|
+
export interface DashboardSource {
|
|
24
|
+
readonly store: Store;
|
|
25
|
+
readonly schemas: Schemas;
|
|
26
|
+
readonly self: Self;
|
|
27
|
+
/** Always true. A false one never gets built. */
|
|
28
|
+
readonly observer: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class ObserverRequired extends Error {
|
|
32
|
+
constructor() {
|
|
33
|
+
super(
|
|
34
|
+
"the dashboard reads only in observer mode — open the Counterpart with { observer: true }",
|
|
35
|
+
);
|
|
36
|
+
this.name = "ObserverRequired";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function sourceOf(counterpart: Counterpart): DashboardSource {
|
|
41
|
+
if (!counterpart.observer || !counterpart.store.observer) throw new ObserverRequired();
|
|
42
|
+
return {
|
|
43
|
+
store: counterpart.store,
|
|
44
|
+
schemas: counterpart.schemas,
|
|
45
|
+
self: counterpart.self,
|
|
46
|
+
observer: true,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `status` — the brain at a glance, in the brain's own voice.
|
|
3
|
+
*
|
|
4
|
+
* This is the view the totality guarantee is really about (CONTRACT §3/§5 [M]).
|
|
5
|
+
* Three registries are enumerated here and every member of each gets a line:
|
|
6
|
+
* every KIND physics knows, every BAND, every PHASE of the cycle. A member with
|
|
7
|
+
* nothing to report prints an absence marker rather than vanishing, because a
|
|
8
|
+
* vanished row reads as "quiet" and quiet is how v1's starved curation path hid
|
|
9
|
+
* for months (scar §2.17).
|
|
10
|
+
*
|
|
11
|
+
* Narration is first person and plain (CONTRACT §3, "narration in the system's
|
|
12
|
+
* own voice") — the owner's fastest read is a sentence, not a legend.
|
|
13
|
+
*
|
|
14
|
+
* One honesty constraint shapes the cycle block. There is no durable per-cycle
|
|
15
|
+
* outcome record: `CycleReport` is returned to its caller and then gone, and the
|
|
16
|
+
* promotion / prune / merge records live under meta keys nothing can enumerate
|
|
17
|
+
* (`INTERFACE-GAPS.md` §2). What IS durable is each phase's completion marker and
|
|
18
|
+
* each row's archived-with-reason state. So the phase table carries the per-cycle
|
|
19
|
+
* truth — *which lived day did this last finish* — and the exit counts are
|
|
20
|
+
* labelled SINCE BIRTH. A number invented to look like "last cycle" would be scar
|
|
21
|
+
* §2.17 committed by the very view that exists to prevent it.
|
|
22
|
+
*/
|
|
23
|
+
import { band, strength, symmetryCheck } from "../../core/physics/index.js";
|
|
24
|
+
import { TUNABLES as SCHEMA_TUNABLES } from "../../core/schemas/index.js";
|
|
25
|
+
import {
|
|
26
|
+
MARKER_UNSET,
|
|
27
|
+
MERGE_ARCHIVE_REASON,
|
|
28
|
+
PRUNE_ARCHIVE_REASON,
|
|
29
|
+
isJournal,
|
|
30
|
+
readMarker,
|
|
31
|
+
} from "../../core/sleep/index.js";
|
|
32
|
+
import type { Band, Kind } from "../../core/types.js";
|
|
33
|
+
import { PLAIN } from "./ansi.js";
|
|
34
|
+
import type { Style } from "./ansi.js";
|
|
35
|
+
import {
|
|
36
|
+
NEVER,
|
|
37
|
+
NONE,
|
|
38
|
+
heading,
|
|
39
|
+
indent,
|
|
40
|
+
meter,
|
|
41
|
+
num,
|
|
42
|
+
plural,
|
|
43
|
+
stack,
|
|
44
|
+
subheading,
|
|
45
|
+
table,
|
|
46
|
+
} from "./layout.js";
|
|
47
|
+
import { BANDS, CYCLE_PHASES, KINDS, countBy } from "./registries.js";
|
|
48
|
+
import { contestedBeliefs } from "./stories.js";
|
|
49
|
+
import type { DashboardSource } from "./source.js";
|
|
50
|
+
|
|
51
|
+
export interface StatusOptions {
|
|
52
|
+
readonly style?: Style;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface Tally {
|
|
56
|
+
readonly byKind: Map<Kind, number>;
|
|
57
|
+
readonly byBand: Map<Band, number>;
|
|
58
|
+
readonly meanStrength: Map<Kind, number>;
|
|
59
|
+
readonly exits: Map<string, number>;
|
|
60
|
+
promoted: number;
|
|
61
|
+
guarded: number;
|
|
62
|
+
/** Rows carrying pressure right now. */
|
|
63
|
+
contested: number;
|
|
64
|
+
/** Beliefs that have EVER taken a credited challenge — a different question. */
|
|
65
|
+
everContested: number;
|
|
66
|
+
/** Memories AND schemas together — the population the kind and band tables
|
|
67
|
+
* are over. Kept because those tables walk both, and split below because a
|
|
68
|
+
* belief is not a memory and the wake preface counts only memories. */
|
|
69
|
+
live: number;
|
|
70
|
+
/** `type: "memory"` rows. THE number the wake preface states
|
|
71
|
+
* (`self/briefing.ts#prefaceLine`), so the number this view must lead with:
|
|
72
|
+
* one demo store reported 143 here and 121 there on 2026-09-05, and both
|
|
73
|
+
* were right about different populations. */
|
|
74
|
+
memories: number;
|
|
75
|
+
/** `type: "schema"` rows — the entities and beliefs. */
|
|
76
|
+
schemas: number;
|
|
77
|
+
archived: number;
|
|
78
|
+
/** Journal entries — episodes. NOT counted in `live`: an episode is the
|
|
79
|
+
* SOURCE a memory was made from, not a memory, and it is outside every
|
|
80
|
+
* sleep phase (`sleep/types.ts#isJournal`). Counted here so excluding it
|
|
81
|
+
* from the census is visible rather than silent (constitution 16). */
|
|
82
|
+
journal: number;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function tally(src: DashboardSource, day: number): Tally {
|
|
86
|
+
const store = src.store;
|
|
87
|
+
const out: Tally = {
|
|
88
|
+
byKind: new Map(),
|
|
89
|
+
byBand: new Map(),
|
|
90
|
+
meanStrength: new Map(),
|
|
91
|
+
exits: new Map(),
|
|
92
|
+
promoted: 0,
|
|
93
|
+
guarded: 0,
|
|
94
|
+
contested: 0,
|
|
95
|
+
everContested: contestedBeliefs(src).length,
|
|
96
|
+
live: 0,
|
|
97
|
+
memories: 0,
|
|
98
|
+
schemas: 0,
|
|
99
|
+
archived: 0,
|
|
100
|
+
journal: 0,
|
|
101
|
+
};
|
|
102
|
+
const strengths = new Map<Kind, number[]>();
|
|
103
|
+
|
|
104
|
+
for (const id of store.list()) {
|
|
105
|
+
const row = store.row(id);
|
|
106
|
+
if (row === undefined) continue;
|
|
107
|
+
if (row.archived === 1) {
|
|
108
|
+
out.archived += 1;
|
|
109
|
+
const reason = row.archived_reason ?? "no reason recorded";
|
|
110
|
+
out.exits.set(reason, (out.exits.get(reason) ?? 0) + 1);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (isJournal(row)) {
|
|
114
|
+
out.journal += 1;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
out.live += 1;
|
|
118
|
+
if (row.type === "schema") out.schemas += 1;
|
|
119
|
+
else out.memories += 1;
|
|
120
|
+
out.byKind.set(row.kind, (out.byKind.get(row.kind) ?? 0) + 1);
|
|
121
|
+
if (row.promoted_identity === 1) out.promoted += 1;
|
|
122
|
+
if (row.protected === 1) out.guarded += 1;
|
|
123
|
+
if (row.pressure > 0) out.contested += 1;
|
|
124
|
+
// The stored band column is a birth fossil — episodic at mint, identity at
|
|
125
|
+
// promotion, never "semantic" (replay review F6). The census a glance
|
|
126
|
+
// trusts must be the LIVE band: arithmetic over the row's physics.
|
|
127
|
+
let liveBand = row.band;
|
|
128
|
+
try {
|
|
129
|
+
const physics = store.physicsOf(id);
|
|
130
|
+
liveBand = band(physics, day);
|
|
131
|
+
const list = strengths.get(row.kind) ?? [];
|
|
132
|
+
list.push(strength(physics, day));
|
|
133
|
+
strengths.set(row.kind, list);
|
|
134
|
+
} catch {
|
|
135
|
+
// A row whose physics will not read is not worth failing a glance over;
|
|
136
|
+
// its recorded band is the honest fallback.
|
|
137
|
+
}
|
|
138
|
+
out.byBand.set(liveBand, (out.byBand.get(liveBand) ?? 0) + 1);
|
|
139
|
+
}
|
|
140
|
+
for (const [kind, list] of strengths) {
|
|
141
|
+
out.meanStrength.set(kind, list.reduce((a, b) => a + b, 0) / Math.max(1, list.length));
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function renderStatus(src: DashboardSource, opts: StatusOptions = {}): string {
|
|
147
|
+
const style = opts.style ?? PLAIN;
|
|
148
|
+
const day = src.store.livedDay();
|
|
149
|
+
const t = tally(src, day);
|
|
150
|
+
const lastActive = src.store.getMeta("lastActiveDate") ?? "";
|
|
151
|
+
|
|
152
|
+
const opening =
|
|
153
|
+
`I have lived ${plural(day, "day")}` +
|
|
154
|
+
(lastActive === "" ? "" : ` — the last of them ${lastActive}`) +
|
|
155
|
+
". " +
|
|
156
|
+
(t.live + t.archived + t.journal === 0
|
|
157
|
+
? "I am holding nothing yet."
|
|
158
|
+
: `I am holding ${plural(t.memories, "memory", "memories")}` +
|
|
159
|
+
// The schemas are named rather than folded in. They ARE live rows, and
|
|
160
|
+
// the kind and band tables below count them — but a belief about Ada is
|
|
161
|
+
// not a memory of a day, and the briefing the model wakes on says only
|
|
162
|
+
// the memories. A view that added them and said "memories" is a view
|
|
163
|
+
// that disagrees with the wake for a reader who checks.
|
|
164
|
+
(t.schemas === 0
|
|
165
|
+
? ""
|
|
166
|
+
: `, plus ${plural(t.schemas, "belief or entity", "beliefs and entities")}`) +
|
|
167
|
+
(t.archived === 0 ? "" : `, and ${t.archived} more sit archived`) +
|
|
168
|
+
// Said out loud because it is EXCLUDED from the count before it: the
|
|
169
|
+
// journal is the source, and it is not subject to forgetting.
|
|
170
|
+
(t.journal === 0
|
|
171
|
+
? "."
|
|
172
|
+
: `, beside ${plural(t.journal, "journal entry", "journal entries")} that do not decay.`));
|
|
173
|
+
|
|
174
|
+
return stack(
|
|
175
|
+
heading("What I am, right now", style),
|
|
176
|
+
opening,
|
|
177
|
+
kindBlock(t, style),
|
|
178
|
+
bandBlock(t, style),
|
|
179
|
+
cycleBlock(src, day, style),
|
|
180
|
+
symmetryBlock(src, style),
|
|
181
|
+
keepBlock(t, style),
|
|
182
|
+
briefingBlock(src, style),
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ── by kind ──────────────────────────────────────────────────────────────────
|
|
187
|
+
|
|
188
|
+
function kindBlock(t: Tally, style: Style): string {
|
|
189
|
+
const peak = Math.max(1, ...KINDS.map((k) => t.byKind.get(k) ?? 0));
|
|
190
|
+
const rows = countBy(KINDS, t.byKind).map((axis) => {
|
|
191
|
+
if (axis.absent) return [axis.axis, "0", style.warn(NONE), ""];
|
|
192
|
+
const mean = t.meanStrength.get(axis.axis as Kind) ?? 0;
|
|
193
|
+
return [axis.axis, String(axis.count), meter(axis.count / peak), `mean strength ${num(mean)}`];
|
|
194
|
+
});
|
|
195
|
+
return `${subheading("By kind — every kind I know how to hold", style)}\n${indent(
|
|
196
|
+
table(rows, { right: [1] }),
|
|
197
|
+
)}`;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ── by band ──────────────────────────────────────────────────────────────────
|
|
201
|
+
|
|
202
|
+
const BAND_GLOSS: Record<Band, string> = {
|
|
203
|
+
episodic: "still an episode; forgettable",
|
|
204
|
+
semantic: "settled into what I know",
|
|
205
|
+
identity: "constitutive, and physics can still move it",
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
function bandBlock(t: Tally, style: Style): string {
|
|
209
|
+
const peak = Math.max(1, ...BANDS.map((b) => t.byBand.get(b) ?? 0));
|
|
210
|
+
const rows = countBy(BANDS, t.byBand).map((axis) =>
|
|
211
|
+
axis.absent
|
|
212
|
+
? [axis.axis, "0", style.warn(NONE), ""]
|
|
213
|
+
: [axis.axis, String(axis.count), meter(axis.count / peak), BAND_GLOSS[axis.axis as Band]],
|
|
214
|
+
);
|
|
215
|
+
return `${subheading("By band — how settled each memory is", style)}\n${indent(
|
|
216
|
+
table(rows, { right: [1] }),
|
|
217
|
+
)}`;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// ── the cycle ────────────────────────────────────────────────────────────────
|
|
221
|
+
|
|
222
|
+
function cycleBlock(src: DashboardSource, day: number, style: Style): string {
|
|
223
|
+
const rows = CYCLE_PHASES.map((phase) => {
|
|
224
|
+
const marker = readMarker(src.store, phase);
|
|
225
|
+
if (marker.health === "torn") {
|
|
226
|
+
return [phase, style.warn("torn marker"), style.warn(`unreadable value ${marker.raw ?? ""}`)];
|
|
227
|
+
}
|
|
228
|
+
if (marker.day === MARKER_UNSET) return [phase, style.warn(NEVER), ""];
|
|
229
|
+
const age = day - marker.day;
|
|
230
|
+
return [phase, `last finished day ${marker.day}`, age <= 0 ? "today" : `${plural(age, "day")} ago`];
|
|
231
|
+
});
|
|
232
|
+
return `${subheading("My last cycle — what finished, and when", style)}\n${indent(table(rows))}`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// ── the ratchet tripwire, read by REASON ────────────────────────────────────
|
|
236
|
+
/**
|
|
237
|
+
* G12 surfaced: up-moves vs down-moves per kind from the durable
|
|
238
|
+
* `band.transition` counter, judged by `physics.symmetryCheck`. The verdict is
|
|
239
|
+
* arithmetic over the log — never persisted, so it cannot go stale — and it is
|
|
240
|
+
* rendered by REASON, never by `ok`: "never-asked" carries ok:true, and a
|
|
241
|
+
* starved counter reading as healthy is exactly the lie scar §2.4 forbids.
|
|
242
|
+
*/
|
|
243
|
+
function symmetryBlock(src: DashboardSource, style: Style): string {
|
|
244
|
+
const rows = KINDS.map((kind) => {
|
|
245
|
+
let up = 0;
|
|
246
|
+
let down = 0;
|
|
247
|
+
for (const row of src.store.eventLog({ name: "band.transition", limit: 100_000 })) {
|
|
248
|
+
if (row.payload === null) continue;
|
|
249
|
+
try {
|
|
250
|
+
const p = JSON.parse(row.payload) as { kind?: string; direction?: string };
|
|
251
|
+
if (p.kind !== kind) continue;
|
|
252
|
+
if (p.direction === "up") up += 1;
|
|
253
|
+
else if (p.direction === "down") down += 1;
|
|
254
|
+
} catch {
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const verdict = symmetryCheck(kind, { up, down });
|
|
259
|
+
const label =
|
|
260
|
+
verdict.reason === "never-asked"
|
|
261
|
+
? style.warn(`never-asked (${up}\u2191/${down}\u2193)`)
|
|
262
|
+
: verdict.reason === "within-expectation"
|
|
263
|
+
? `within-expectation (${up}\u2191/${down}\u2193)`
|
|
264
|
+
: style.warn(`${verdict.reason} (${up}\u2191/${down}\u2193)`);
|
|
265
|
+
return [kind, label];
|
|
266
|
+
});
|
|
267
|
+
return `${subheading("Band symmetry \u2014 the ratchet tripwire, by reason", style)}\n${indent(table(rows))}`;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// ── what I have kept, and what I let go ──────────────────────────────────────
|
|
271
|
+
|
|
272
|
+
function keepBlock(t: Tally, style: Style): string {
|
|
273
|
+
const named: [string, string][] = [
|
|
274
|
+
[PRUNE_ARCHIVE_REASON, "let go at the floor"],
|
|
275
|
+
[MERGE_ARCHIVE_REASON, "merged into a duplicate"],
|
|
276
|
+
[SCHEMA_TUNABLES.FADE_REASON, "faded out of my vocabulary"],
|
|
277
|
+
];
|
|
278
|
+
const rows: string[][] = named.map(([reason, gloss]) => {
|
|
279
|
+
const n = t.exits.get(reason) ?? 0;
|
|
280
|
+
return [reason, n === 0 ? style.warn(NONE) : String(n), gloss];
|
|
281
|
+
});
|
|
282
|
+
for (const [reason, n] of t.exits) {
|
|
283
|
+
if (named.some(([r]) => r === reason)) continue;
|
|
284
|
+
// Every other reason a row carries — supersession's `revised-by-pressure`
|
|
285
|
+
// among them. Listed rather than folded away: an exit I cannot gloss is
|
|
286
|
+
// still an exit, and hiding it would be the silence this block prevents.
|
|
287
|
+
rows.push([reason, String(n), "recorded by whatever archived it"]);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const sentence =
|
|
291
|
+
`${t.promoted === 0 ? "Nothing" : plural(t.promoted, "memory", "memories")} ` +
|
|
292
|
+
`${t.promoted === 1 || t.promoted === 0 ? "has" : "have"} crossed into identity; ` +
|
|
293
|
+
`${t.guarded === 0 ? "nothing is" : `${plural(t.guarded, "memory", "memories")} ${t.guarded === 1 ? "is" : "are"}`} protected; ` +
|
|
294
|
+
`${t.contested === 0 ? "no belief is" : `${plural(t.contested, "belief")} ${t.contested === 1 ? "is" : "are"}`} under challenge right now.`;
|
|
295
|
+
|
|
296
|
+
// Standing pressure and having-been-argued-with are different questions, and a
|
|
297
|
+
// revision resets the first — so a store can read "nothing under challenge"
|
|
298
|
+
// while `stories` has a story to tell. Reconciled here rather than left as an
|
|
299
|
+
// apparent contradiction between two views.
|
|
300
|
+
const ever = t.everContested;
|
|
301
|
+
const history =
|
|
302
|
+
ever === 0
|
|
303
|
+
? "No belief has ever taken a credited challenge."
|
|
304
|
+
: `${plural(ever, "belief")} ${ever === 1 ? "has" : "have"} been argued with at some point — \`stories\` tells each one.`;
|
|
305
|
+
|
|
306
|
+
const body = [
|
|
307
|
+
sentence,
|
|
308
|
+
history,
|
|
309
|
+
"",
|
|
310
|
+
"Ways out, counted since birth — never a per-cycle number I do not durably hold:",
|
|
311
|
+
indent(table(rows, { right: [1] })),
|
|
312
|
+
].join("\n");
|
|
313
|
+
return `${subheading("What I have kept, and what I let go", style)}\n${indent(body)}`;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// ── the briefing ─────────────────────────────────────────────────────────────
|
|
317
|
+
|
|
318
|
+
function briefingBlock(src: DashboardSource, style: Style): string {
|
|
319
|
+
// `self.wake()` is a pure read (self/ §1 G8: no model, no network, no write).
|
|
320
|
+
// Only its SHAPE is printed — the briefing text itself belongs in the wake
|
|
321
|
+
// bundle, not in an instrument's output.
|
|
322
|
+
const wake = src.self.wake();
|
|
323
|
+
const line = wake.ok
|
|
324
|
+
? `I have a briefing composed and waiting: ${plural(wake.bytes, "byte")}.`
|
|
325
|
+
: style.warn(`I have no briefing waiting to give (${wake.reason}).`);
|
|
326
|
+
return `${subheading("What I would say on waking", style)}\n${indent(line)}`;
|
|
327
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `stories` — how a belief changed its mind, told as a story.
|
|
3
|
+
*
|
|
4
|
+
* The keep (CONTRACT §3, review finding 1): the challenge-pressure log rendered
|
|
5
|
+
* as a watchable narrative per contested belief. v1 had the arithmetic and lost
|
|
6
|
+
* the explanation — the pressure NUMBER survived a restart while the story of how
|
|
7
|
+
* it got there did not, which is why `schemas/` now appends every credited
|
|
8
|
+
* increment to box 2's durable `events` table (SEAMS item K). This view is that
|
|
9
|
+
* table, read back.
|
|
10
|
+
*
|
|
11
|
+
* Five things per challenge, exactly as the task states them: **lived day,
|
|
12
|
+
* challenger, force, bar, verdict.**
|
|
13
|
+
*
|
|
14
|
+
* The verdict is DERIVED, not looked up, because there is no durable verdict
|
|
15
|
+
* event — `revision.pressure` is the only event name anything in the core
|
|
16
|
+
* appends today. The derivation is the same arithmetic physics used at the time:
|
|
17
|
+
* `pressureAfter >= bar` is a crossing, and a crossing is a revision. When the
|
|
18
|
+
* lineage confirms it, the successor is resolved at render time and printed, so
|
|
19
|
+
* the story ends in what the belief BECAME rather than in a number.
|
|
20
|
+
*
|
|
21
|
+
* Grouping is by resolved head: a chain challenged at two generations is ONE
|
|
22
|
+
* story about one belief, not two stories about two ids.
|
|
23
|
+
*/
|
|
24
|
+
import { isJournal } from "../../core/sleep/index.js";
|
|
25
|
+
import { PLAIN } from "./ansi.js";
|
|
26
|
+
import type { Style } from "./ansi.js";
|
|
27
|
+
import { NONE, heading, indent, num, plural, stack, subheading, table } from "./layout.js";
|
|
28
|
+
import { resolveRef } from "./resolve.js";
|
|
29
|
+
import type { DashboardSource } from "./source.js";
|
|
30
|
+
|
|
31
|
+
/** The durable increment's event name. Written by `schemas/challengeBelief` and
|
|
32
|
+
* by `core/revision.ts`'s identity arm, in the same shape — so an identity
|
|
33
|
+
* element's story renders here without this file knowing there are two. */
|
|
34
|
+
export const PRESSURE_EVENT = "revision.pressure";
|
|
35
|
+
|
|
36
|
+
export const DEFAULT_STORY_LIMIT = 10;
|
|
37
|
+
|
|
38
|
+
export interface StoriesOptions {
|
|
39
|
+
readonly style?: Style;
|
|
40
|
+
/** Tell one belief's story. Any id in the chain finds the whole chain. */
|
|
41
|
+
readonly id?: string;
|
|
42
|
+
readonly limit?: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Every belief that has ever been argued with: the refs of the durable pressure
|
|
47
|
+
* events, plus any row still carrying pressure (a challenge credited before the
|
|
48
|
+
* durable log existed, or one whose event was pruned). Union, then grouped.
|
|
49
|
+
*/
|
|
50
|
+
export function contestedBeliefs(src: DashboardSource): string[][] {
|
|
51
|
+
const store = src.store;
|
|
52
|
+
const candidates = new Set<string>();
|
|
53
|
+
for (const row of store.eventLog({ name: PRESSURE_EVENT, limit: 1000 })) {
|
|
54
|
+
if (row.ref !== null) candidates.add(row.ref);
|
|
55
|
+
}
|
|
56
|
+
for (const id of store.list()) {
|
|
57
|
+
const row = store.row(id);
|
|
58
|
+
// `list()` returns the whole `memories` table, episodes included. An episode
|
|
59
|
+
// is a journal entry, not a belief: nothing argues with the account of a day,
|
|
60
|
+
// and a pressure column it somehow carried would open a story with no
|
|
61
|
+
// challenge log behind it. Skipped the way `status.ts` skips it.
|
|
62
|
+
if (row === undefined || isJournal(row)) continue;
|
|
63
|
+
if (row.pressure > 0) candidates.add(id);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Group by the live head. The chain each candidate walks is what decides which
|
|
67
|
+
// of them is the ROOT — the longest chain starts furthest back.
|
|
68
|
+
const groups = new Map<string, { id: string; length: number }[]>();
|
|
69
|
+
for (const id of candidates) {
|
|
70
|
+
const chain: string[] = [];
|
|
71
|
+
let cursor: string | undefined = id;
|
|
72
|
+
while (cursor !== undefined && !chain.includes(cursor)) {
|
|
73
|
+
chain.push(cursor);
|
|
74
|
+
cursor = store.row(cursor)?.superseded_by ?? undefined;
|
|
75
|
+
}
|
|
76
|
+
const head = chain[chain.length - 1] ?? id;
|
|
77
|
+
const group = groups.get(head) ?? [];
|
|
78
|
+
group.push({ id, length: chain.length });
|
|
79
|
+
groups.set(head, group);
|
|
80
|
+
}
|
|
81
|
+
return [...groups.entries()]
|
|
82
|
+
.sort((a, b) => (a[0] < b[0] ? -1 : 1))
|
|
83
|
+
.map(([head, members]) => {
|
|
84
|
+
const root = [...members].sort((a, b) => b.length - a.length || (a.id < b.id ? -1 : 1))[0];
|
|
85
|
+
return [root?.id ?? head, head];
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function renderStories(src: DashboardSource, opts: StoriesOptions = {}): string {
|
|
90
|
+
const style = opts.style ?? PLAIN;
|
|
91
|
+
const limit = opts.limit ?? DEFAULT_STORY_LIMIT;
|
|
92
|
+
const groups = opts.id === undefined ? contestedBeliefs(src) : [[opts.id, opts.id]];
|
|
93
|
+
|
|
94
|
+
if (groups.length === 0) {
|
|
95
|
+
return stack(
|
|
96
|
+
heading("How my beliefs have changed", style),
|
|
97
|
+
style.warn(
|
|
98
|
+
`${NONE} — nothing I hold has been argued with. No belief has taken a single credited challenge.`,
|
|
99
|
+
),
|
|
100
|
+
"That is a real answer, not an empty panel: a store with no contested belief has never had one, and this line is how I say so.",
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const told = groups.slice(0, limit).map(([root]) => oneStory(src, root ?? "", style));
|
|
105
|
+
const footer =
|
|
106
|
+
groups.length > limit
|
|
107
|
+
? `${plural(groups.length, "contested belief")}; showing ${limit}. Ask for one with \`stories --id <id>\`.`
|
|
108
|
+
: `${plural(groups.length, "contested belief")}, all shown.`;
|
|
109
|
+
|
|
110
|
+
return stack(heading("How my beliefs have changed", style), ...told, footer);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ── one belief's story ───────────────────────────────────────────────────────
|
|
114
|
+
|
|
115
|
+
function oneStory(src: DashboardSource, rootId: string, style: Style): string {
|
|
116
|
+
const store = src.store;
|
|
117
|
+
const story = src.schemas.story(rootId);
|
|
118
|
+
const head = resolveRef(store, story.headId);
|
|
119
|
+
const origin = resolveRef(store, rootId, { follow: false });
|
|
120
|
+
|
|
121
|
+
// The entity this belief is about, resolved now — a story with no subject is
|
|
122
|
+
// a column of floats.
|
|
123
|
+
const entityId = (() => {
|
|
124
|
+
try {
|
|
125
|
+
return store.readProse(story.headId).meta["entityId"];
|
|
126
|
+
} catch {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
})();
|
|
130
|
+
const about =
|
|
131
|
+
typeof entityId === "string" ? resolveRef(store, entityId).label : `${NONE} (no entity named)`;
|
|
132
|
+
|
|
133
|
+
const revised = story.headId !== rootId;
|
|
134
|
+
const facts: string[][] = [
|
|
135
|
+
["about", about],
|
|
136
|
+
// UNFOLLOWED on purpose: the retained prose at the original address is what
|
|
137
|
+
// "it began as" means, and it is read here, now — not carried from anywhere.
|
|
138
|
+
["it began as", origin.label],
|
|
139
|
+
["it now says", revised ? head.label : "the same thing — nothing has revised it"],
|
|
140
|
+
[
|
|
141
|
+
"pressure standing",
|
|
142
|
+
story.pressure === 0
|
|
143
|
+
? revised
|
|
144
|
+
? `${NONE} — the revision reset it; the successor starts clean`
|
|
145
|
+
: `${NONE} — the pressure has decayed, or was never credited`
|
|
146
|
+
: `${num(story.pressure)} against a bar of ${num(story.bar)}` +
|
|
147
|
+
(story.lastChallengedDay === null
|
|
148
|
+
? ""
|
|
149
|
+
: `, last argued with on day ${story.lastChallengedDay}`),
|
|
150
|
+
],
|
|
151
|
+
["strength of the belief now", num(story.strength)],
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
const beats = story.increments
|
|
155
|
+
.slice()
|
|
156
|
+
.sort((a, b) => a.day - b.day)
|
|
157
|
+
.map((inc) => {
|
|
158
|
+
const challenger = resolveRef(store, inc.challengerId, 52);
|
|
159
|
+
const crossed = inc.pressureAfter >= inc.bar;
|
|
160
|
+
// The lineage confirms the crossing and names what it became. Matched on
|
|
161
|
+
// the TARGET's own supersession row rather than on dates: the challenge
|
|
162
|
+
// day is the caller's lived day and the version day is the store's, and
|
|
163
|
+
// a story must not depend on those two agreeing. A crossing with no
|
|
164
|
+
// lineage row is still reported — that mismatch is worth seeing.
|
|
165
|
+
const step = story.lineage.find((l) => l.id === inc.targetId && l.successorId !== null);
|
|
166
|
+
const verdict = crossed
|
|
167
|
+
? step === undefined || step.successorId === null
|
|
168
|
+
? style.warn("crossed the bar — but I find no supersession recorded")
|
|
169
|
+
: `${style.bold("REVISED")}, becoming ${resolveRef(store, step.successorId, 52).label}`
|
|
170
|
+
: "held";
|
|
171
|
+
return [
|
|
172
|
+
`day ${inc.day}`,
|
|
173
|
+
`challenged by ${challenger.label}`,
|
|
174
|
+
`force ${num(inc.force)}`,
|
|
175
|
+
`pressure ${num(inc.pressureAfter)} of ${num(inc.bar)}`,
|
|
176
|
+
verdict,
|
|
177
|
+
];
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const log =
|
|
181
|
+
beats.length === 0
|
|
182
|
+
? indent(
|
|
183
|
+
style.warn(
|
|
184
|
+
`${NONE} — this belief carries pressure but I hold no credited challenge for it. Its increments predate the durable log, or were pruned.`,
|
|
185
|
+
),
|
|
186
|
+
)
|
|
187
|
+
: indent(table(beats));
|
|
188
|
+
|
|
189
|
+
return stack(
|
|
190
|
+
subheading(`Belief ${rootId}`, style),
|
|
191
|
+
indent(table(facts)),
|
|
192
|
+
`${indent(subheading("Every credited challenge, in the order it landed", style))}\n${log}`,
|
|
193
|
+
);
|
|
194
|
+
}
|