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,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain-text layout: headings, aligned tables, meters, side-by-side columns —
|
|
3
|
+
* and the ABSENCE VOCABULARY, which is the load-bearing part of this file.
|
|
4
|
+
*
|
|
5
|
+
* The totality test (CONTRACT §3, scar §2.17) is only as good as the marker it
|
|
6
|
+
* looks for. v1's curation starvation hid because a panel with nothing in it
|
|
7
|
+
* rendered as nothing at all, which reads as "quiet" rather than "never fired".
|
|
8
|
+
* So every axis that has no data prints one of the tokens below, on the axis's
|
|
9
|
+
* own line, and `test/dashboard.test.ts` asserts per-axis coverage against the
|
|
10
|
+
* live registries rather than against a copied list.
|
|
11
|
+
*
|
|
12
|
+
* `NEVER` and `NONE` are different records on purpose: "was never asked" and
|
|
13
|
+
* "was asked and the answer is zero" are the distinction scar §2.4 is about.
|
|
14
|
+
*/
|
|
15
|
+
import { visibleWidth } from "./ansi.js";
|
|
16
|
+
import type { Style } from "./ansi.js";
|
|
17
|
+
|
|
18
|
+
/** The axis exists, it has been evaluated, and its count is zero. */
|
|
19
|
+
export const NONE = "(none yet)";
|
|
20
|
+
/** The axis exists and has never run / never been asked. Not the same as zero. */
|
|
21
|
+
export const NEVER = "(never run)";
|
|
22
|
+
/** A value the store holds but this render could not resolve to anything. */
|
|
23
|
+
export const UNRESOLVED = "(unresolved)";
|
|
24
|
+
|
|
25
|
+
export const ABSENCE_TOKENS = [NONE, NEVER, UNRESOLVED] as const;
|
|
26
|
+
|
|
27
|
+
export const DEFAULT_WIDTH = 88;
|
|
28
|
+
|
|
29
|
+
export function heading(text: string, style: Style): string {
|
|
30
|
+
const rule = "─".repeat(Math.max(visibleWidth(text), 1));
|
|
31
|
+
return `${style.bold(text)}\n${style.dim(rule)}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function subheading(text: string, style: Style): string {
|
|
35
|
+
return style.bold(text);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function indent(text: string, by = 2): string {
|
|
39
|
+
const pad = " ".repeat(by);
|
|
40
|
+
return text
|
|
41
|
+
.split("\n")
|
|
42
|
+
.map((line) => (line.length === 0 ? line : pad + line))
|
|
43
|
+
.join("\n");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function pad(text: string, width: number): string {
|
|
47
|
+
const gap = width - visibleWidth(text);
|
|
48
|
+
return gap <= 0 ? text : text + " ".repeat(gap);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function padStart(text: string, width: number): string {
|
|
52
|
+
const gap = width - visibleWidth(text);
|
|
53
|
+
return gap <= 0 ? text : " ".repeat(gap) + text;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Truncation is announced with an ellipsis — a silently cut line is a lie. */
|
|
57
|
+
export function truncate(text: string, width: number): string {
|
|
58
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
59
|
+
if (flat.length <= width) return flat;
|
|
60
|
+
return width <= 1 ? flat.slice(0, width) : `${flat.slice(0, width - 1)}…`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface TableOptions {
|
|
64
|
+
/** Column indexes to right-align. Numbers read wrong on the left. */
|
|
65
|
+
readonly right?: readonly number[];
|
|
66
|
+
readonly gap?: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Column-aligned rows. Widths measure VISIBLE characters, so colour is free. */
|
|
70
|
+
export function table(rows: readonly (readonly string[])[], opts: TableOptions = {}): string {
|
|
71
|
+
if (rows.length === 0) return "";
|
|
72
|
+
const gap = " ".repeat(opts.gap ?? 2);
|
|
73
|
+
const right = new Set(opts.right ?? []);
|
|
74
|
+
const columns = Math.max(...rows.map((r) => r.length));
|
|
75
|
+
const widths: number[] = [];
|
|
76
|
+
for (let c = 0; c < columns; c++) {
|
|
77
|
+
widths.push(Math.max(...rows.map((r) => visibleWidth(r[c] ?? ""))));
|
|
78
|
+
}
|
|
79
|
+
return rows
|
|
80
|
+
.map((row) =>
|
|
81
|
+
row
|
|
82
|
+
.map((cell, c) => {
|
|
83
|
+
const w = widths[c] ?? 0;
|
|
84
|
+
// The last cell is never padded: trailing spaces are invisible noise
|
|
85
|
+
// that makes byte-for-byte assertions annoying for no reader's gain.
|
|
86
|
+
if (c === row.length - 1) return cell;
|
|
87
|
+
return right.has(c) ? padStart(cell, w) : pad(cell, w);
|
|
88
|
+
})
|
|
89
|
+
.join(gap)
|
|
90
|
+
.replace(/\s+$/, ""),
|
|
91
|
+
)
|
|
92
|
+
.join("\n");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A proportion, drawn. Deliberately coarse: this is a glance instrument, and a
|
|
97
|
+
* bar precise enough to read a number off would be a number badly printed.
|
|
98
|
+
*/
|
|
99
|
+
export function meter(fraction: number, width = 10): string {
|
|
100
|
+
const clamped = fraction < 0 ? 0 : fraction > 1 ? 1 : fraction;
|
|
101
|
+
const filled = Math.round(clamped * width);
|
|
102
|
+
return "█".repeat(filled) + "░".repeat(width - filled);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Two decimals, always — a strength that prints as `0.6` and `0.60` on
|
|
106
|
+
* neighbouring lines makes a column unreadable. */
|
|
107
|
+
export function num(x: number, places = 2): string {
|
|
108
|
+
return Number.isFinite(x) ? x.toFixed(places) : "—";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface ColumnsOptions {
|
|
112
|
+
readonly gap?: number;
|
|
113
|
+
readonly width?: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Two blocks, side by side — the identity/protected pair, whose whole point is
|
|
118
|
+
* being read TOGETHER (self/identity.ts, scar §2.19). Falls back to stacking
|
|
119
|
+
* when the terminal is too narrow to hold both honestly.
|
|
120
|
+
*/
|
|
121
|
+
export function columns(left: string, right: string, opts: ColumnsOptions = {}): string {
|
|
122
|
+
const gap = opts.gap ?? 4;
|
|
123
|
+
const total = opts.width ?? DEFAULT_WIDTH;
|
|
124
|
+
const leftLines = left.split("\n");
|
|
125
|
+
const rightLines = right.split("\n");
|
|
126
|
+
const leftWidth = Math.max(...leftLines.map(visibleWidth), 0);
|
|
127
|
+
const rightWidth = Math.max(...rightLines.map(visibleWidth), 0);
|
|
128
|
+
if (leftWidth + gap + rightWidth > total) {
|
|
129
|
+
return `${left}\n\n${right}`;
|
|
130
|
+
}
|
|
131
|
+
const rows = Math.max(leftLines.length, rightLines.length);
|
|
132
|
+
const out: string[] = [];
|
|
133
|
+
for (let i = 0; i < rows; i++) {
|
|
134
|
+
const l = leftLines[i] ?? "";
|
|
135
|
+
const r = rightLines[i] ?? "";
|
|
136
|
+
out.push(`${pad(l, leftWidth)}${" ".repeat(gap)}${r}`.replace(/\s+$/, ""));
|
|
137
|
+
}
|
|
138
|
+
return out.join("\n");
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Blocks separated by exactly one blank line, empties dropped. */
|
|
142
|
+
export function stack(...blocks: (string | null)[]): string {
|
|
143
|
+
return blocks.filter((b): b is string => b !== null && b.length > 0).join("\n\n");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** `1 memory` / `2 memories` — the brain voice does not print `1 memories`. */
|
|
147
|
+
export function plural(n: number, one: string, many = `${one}s`): string {
|
|
148
|
+
return `${n} ${n === 1 ? one : many}`;
|
|
149
|
+
}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The axes the totality test enumerates (CONTRACT §3 / §5 [M]).
|
|
3
|
+
*
|
|
4
|
+
* The rule this file exists to keep: **a new axis in the core must break
|
|
5
|
+
* something here, at compile time, before it can go missing on screen.** v1's
|
|
6
|
+
* curation starvation hid inside a panel nobody rendered, and a hand-copied list
|
|
7
|
+
* of kinds in a dashboard would reproduce that exactly — it would keep rendering
|
|
8
|
+
* five kinds forever after a sixth was born.
|
|
9
|
+
*
|
|
10
|
+
* So none of these three lists is a copy:
|
|
11
|
+
*
|
|
12
|
+
* - `KINDS` is `Object.keys(PHYSICS.TUNABLES.KINDS)`. That object is declared
|
|
13
|
+
* `satisfies Record<Kind, KindPhysics>` in `physics/`, so it IS the registry;
|
|
14
|
+
* reading its keys cannot go stale.
|
|
15
|
+
* - `BANDS` has no runtime registry in the core (`Band` is a bare union), so
|
|
16
|
+
* the order map below is declared `satisfies Record<Band, number>`. A band
|
|
17
|
+
* added to `core/types.ts` fails `tsc` HERE until it is given a position, and
|
|
18
|
+
* a band removed fails too. `INTERFACE-GAPS.md` §1 asks the core for the
|
|
19
|
+
* array so this workaround can be deleted.
|
|
20
|
+
* - `PHASES` is `sleep/`'s own exported tuple, imported, never restated.
|
|
21
|
+
*/
|
|
22
|
+
import { TUNABLES as PHYSICS } from "../../core/physics/index.js";
|
|
23
|
+
import type { PromotionCrossing, PruneRecord } from "../../core/physics/index.js";
|
|
24
|
+
import { PHASES } from "../../core/sleep/index.js";
|
|
25
|
+
import type { MergeRecord, Phase } from "../../core/sleep/index.js";
|
|
26
|
+
// A TYPE import, erased at runtime: the caller-universality test's own rule
|
|
27
|
+
// (`test/cli.test.ts`) is that a type import reaches no function on that seam.
|
|
28
|
+
import type { UnmergeRecord } from "../../core/store/owner-op-seam.js";
|
|
29
|
+
import type { PressureIncrement } from "../../core/schemas/index.js";
|
|
30
|
+
import type { Band, Kind } from "../../core/types.js";
|
|
31
|
+
import {
|
|
32
|
+
ADAPTER_ASK_EVENT,
|
|
33
|
+
ASSOCIATE_FLUSH_EVENT,
|
|
34
|
+
AUTHORSHIP_ASK_EVENT,
|
|
35
|
+
BOUNDARY_EVENT,
|
|
36
|
+
CHECKOUT_EVENT,
|
|
37
|
+
EMBED_BACKFILL_EVENT,
|
|
38
|
+
EPISODE_ASK_EVENT,
|
|
39
|
+
GATE_CHUNK_EVENT,
|
|
40
|
+
GATE_DEPOSIT_EVENT,
|
|
41
|
+
PRIMACY_DELIVER_EVENT,
|
|
42
|
+
PRIMACY_STANDDOWN_EVENT,
|
|
43
|
+
RECALL_CREDIT_EVENT,
|
|
44
|
+
RECALL_DECISION_EVENT,
|
|
45
|
+
RECALL_DELIVERED_EVENT,
|
|
46
|
+
RUNNER_FAILED_EVENT,
|
|
47
|
+
SELF_BRIEFING_EVENT,
|
|
48
|
+
SEMANTIC_LAG_EVENT,
|
|
49
|
+
SLEEP_CYCLE_EVENT,
|
|
50
|
+
SNAPSHOT_FAILED_EVENT,
|
|
51
|
+
SNAPSHOT_ROTATED_EVENT,
|
|
52
|
+
SNAPSHOT_TAKEN_EVENT,
|
|
53
|
+
MCP_RECALL_EVENT,
|
|
54
|
+
SPAWN_FAILED_EVENT,
|
|
55
|
+
SPAWN_REFUSED_EVENT,
|
|
56
|
+
SPAWN_STARTED_EVENT,
|
|
57
|
+
STORE_EXPORT_EVENT,
|
|
58
|
+
SWEEP_GATE_EVENT,
|
|
59
|
+
SWEEP_WAKE_EVENT,
|
|
60
|
+
WAKE_DELIVERED_EVENT,
|
|
61
|
+
WAKE_INJECTED_EVENT,
|
|
62
|
+
} from "../../core/counterpart.js";
|
|
63
|
+
import { BAND_TRANSITION_EVENT } from "../../core/sleep/index.js";
|
|
64
|
+
// Prospective memory's two (2026-09-20, E2). The module had no durable row at
|
|
65
|
+
// all: `fires` is a column, so the store could say a window had ever fired and
|
|
66
|
+
// never when, or why one did not.
|
|
67
|
+
import {
|
|
68
|
+
PROSPECTIVE_FIRE_EVENT,
|
|
69
|
+
PROSPECTIVE_REFUSED_EVENT,
|
|
70
|
+
} from "../../core/prospective/index.js";
|
|
71
|
+
// The self page's two, from `self/` itself (2026-09-18, S1): a written page is
|
|
72
|
+
// not a briefing render, and a refused write is not an accepted one.
|
|
73
|
+
import {
|
|
74
|
+
JOURNAL_COPY_FAILED_EVENT,
|
|
75
|
+
JOURNAL_COPY_WRITTEN_EVENT,
|
|
76
|
+
SELF_PAGE_REFUSED_EVENT,
|
|
77
|
+
SELF_PAGE_REVISED_EVENT,
|
|
78
|
+
SELF_PAGE_WRITER_EVENT,
|
|
79
|
+
} from "../../core/self/index.js";
|
|
80
|
+
// The per-directory handoff's four, from `handoff/` itself (2026-09-20, E1):
|
|
81
|
+
// working context for a place is not a memory, so its rows are its own.
|
|
82
|
+
import {
|
|
83
|
+
HANDOFF_CLEARED_EVENT,
|
|
84
|
+
HANDOFF_REFUSED_EVENT,
|
|
85
|
+
HANDOFF_SHOWN_EVENT,
|
|
86
|
+
HANDOFF_WRITTEN_EVENT,
|
|
87
|
+
} from "../../core/handoff/index.js";
|
|
88
|
+
|
|
89
|
+
/** Display order for the bands, weakest commitment first. EXHAUSTIVE BY TYPE. */
|
|
90
|
+
const BAND_ORDER = {
|
|
91
|
+
episodic: 0,
|
|
92
|
+
semantic: 1,
|
|
93
|
+
identity: 2,
|
|
94
|
+
} as const satisfies Record<Band, number>;
|
|
95
|
+
|
|
96
|
+
export const BANDS: readonly Band[] = (Object.keys(BAND_ORDER) as Band[]).sort(
|
|
97
|
+
(a, b) => BAND_ORDER[a] - BAND_ORDER[b],
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
/** Every kind physics knows how to move. Derived from the physics registry. */
|
|
101
|
+
export const KINDS: readonly Kind[] = Object.keys(PHYSICS.KINDS) as Kind[];
|
|
102
|
+
|
|
103
|
+
/** Every phase the cycle runs, in the cycle's own order. */
|
|
104
|
+
export const CYCLE_PHASES: readonly Phase[] = PHASES;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Every event name that reaches box 2's `events` table — the DURABLE log, the
|
|
108
|
+
* one that survives the process. Its writers today: `sleep/`'s consolidate,
|
|
109
|
+
* prune, dedup and decay phases, `schemas/`'s credited challenge and
|
|
110
|
+
* `core/revision.ts`'s identity arm (the same name, the same shape, the same
|
|
111
|
+
* dedup latch — a story does not care which arm moved the row), the
|
|
112
|
+
* composition root's four records — the chunk gate's, the AUTHORED gate's (both
|
|
113
|
+
* doors of one battery, added 2026-09-05 with replay §2a), one per turn's
|
|
114
|
+
* surfacing decision, and one per crash-fallback run's gate, whose ordinary
|
|
115
|
+
* answer is "nothing crashed" and which is therefore the one record here
|
|
116
|
+
* written to prove a SILENCE — and the one narrow seam an ADAPTER may write
|
|
117
|
+
* through (`Counterpart.noteAdapterEvent`, typed on `AdapterDurableEventName`).
|
|
118
|
+
*
|
|
119
|
+
* EXHAUSTIVE BY TYPE, the same way `BAND_ORDER` is. Each record interface
|
|
120
|
+
* declares its `event` as a string literal; the `satisfies` below is keyed on
|
|
121
|
+
* the union of those literals, so one more durable record type — or a renamed
|
|
122
|
+
* literal — fails `tsc` here rather than quietly never appearing in the feed.
|
|
123
|
+
* That is the totality test applied to the log itself: "consolidation has
|
|
124
|
+
* promoted nothing, ever" must be a line the owner can read, not an empty space
|
|
125
|
+
* (scar §2.17, §2.4). The adapter seam is typed rather than `name: string` for
|
|
126
|
+
* exactly this reason.
|
|
127
|
+
*/
|
|
128
|
+
export type DurableEventName =
|
|
129
|
+
| PromotionCrossing["event"]
|
|
130
|
+
| PruneRecord["event"]
|
|
131
|
+
| MergeRecord["event"]
|
|
132
|
+
| UnmergeRecord["event"]
|
|
133
|
+
| PressureIncrement["event"]
|
|
134
|
+
| typeof GATE_CHUNK_EVENT
|
|
135
|
+
| typeof GATE_DEPOSIT_EVENT
|
|
136
|
+
| typeof RECALL_DECISION_EVENT
|
|
137
|
+
| typeof SWEEP_GATE_EVENT
|
|
138
|
+
| typeof SWEEP_WAKE_EVENT
|
|
139
|
+
| typeof SLEEP_CYCLE_EVENT
|
|
140
|
+
| typeof SELF_BRIEFING_EVENT
|
|
141
|
+
| typeof SELF_PAGE_REVISED_EVENT
|
|
142
|
+
| typeof SELF_PAGE_REFUSED_EVENT
|
|
143
|
+
| typeof SELF_PAGE_WRITER_EVENT
|
|
144
|
+
| typeof HANDOFF_WRITTEN_EVENT
|
|
145
|
+
| typeof HANDOFF_SHOWN_EVENT
|
|
146
|
+
| typeof HANDOFF_REFUSED_EVENT
|
|
147
|
+
| typeof HANDOFF_CLEARED_EVENT
|
|
148
|
+
| typeof RECALL_CREDIT_EVENT
|
|
149
|
+
| typeof ASSOCIATE_FLUSH_EVENT
|
|
150
|
+
| typeof BAND_TRANSITION_EVENT
|
|
151
|
+
| typeof PRIMACY_STANDDOWN_EVENT
|
|
152
|
+
| typeof PRIMACY_DELIVER_EVENT
|
|
153
|
+
| typeof WAKE_INJECTED_EVENT
|
|
154
|
+
| typeof WAKE_DELIVERED_EVENT
|
|
155
|
+
| typeof RECALL_DELIVERED_EVENT
|
|
156
|
+
| typeof EPISODE_ASK_EVENT
|
|
157
|
+
| typeof BOUNDARY_EVENT
|
|
158
|
+
| typeof AUTHORSHIP_ASK_EVENT
|
|
159
|
+
| typeof ADAPTER_ASK_EVENT
|
|
160
|
+
| typeof EMBED_BACKFILL_EVENT
|
|
161
|
+
| typeof SEMANTIC_LAG_EVENT
|
|
162
|
+
| typeof SPAWN_REFUSED_EVENT
|
|
163
|
+
| typeof SPAWN_FAILED_EVENT
|
|
164
|
+
| typeof SPAWN_STARTED_EVENT
|
|
165
|
+
| typeof RUNNER_FAILED_EVENT
|
|
166
|
+
| typeof MCP_RECALL_EVENT
|
|
167
|
+
| typeof CHECKOUT_EVENT
|
|
168
|
+
| typeof SNAPSHOT_TAKEN_EVENT
|
|
169
|
+
| typeof SNAPSHOT_FAILED_EVENT
|
|
170
|
+
| typeof SNAPSHOT_ROTATED_EVENT
|
|
171
|
+
| typeof PROSPECTIVE_FIRE_EVENT
|
|
172
|
+
| typeof PROSPECTIVE_REFUSED_EVENT
|
|
173
|
+
| typeof JOURNAL_COPY_WRITTEN_EVENT
|
|
174
|
+
| typeof JOURNAL_COPY_FAILED_EVENT
|
|
175
|
+
| typeof STORE_EXPORT_EVENT;
|
|
176
|
+
|
|
177
|
+
export const DURABLE_EVENTS = {
|
|
178
|
+
"adapter.ask": "the Stop ask was evaluated (asked, paced out, or capped for the day)",
|
|
179
|
+
// The two names below are HISTORICAL: until 2026-09-04 the blocked moment
|
|
180
|
+
// carried two asks on two pacers and each left its own row. Nothing writes
|
|
181
|
+
// them now; they stay in the vocabulary so the days recorded under them are
|
|
182
|
+
// still readable, which is what a feed the owner can trust requires (§16).
|
|
183
|
+
"adapter.authorship.ask": "HISTORICAL: the authorship half of the old two-ask Stop",
|
|
184
|
+
"adapter.boundary": "a session-ending path reached the boundary (spans captured, cursor moved)",
|
|
185
|
+
"adapter.embed.backfill": "the worker gave vectors to memories that had none (embedded, remaining, failed)",
|
|
186
|
+
"adapter.semantic.lag": "the worker left next turn's semantic cue (or named why it could not)",
|
|
187
|
+
// The spawn seam's three, durable since 2026-09-11 (I32): for a week the
|
|
188
|
+
// worker was refused at every boundary and the only record was a ring that
|
|
189
|
+
// died with the hook process. One row per reason per date.
|
|
190
|
+
"adapter.runner.failed": "the detached worker failed after opening the store (which step, and the code)",
|
|
191
|
+
"adapter.spawn.failed": "the detached worker could not be started at all (the OS said why)",
|
|
192
|
+
"adapter.spawn.refused": "the detached worker was not started, by name (and how many times running)",
|
|
193
|
+
// The other half of those three (2026-09-20, E2): until it existed, a worker
|
|
194
|
+
// dead all week and a week with nothing to do left the same nothing.
|
|
195
|
+
"adapter.spawn.started": "the detached worker DID start, at least once today (one row per date, with the day's count)",
|
|
196
|
+
// The deliberate look's first durable row (2026-09-20, E2). The whole MCP tool
|
|
197
|
+
// surface wrote nothing, so a session that asked and got nothing and a session
|
|
198
|
+
// that never asked were the same silence.
|
|
199
|
+
"mcp.recall": "the session went looking for a memory on purpose (what kind of ask, how much came back, and every verdict that kept something out)",
|
|
200
|
+
// Which CODE was live at a session start (2026-09-14): the hooks run whatever
|
|
201
|
+
// the install tree has checked out, so a peer session's unmerged branch in
|
|
202
|
+
// that tree is the memory layer the owner is using.
|
|
203
|
+
"adapter.checkout": "which checkout the hooks were running at session start (branch, short sha, tracked modifications)",
|
|
204
|
+
"adapter.episode.ask": "HISTORICAL: the episode half of the old two-ask Stop",
|
|
205
|
+
"adapter.primacy.deliver": "a hook delivered while the parallel run was on",
|
|
206
|
+
"adapter.primacy.standdown": "a hook withheld delivery so the other system could speak",
|
|
207
|
+
"adapter.recall": "a turn's recall was composed for injection (counts and bytes)",
|
|
208
|
+
"adapter.wake.delivered": "the previous wake's arrival was checked on the next turn",
|
|
209
|
+
"adapter.wake.injected": "a wake bundle was handed to the host (bytes, never text)",
|
|
210
|
+
"band.promoted": "a memory crossed into the identity band",
|
|
211
|
+
"band.transition": "a memory changed bands (the symmetry counter's food)",
|
|
212
|
+
"gate.chunk": "a swept chunk met the gate battery",
|
|
213
|
+
"gate.deposit": "an authored deposit met the gate battery (which gates acted, and what they refused)",
|
|
214
|
+
"memory.pruned": "a memory was let go at the floor",
|
|
215
|
+
"memory.merged": "a duplicate was merged into its original",
|
|
216
|
+
"memory.unmerged": "the owner put back a row a merge had archived (repair-merged-beliefs)",
|
|
217
|
+
"recall.decision": "a turn decided what came to mind (and what stayed quiet)",
|
|
218
|
+
"revision.pressure": "a belief or an identity element took a credited challenge",
|
|
219
|
+
"sweep.gate": "the crash fallback ran its gate (scopes looked at, every scope's refusal counted by reason, spans swept)",
|
|
220
|
+
"sweep.wake": "the crash fallback was woken as me before it read a transcript (whether a self went, its size, what the cap trimmed, what was held back)",
|
|
221
|
+
// The two U9 rows: until 2026-09-14 the whole sleep cycle and the whole wake
|
|
222
|
+
// render lived in an in-process ring that died with the worker, so "did the
|
|
223
|
+
// cycle run today, did every phase succeed, what did the wake trim" could not
|
|
224
|
+
// be answered from the store at all.
|
|
225
|
+
"sleep.cycle": "the consolidation cycle ran (every phase by name, with its status, and the run's counts)",
|
|
226
|
+
"self.briefing": "the wake briefing was re-rendered (what rendered per lane, and which elements the trim dropped)",
|
|
227
|
+
// The page's two (2026-09-18, S1). The refusal has a row of its own because a
|
|
228
|
+
// cap reports what it refused where the owner will see it (owner ruling 2's
|
|
229
|
+
// corollary): the 196 refused asks sat in the events table unseen.
|
|
230
|
+
"self.page.revised": "the written self page was amended (who wrote it, why, how big, and which version it produced)",
|
|
231
|
+
"self.page.refused": "a write to the self page was turned away (empty, past the hard limit, stopped by the gate battery, carrying the wake's own markers, or naming a version the page has moved past)",
|
|
232
|
+
// The nightly writer's own row (2026-09-20, S2). It is a row per ATTEMPT, not
|
|
233
|
+
// per revision: the page's row says what changed, and this one says whether
|
|
234
|
+
// the night ran at all, in which mode, and what it came to — including the
|
|
235
|
+
// day it read and had nothing to say about, which is an answer and not a
|
|
236
|
+
// silence.
|
|
237
|
+
"self.page.writer.ran": "the nightly page writer ran (which day it read, in which mode, how many memories it was handed, and whether it revised the page, had nothing to say, was refused or failed)",
|
|
238
|
+
// The handoff's four (2026-09-20, E1). Written and shown are separate rows
|
|
239
|
+
// for scar §2.3's reason, one lane along: "we wrote one" is not "a session
|
|
240
|
+
// was handed one", and a pointer that stops being delivered is exactly the
|
|
241
|
+
// failure a single row would hide.
|
|
242
|
+
"handoff.written": "a session left a handoff for the next one in that directory (how big, which version, and how long it will show)",
|
|
243
|
+
"handoff.shown": "a session opening in that directory was handed the pointer to its handoff (how old it was, and what it cost the wake)",
|
|
244
|
+
"handoff.cleared": "a session finished the work in a directory and retired its handoff, so the next one there is handed nothing (how big the retired one was, and which version)",
|
|
245
|
+
"handoff.refused": "a handoff was turned away (past the hard limit, stopped by the gate battery, carrying the wake's own markers, written where no directory was named, sent as something other than text, or — with `no-room` — composed before the wake had room reserved for its pointer)",
|
|
246
|
+
"recall.credit": "a boundary decided which memories the replies actually used, and credited them",
|
|
247
|
+
// Learned association had no line in the log at all: an edge is its own
|
|
248
|
+
// record, so a flush that never happened read exactly like a credit pass with
|
|
249
|
+
// nothing to wire (2026-09-17, mechanism inventory §3 S3).
|
|
250
|
+
"associate.flush": "the boundary's worker wired together the memories its sessions credited together (passes carried, pairs, edge rows written, evictions)",
|
|
251
|
+
// The daily rotating snapshot (2026-09-18). Until it existed, a backup that
|
|
252
|
+
// had run and one that never had were the same silence.
|
|
253
|
+
"snapshot.taken": "a copy of the whole store was made and kept (which one, how many files, how many are kept, the oldest)",
|
|
254
|
+
"snapshot.failed": "a copy could not be made (which step, and why) — the store is unharmed, and the worker carried on",
|
|
255
|
+
"snapshot.rotated": "old copies were let go so the newest 14 remain (which ones went, and how many are left)",
|
|
256
|
+
// Remembering to act (2026-09-20, E2), in two names so a refusal can never be
|
|
257
|
+
// counted as a firing.
|
|
258
|
+
"prospective.fire": "a future date arrived and the reminder was offered into the turn (which window, and how much of its budget is left)",
|
|
259
|
+
"prospective.fire.refused": "a reminder was NOT offered (which brake held — one row per window per reason per lived day)",
|
|
260
|
+
// The journal's markdown copy and the hand export (2026-09-20, F6 and F7):
|
|
261
|
+
// the two places the constitution's "prose the owner can view" is kept now
|
|
262
|
+
// that every body is a column.
|
|
263
|
+
"journal.copy.written": "a chapter's markdown copy was written beside the store, so the diary is readable in any editor (which episode, which file, how big)",
|
|
264
|
+
"journal.copy.failed": "a chapter's markdown copy could not be written (which episode, and the reason code) — the chapter itself is safe in the database",
|
|
265
|
+
"store.export": "the owner exported the store by hand (which kind of export, how many rows went, how many confidential ones were left out)",
|
|
266
|
+
} as const satisfies Record<DurableEventName, string>;
|
|
267
|
+
|
|
268
|
+
export const DURABLE_EVENT_NAMES: readonly DurableEventName[] = Object.keys(
|
|
269
|
+
DURABLE_EVENTS,
|
|
270
|
+
) as DurableEventName[];
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* What one axis reports. `absent` is a fact about the axis, not a formatting
|
|
274
|
+
* hint: the renderer prints the absence marker when it is true, and the test
|
|
275
|
+
* asserts the pairing (a nonzero axis marked absent is a bug either way).
|
|
276
|
+
*/
|
|
277
|
+
export interface AxisCount {
|
|
278
|
+
readonly axis: string;
|
|
279
|
+
readonly count: number;
|
|
280
|
+
readonly absent: boolean;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export function countBy<T extends string>(
|
|
284
|
+
registry: readonly T[],
|
|
285
|
+
counts: ReadonlyMap<T, number>,
|
|
286
|
+
): AxisCount[] {
|
|
287
|
+
return registry.map((axis) => {
|
|
288
|
+
const count = counts.get(axis) ?? 0;
|
|
289
|
+
return { axis, count, absent: count === 0 };
|
|
290
|
+
});
|
|
291
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render-time id resolution — the keep this adapter would be dishonest without
|
|
3
|
+
* (CONTRACT §3, scar §2.20; v1's dashboard batch).
|
|
4
|
+
*
|
|
5
|
+
* The rule: **nothing printed here is text that was stored alongside an id.**
|
|
6
|
+
* Every id the dashboard shows goes through `resolveRef` at the moment of
|
|
7
|
+
* rendering, and what comes back is either the CURRENT text at that address or a
|
|
8
|
+
* NAMED absence. So an owner-removed memory stops appearing the instant it is
|
|
9
|
+
* removed, a superseded belief prints what it became rather than what it said,
|
|
10
|
+
* and a dangling pointer says it is dangling instead of quietly showing the last
|
|
11
|
+
* thing anyone happened to cache.
|
|
12
|
+
*
|
|
13
|
+
* Every path is read-only and every failure is a value, never a throw: this runs
|
|
14
|
+
* in an instrument, and an instrument that crashes on a broken store is the one
|
|
15
|
+
* moment the owner most needs it to render (`observer-mode.md`, scar E7).
|
|
16
|
+
*/
|
|
17
|
+
import { StoreError } from "../../core/store/index.js";
|
|
18
|
+
import type { ProseDoc, Store } from "../../core/store/index.js";
|
|
19
|
+
import { truncate } from "./layout.js";
|
|
20
|
+
|
|
21
|
+
export type RefState =
|
|
22
|
+
/** Resolves, is the live head, is not archived. */
|
|
23
|
+
| "live"
|
|
24
|
+
/** Resolves, but the address forwards: what it BECAME is what we print. */
|
|
25
|
+
| "superseded"
|
|
26
|
+
/** Resolves and is the head, but archived (pruned, merged, faded). */
|
|
27
|
+
| "archived"
|
|
28
|
+
/** No such row. The commonest honest absence. */
|
|
29
|
+
| "unknown"
|
|
30
|
+
/** The owner removed it. The deny list answers before the prose does. */
|
|
31
|
+
| "removed"
|
|
32
|
+
/** A forwarding address whose destination is gone. */
|
|
33
|
+
| "dangling"
|
|
34
|
+
/** A forwarding loop, or one too deep to walk. */
|
|
35
|
+
| "broken"
|
|
36
|
+
/** The row is there and the prose is not readable. */
|
|
37
|
+
| "unreadable"
|
|
38
|
+
/** No id was given at all. */
|
|
39
|
+
| "none";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The named absences, in the system's own voice. They are WORDS, not blanks:
|
|
43
|
+
* a blank is indistinguishable from "nothing was ever here", which is exactly
|
|
44
|
+
* the distinction scar §2.4 refuses to lose.
|
|
45
|
+
*/
|
|
46
|
+
export const ABSENCE: Record<Exclude<RefState, "live" | "superseded" | "archived">, string> = {
|
|
47
|
+
unknown: "[no longer at this address]",
|
|
48
|
+
removed: "[removed by the owner]",
|
|
49
|
+
dangling: "[a forwarding address with nothing at the end]",
|
|
50
|
+
broken: "[a forwarding loop]",
|
|
51
|
+
unreadable: "[here, but unreadable]",
|
|
52
|
+
none: "[nothing named]",
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export interface ResolvedRef {
|
|
56
|
+
/** The id as it was stored — always shown, so the owner can go look. */
|
|
57
|
+
readonly id: string;
|
|
58
|
+
/** The live head this address forwards to, when there is one. */
|
|
59
|
+
readonly headId: string | null;
|
|
60
|
+
readonly state: RefState;
|
|
61
|
+
/** Whether anything is actually there right now. */
|
|
62
|
+
readonly present: boolean;
|
|
63
|
+
/** The CURRENT text at this address, resolved just now. Null when absent. */
|
|
64
|
+
readonly text: string | null;
|
|
65
|
+
/** The whole thing, ready to print. Never persisted anywhere. */
|
|
66
|
+
readonly label: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const TEXT_WIDTH = 64;
|
|
70
|
+
/** Decimal places a telemetry float is printed to. Display only. */
|
|
71
|
+
const FLOAT_PLACES = 3;
|
|
72
|
+
|
|
73
|
+
/** Title if it has one, else its opening line. Never the whole body. */
|
|
74
|
+
export function gistOf(doc: ProseDoc, width = TEXT_WIDTH): string {
|
|
75
|
+
if (typeof doc.title === "string" && doc.title.trim().length > 0) {
|
|
76
|
+
return truncate(doc.title, width);
|
|
77
|
+
}
|
|
78
|
+
const firstProse = doc.body
|
|
79
|
+
.split("\n")
|
|
80
|
+
.map((l) => l.trim())
|
|
81
|
+
.find((l) => l.length > 0 && !l.startsWith("#"));
|
|
82
|
+
return truncate(firstProse ?? doc.body, width);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function errCode(err: unknown): string {
|
|
86
|
+
return err instanceof StoreError ? err.code : "UNREADABLE";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** `resolve()` without the forwarding walk: is there a row at THIS address? */
|
|
90
|
+
function requireHere(store: Store, id: string): string {
|
|
91
|
+
if (store.row(id) === undefined) throw new StoreError("ID_UNKNOWN", { id });
|
|
92
|
+
return id;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface ResolveOptions {
|
|
96
|
+
readonly width?: number;
|
|
97
|
+
/**
|
|
98
|
+
* Follow the forwarding address (the default). `false` resolves the id's OWN
|
|
99
|
+
* current content instead — which is still a render-time read of live state,
|
|
100
|
+
* not baked text: a superseded belief's prose is RETAINED by design (§5 G10,
|
|
101
|
+
* earned live when accommodation's forensics needed the retained element), and
|
|
102
|
+
* "it began as X, it now says Y" is unsayable without reading both ends. An id
|
|
103
|
+
* whose own row is gone still comes back as a named absence.
|
|
104
|
+
*/
|
|
105
|
+
readonly follow?: boolean;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Resolve one id, now. `width` bounds the text, not the truth: a truncated gist
|
|
110
|
+
* ends in an ellipsis so nobody mistakes it for the whole memory.
|
|
111
|
+
*/
|
|
112
|
+
export function resolveRef(
|
|
113
|
+
store: Store,
|
|
114
|
+
id: string | null | undefined,
|
|
115
|
+
widthOrOpts: number | ResolveOptions = TEXT_WIDTH,
|
|
116
|
+
): ResolvedRef {
|
|
117
|
+
const opts: ResolveOptions =
|
|
118
|
+
typeof widthOrOpts === "number" ? { width: widthOrOpts } : widthOrOpts;
|
|
119
|
+
const width = opts.width ?? TEXT_WIDTH;
|
|
120
|
+
const follow = opts.follow !== false;
|
|
121
|
+
|
|
122
|
+
if (typeof id !== "string" || id.trim().length === 0) {
|
|
123
|
+
return { id: "", headId: null, state: "none", present: false, text: null, label: ABSENCE.none };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let headId: string;
|
|
127
|
+
try {
|
|
128
|
+
headId = follow ? store.resolve(id) : requireHere(store, id);
|
|
129
|
+
} catch (err) {
|
|
130
|
+
const code = errCode(err);
|
|
131
|
+
const state: RefState =
|
|
132
|
+
code === "ID_UNKNOWN"
|
|
133
|
+
? "unknown"
|
|
134
|
+
: code === "ID_DANGLING"
|
|
135
|
+
? "dangling"
|
|
136
|
+
: code === "ID_CYCLE" || code === "ID_CHAIN_TOO_DEEP"
|
|
137
|
+
? "broken"
|
|
138
|
+
: "unreadable";
|
|
139
|
+
return {
|
|
140
|
+
id,
|
|
141
|
+
headId: null,
|
|
142
|
+
state,
|
|
143
|
+
present: false,
|
|
144
|
+
text: null,
|
|
145
|
+
label: `${ABSENCE[state as keyof typeof ABSENCE]} ${id}`,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let doc: ProseDoc;
|
|
150
|
+
try {
|
|
151
|
+
doc = store.readProse(headId);
|
|
152
|
+
} catch (err) {
|
|
153
|
+
// REMOVED is the owner's erasure answering before the prose does — the one
|
|
154
|
+
// absence that must never degrade into "unreadable".
|
|
155
|
+
const state: RefState = errCode(err) === "REMOVED" ? "removed" : "unreadable";
|
|
156
|
+
return {
|
|
157
|
+
id,
|
|
158
|
+
headId,
|
|
159
|
+
state,
|
|
160
|
+
present: false,
|
|
161
|
+
text: null,
|
|
162
|
+
label: `${ABSENCE[state as keyof typeof ABSENCE]} ${id}`,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const row = store.row(headId);
|
|
167
|
+
const text = gistOf(doc, width);
|
|
168
|
+
const forwarded = headId !== id;
|
|
169
|
+
const state: RefState = forwarded ? "superseded" : row?.archived === 1 ? "archived" : "live";
|
|
170
|
+
const label = forwarded
|
|
171
|
+
? `"${text}" [${headId}, was ${id}]`
|
|
172
|
+
: state === "archived"
|
|
173
|
+
? `"${text}" [${id}, archived: ${row?.archived_reason ?? "no reason recorded"}]`
|
|
174
|
+
: `"${text}" [${id}]`;
|
|
175
|
+
return { id, headId, state, present: true, text, label };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** True for a string that looks like one of this store's addresses. */
|
|
179
|
+
const ID_SHAPE = /^(?:mem|epi|sch)_[0-9a-z]+$/;
|
|
180
|
+
|
|
181
|
+
export function looksLikeId(value: unknown): value is string {
|
|
182
|
+
return typeof value === "string" && ID_SHAPE.test(value);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Render one telemetry payload. Ids inside it are resolved the same way ids
|
|
187
|
+
* outside it are — that is what "content-by-reference, resolved at render" has
|
|
188
|
+
* to mean for the activity feed, or the feed becomes a wall of hex.
|
|
189
|
+
*/
|
|
190
|
+
export function resolvePayload(
|
|
191
|
+
store: Store,
|
|
192
|
+
payload: Record<string, unknown>,
|
|
193
|
+
width = 40,
|
|
194
|
+
): { key: string; value: string }[] {
|
|
195
|
+
return Object.entries(payload).map(([key, value]) => {
|
|
196
|
+
if (looksLikeId(value)) return { key, value: resolveRef(store, value, width).label };
|
|
197
|
+
if (value === null) return { key, value: "null" };
|
|
198
|
+
// A raw float is telemetry, not a reading: `0.5975142297464837` costs the eye
|
|
199
|
+
// more than it tells it. Integers stay whole.
|
|
200
|
+
if (typeof value === "number") {
|
|
201
|
+
return { key, value: Number.isInteger(value) ? String(value) : value.toFixed(FLOAT_PLACES) };
|
|
202
|
+
}
|
|
203
|
+
if (typeof value === "object") return { key, value: JSON.stringify(value) };
|
|
204
|
+
return { key, value: String(value) };
|
|
205
|
+
});
|
|
206
|
+
}
|