@phren/cli 0.1.42 → 0.1.45

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.
Files changed (97) hide show
  1. package/dist/capabilities/cli.js +1 -1
  2. package/dist/capabilities/mcp.js +1 -1
  3. package/dist/capabilities/vscode.js +3 -3
  4. package/dist/capabilities/web-ui.js +29 -29
  5. package/dist/cli/actions.d.ts +1 -1
  6. package/dist/cli/actions.js +7 -2
  7. package/dist/cli/config-proactivity.d.ts +6 -6
  8. package/dist/cli/hooks-output.js +15 -6
  9. package/dist/cli/hooks.d.ts +1 -1
  10. package/dist/cli/hooks.js +16 -5
  11. package/dist/cli/session-stop.d.ts +1 -1
  12. package/dist/cli/session-tool-hook.d.ts +1 -1
  13. package/dist/cli-registry.js +1 -1
  14. package/dist/data/access.js +2 -1
  15. package/dist/generated/memory-ui-graph.browser.js +481 -318
  16. package/dist/governance/locks.js +6 -0
  17. package/dist/governance/scores.d.ts +9 -1
  18. package/dist/governance/scores.js +12 -1
  19. package/dist/graph-core/index.d.ts +2 -0
  20. package/dist/graph-core/index.js +2 -0
  21. package/dist/graph-core/model.d.ts +84 -0
  22. package/dist/graph-core/model.js +355 -0
  23. package/dist/graph-core/types.d.ts +110 -0
  24. package/dist/graph-core/types.js +43 -0
  25. package/dist/index.js +4 -1
  26. package/dist/init/init-uninstall.d.ts +1 -0
  27. package/dist/init/init-uninstall.js +13 -3
  28. package/dist/init/setup.js +11 -4
  29. package/dist/link/context.js +2 -1
  30. package/dist/link/link.js +3 -2
  31. package/dist/link/skills.js +2 -1
  32. package/dist/memory-ui-graph.runtime.js +481 -318
  33. package/dist/phren-core.d.ts +16 -0
  34. package/dist/phren-core.js +21 -0
  35. package/dist/phren-paths.js +8 -4
  36. package/dist/profile-store.d.ts +2 -0
  37. package/dist/profile-store.js +16 -19
  38. package/dist/project-config.js +2 -1
  39. package/dist/shared/fragment-graph.js +7 -2
  40. package/dist/shared/index.js +1 -1
  41. package/dist/shared/retrieval.d.ts +38 -0
  42. package/dist/shared/retrieval.js +62 -4
  43. package/dist/shell/entry.d.ts +10 -2
  44. package/dist/shell/entry.js +128 -97
  45. package/dist/shell/graph/canvas.d.ts +64 -0
  46. package/dist/shell/graph/canvas.js +256 -0
  47. package/dist/shell/graph/controller.d.ts +164 -0
  48. package/dist/shell/graph/controller.js +645 -0
  49. package/dist/shell/graph/glyphs.d.ts +12 -0
  50. package/dist/shell/graph/glyphs.js +31 -0
  51. package/dist/shell/graph/graph-view.d.ts +12 -0
  52. package/dist/shell/graph/graph-view.js +408 -0
  53. package/dist/shell/graph/layout.d.ts +68 -0
  54. package/dist/shell/graph/layout.js +267 -0
  55. package/dist/shell/input.d.ts +4 -1
  56. package/dist/shell/input.js +28 -5
  57. package/dist/shell/intro.d.ts +37 -0
  58. package/dist/shell/intro.js +82 -0
  59. package/dist/shell/keys.d.ts +36 -0
  60. package/dist/shell/keys.js +107 -0
  61. package/dist/shell/logo-fx.d.ts +35 -0
  62. package/dist/shell/logo-fx.js +128 -0
  63. package/dist/shell/render.d.ts +34 -1
  64. package/dist/shell/render.js +220 -66
  65. package/dist/shell/shell.d.ts +13 -1
  66. package/dist/shell/shell.js +61 -10
  67. package/dist/shell/startup.d.ts +37 -0
  68. package/dist/shell/startup.js +105 -0
  69. package/dist/shell/state-store.d.ts +1 -1
  70. package/dist/shell/state-store.js +1 -1
  71. package/dist/shell/types.js +1 -0
  72. package/dist/shell/view.d.ts +3 -0
  73. package/dist/shell/view.js +26 -4
  74. package/dist/store-registry.d.ts +13 -0
  75. package/dist/store-registry.js +109 -37
  76. package/dist/test-global-setup.d.ts +1 -0
  77. package/dist/test-global-setup.js +22 -0
  78. package/dist/tool-registry.js +1 -0
  79. package/dist/tools/memory.js +12 -5
  80. package/dist/tools/ops.js +1 -1
  81. package/dist/ui/data.d.ts +15 -7
  82. package/dist/ui/data.js +102 -3
  83. package/dist/utils-fts.js +2 -1
  84. package/dist/utils-helpers.d.ts +1 -0
  85. package/dist/utils-helpers.js +6 -0
  86. package/dist/utils.d.ts +1 -1
  87. package/dist/utils.js +1 -1
  88. package/package.json +38 -7
  89. package/starter/global/skills/phren-consolidate/SKILL.md +152 -0
  90. package/starter/global/skills/phren-discover/SKILL.md +175 -0
  91. package/starter/global/skills/phren-init/SKILL.md +216 -0
  92. package/starter/global/skills/phren-profiles/SKILL.md +121 -0
  93. package/starter/global/skills/phren-sync/SKILL.md +261 -0
  94. package/dist/init-uninstall.d.ts +0 -3
  95. package/dist/init-uninstall.js +0 -514
  96. package/dist/init-walkthrough.d.ts +0 -55
  97. package/dist/init-walkthrough.js +0 -524
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Renders the terminal graph view: a braille force-graph canvas with a
3
+ * details pane beside it (or a strip beneath it on narrow terminals).
4
+ *
5
+ * Mirrors the web viewer's layout — canvas left, contents pane right — and
6
+ * its colour language: nodes take their topic/kind colour, the selection is
7
+ * amber, search dims everything that does not match.
8
+ */
9
+ import type { GraphController } from "./controller.js";
10
+ /** Word-wrap plain text to `width` cells, at most `maxLines` lines, ellipsised. */
11
+ export declare function wrapText(text: string, width: number, maxLines: number): string[];
12
+ export declare function renderGraphView(controller: GraphController, width: number, height: number): string[];
@@ -0,0 +1,408 @@
1
+ /**
2
+ * Renders the terminal graph view: a braille force-graph canvas with a
3
+ * details pane beside it (or a strip beneath it on narrow terminals).
4
+ *
5
+ * Mirrors the web viewer's layout — canvas left, contents pane right — and
6
+ * its colour language: nodes take their topic/kind colour, the selection is
7
+ * amber, search dims everything that does not match.
8
+ */
9
+ import { ACCENT_AMBER, ACCENT_CYAN, BG_COLOR, KIND_COLORS } from "../../graph-core/types.js";
10
+ import { nodeRank } from "../../graph-core/model.js";
11
+ import { displayWidth, padToWidth, style } from "../render.js";
12
+ import { BrailleCanvas, blendHex, hexToSgr } from "./canvas.js";
13
+ import { graphGlyphs } from "./glyphs.js";
14
+ const PANE_WIDTH = 34;
15
+ const WIDE_BREAKPOINT = 100;
16
+ const NARROW_STRIP_ROWS = 6;
17
+ const DIM_TARGET = "#3a3f55";
18
+ /** Resolved per frame so PHREN_ICONS is honoured without a restart. */
19
+ let KIND_GLYPH = graphGlyphs();
20
+ const KIND_LABEL = {
21
+ project: "project",
22
+ finding: "finding",
23
+ task: "task",
24
+ entity: "fragment",
25
+ reference: "reference",
26
+ other: "node",
27
+ };
28
+ const HEALTH_COLOR = {
29
+ healthy: "#3ae374",
30
+ decaying: "#ffb648",
31
+ stale: "#ff5470",
32
+ };
33
+ function sgr(hex, extra = "") {
34
+ return `${hexToSgr(hex)}${extra}`;
35
+ }
36
+ function colored(hex, text) {
37
+ return `${hexToSgr(hex)}${text}\x1b[0m`;
38
+ }
39
+ /** Word-wrap plain text to `width` cells, at most `maxLines` lines, ellipsised. */
40
+ export function wrapText(text, width, maxLines) {
41
+ const words = text.split(/\s+/).filter(Boolean);
42
+ const lines = [];
43
+ let current = "";
44
+ for (const word of words) {
45
+ const candidate = current ? `${current} ${word}` : word;
46
+ if (displayWidth(candidate) <= width) {
47
+ current = candidate;
48
+ continue;
49
+ }
50
+ if (current)
51
+ lines.push(current);
52
+ current = displayWidth(word) > width ? `${sliceWidth(word, width - 1)}…` : word;
53
+ if (lines.length >= maxLines)
54
+ break;
55
+ }
56
+ if (current && lines.length < maxLines)
57
+ lines.push(current);
58
+ if (lines.length > maxLines)
59
+ lines.length = maxLines;
60
+ const complete = lines.join(" ") === words.join(" ");
61
+ if (lines.length === maxLines && !complete && !lines[maxLines - 1].endsWith("…")) {
62
+ const last = lines[maxLines - 1];
63
+ lines[maxLines - 1] = displayWidth(last) >= width ? `${sliceWidth(last, width - 1)}…` : `${last}…`;
64
+ }
65
+ return lines;
66
+ }
67
+ function sliceWidth(text, width) {
68
+ let out = "";
69
+ let used = 0;
70
+ for (const ch of text) {
71
+ const w = displayWidth(ch);
72
+ if (used + w > width)
73
+ break;
74
+ out += ch;
75
+ used += w;
76
+ }
77
+ return out;
78
+ }
79
+ /** Braille radius for a node from its viewer size. */
80
+ function dotRadius(node, selected) {
81
+ const base = node.kind === "project" ? 3 : node.size >= 16 ? 2 : node.size >= 10 ? 1 : 0;
82
+ return selected ? base + 1 : base;
83
+ }
84
+ export function renderGraphView(controller, width, height) {
85
+ KIND_GLYPH = graphGlyphs();
86
+ if (controller.status === "loading" || controller.status === "idle")
87
+ return centered(width, height, [
88
+ colored(ACCENT_CYAN, "⠿ building your knowledge graph…"),
89
+ style.dim("scanning findings, tasks, fragments and references"),
90
+ ]);
91
+ if (controller.status === "error")
92
+ return centered(width, height, [
93
+ style.boldRed("graph build failed"),
94
+ style.dim(controller.errorText || "unknown error"),
95
+ style.dim("press r to retry"),
96
+ ]);
97
+ if (controller.status === "empty")
98
+ return centered(width, height, [
99
+ style.bold("nothing to draw yet"),
100
+ style.dim("add a project and some findings, then come back"),
101
+ ]);
102
+ const wide = width >= WIDE_BREAKPOINT;
103
+ const selected = controller.selectedId ? controller.model.nodeById.get(controller.selectedId) ?? null : null;
104
+ const stripRows = !wide && selected ? NARROW_STRIP_ROWS : 0;
105
+ const canvasCols = wide ? width - PANE_WIDTH - 1 : width;
106
+ const canvasRows = Math.max(4, height - 1 - stripRows);
107
+ const canvas = drawCanvas(controller, canvasCols, canvasRows, selected);
108
+ const legend = padToWidth(renderLegend(controller, canvasCols), canvasCols);
109
+ const canvasLines = [...canvas, legend];
110
+ if (wide) {
111
+ const pane = renderPane(controller, selected, PANE_WIDTH, canvasRows + 1);
112
+ const divider = style.dim("│");
113
+ return canvasLines.map((line, i) => `${line}${divider}${padToWidth(pane[i] ?? "", PANE_WIDTH)}`);
114
+ }
115
+ const strip = selected ? renderStrip(controller, selected, width, stripRows) : [];
116
+ return [...canvasLines, ...strip.map((line) => padToWidth(line, width))];
117
+ }
118
+ function centered(width, height, lines) {
119
+ const out = [];
120
+ const top = Math.max(0, Math.floor((height - lines.length) / 2));
121
+ for (let i = 0; i < height; i++) {
122
+ const line = lines[i - top];
123
+ if (!line) {
124
+ out.push(" ".repeat(width));
125
+ continue;
126
+ }
127
+ const pad = Math.max(0, Math.floor((width - displayWidth(line)) / 2));
128
+ out.push(padToWidth(" ".repeat(pad) + line, width));
129
+ }
130
+ return out;
131
+ }
132
+ function drawCanvas(controller, cols, rows, selected) {
133
+ const canvas = new BrailleCanvas(cols, rows);
134
+ controller.setViewport(canvas.dotWidth, canvas.dotHeight);
135
+ const positions = controller.positions;
136
+ const searching = Boolean(controller.search.query);
137
+ const matches = controller.search.matchIds;
138
+ const placed = [];
139
+ const projected = new Map();
140
+ for (const node of controller.visible.nodes) {
141
+ const p = positions.get(node.id);
142
+ if (!p)
143
+ continue;
144
+ const d = controller.project(p);
145
+ projected.set(node.id, d);
146
+ placed.push({ node, x: d.x, y: d.y });
147
+ }
148
+ const isLit = (id) => !searching || matches.has(id);
149
+ // Edges first so node dots win the cell colour.
150
+ for (const link of controller.visible.links) {
151
+ const a = projected.get(link.source);
152
+ const b = projected.get(link.target);
153
+ if (!a || !b)
154
+ continue;
155
+ const touchesSelected = selected !== null && (link.source === selected.id || link.target === selected.id);
156
+ const color = edgeColor(controller, link, touchesSelected, isLit(link.source) && isLit(link.target));
157
+ canvas.line(a.x, a.y, b.x, b.y, color, { z: touchesSelected ? 2 : 0, dotted: link.kind === "contradicts" });
158
+ }
159
+ for (const { node, x, y } of placed) {
160
+ const isSelected = selected?.id === node.id;
161
+ let color = node.baseColor;
162
+ if (isSelected)
163
+ color = ACCENT_AMBER;
164
+ else if (searching && !matches.has(node.id))
165
+ color = blendHex(node.baseColor, DIM_TARGET, 0.7);
166
+ canvas.disc(x, y, dotRadius(node, isSelected), color, isSelected ? 4 : node.kind === "project" ? 3 : 1);
167
+ }
168
+ // Glyphs + labels live in the overlay so they are never eaten by dots.
169
+ // Labelling policy: projects, the selection and the current search hit are
170
+ // always named; the selection's neighbours get their 1-9 jump number; other
171
+ // leaves are named only while there is room (zoomed in, or a search has
172
+ // thinned the field) and only where the text does not cover other nodes.
173
+ const neighborIndex = new Map();
174
+ if (selected)
175
+ controller.neighborsOf(selected.id).slice(0, 9).forEach((node, i) => neighborIndex.set(node.id, i + 1));
176
+ const currentHit = searching ? controller.search.results[controller.search.index]?.id : undefined;
177
+ const zoomedIn = controller.camera.scale >= 5;
178
+ const ranked = placed.slice().sort((a, b) => labelPriority(controller, b.node, selected, neighborIndex) - labelPriority(controller, a.node, selected, neighborIndex));
179
+ const labelBudget = searching ? 14 : zoomedIn ? Math.max(8, Math.floor((cols * rows) / 60)) : Math.max(4, Math.floor((cols * rows) / 220));
180
+ let labels = 0;
181
+ for (const { node, x, y } of ranked) {
182
+ const col = Math.floor(x / 2);
183
+ const row = Math.floor(y / 4);
184
+ if (col < 0 || col >= cols || row < 0 || row >= rows)
185
+ continue;
186
+ const isSelected = selected?.id === node.id;
187
+ const lit = isLit(node.id);
188
+ const glyphColor = isSelected ? ACCENT_AMBER : lit ? node.baseColor : blendHex(node.baseColor, DIM_TARGET, 0.7);
189
+ const number = neighborIndex.get(node.id);
190
+ if (isSelected)
191
+ canvas.putText(col, row, "◆", sgr(ACCENT_AMBER, "\x1b[1m"));
192
+ else if (node.kind === "project")
193
+ canvas.putText(col, row, KIND_GLYPH.project, sgr(glyphColor, "\x1b[1m"));
194
+ else if (number !== undefined)
195
+ canvas.putText(col, row, String(number), sgr(ACCENT_CYAN, "\x1b[1m"));
196
+ const forced = node.forceLabel || isSelected || node.id === currentHit;
197
+ const wanted = forced || number !== undefined || (lit && labels < labelBudget && (zoomedIn || searching));
198
+ if (!wanted)
199
+ continue;
200
+ const maxLabel = node.kind === "project" ? 20 : number !== undefined ? 14 : 18;
201
+ const text = sliceWidth(node.label, maxLabel);
202
+ const w = displayWidth(text);
203
+ const labelSgr = isSelected
204
+ ? `${hexToSgr(BG_COLOR)}\x1b[48;2;255;209;102m\x1b[1m`
205
+ : node.kind === "project"
206
+ ? sgr(glyphColor, "\x1b[1m")
207
+ : number !== undefined
208
+ ? sgr(lit ? blendHex(node.baseColor, "#ffffff", 0.35) : blendHex(node.baseColor, DIM_TARGET, 0.6))
209
+ : sgr(lit ? blendHex(node.baseColor, "#ffffff", 0.2) : blendHex(node.baseColor, DIM_TARGET, 0.6));
210
+ const slots = [[col + 2, row], [col - w - 1, row], [col + 2, row - 1], [col + 2, row + 1], [col - w - 1, row - 1], [col - w - 1, row + 1]];
211
+ // Clean slots first (no text, no dots); forced labels may cover dots as a last resort.
212
+ const placedAt = slots.find(([c, r]) => canvas.isFree(c, r, w, true)) ?? (forced ? slots.find(([c, r]) => canvas.isFree(c, r, w)) : undefined);
213
+ if (!placedAt)
214
+ continue;
215
+ canvas.putText(placedAt[0], placedAt[1], text, labelSgr);
216
+ if (!forced)
217
+ labels++;
218
+ }
219
+ if (controller.refreshing) {
220
+ const badge = " ⟳ refreshing ";
221
+ canvas.putText(cols - displayWidth(badge), 0, badge, sgr(ACCENT_CYAN, "\x1b[2m"));
222
+ }
223
+ return canvas.render();
224
+ }
225
+ function edgeColor(controller, link, touchesSelected, lit) {
226
+ if (touchesSelected)
227
+ return ACCENT_AMBER;
228
+ let base;
229
+ if (link.kind === "fragment")
230
+ base = blendHex(ACCENT_CYAN, BG_COLOR, 0.45);
231
+ else if (link.kind === "contradicts")
232
+ base = "#ff5470";
233
+ else if (link.kind === "supersedes")
234
+ base = "#8a93b8";
235
+ else {
236
+ const leaf = controller.model.nodeById.get(link.target)?.kind === "project" ? link.source : link.target;
237
+ const node = controller.model.nodeById.get(leaf);
238
+ base = blendHex(node?.baseColor ?? KIND_COLORS.other, BG_COLOR, 0.55);
239
+ }
240
+ return lit ? base : blendHex(base, BG_COLOR, 0.6);
241
+ }
242
+ function labelPriority(controller, node, selected, neighborIndex) {
243
+ let score = nodeRank(node, controller.filters, controller.model.scores);
244
+ if (selected?.id === node.id)
245
+ score += 100000;
246
+ if (node.kind === "project")
247
+ score += 50000;
248
+ if (neighborIndex.has(node.id))
249
+ score += 30000 - (neighborIndex.get(node.id) ?? 0);
250
+ if (controller.search.matchIds.has(node.id))
251
+ score += 20000;
252
+ return score;
253
+ }
254
+ function renderLegend(controller, width) {
255
+ const counts = { project: 0, finding: 0, task: 0, entity: 0, reference: 0, other: 0 };
256
+ for (const node of controller.visible.nodes)
257
+ counts[node.kind]++;
258
+ const parts = [];
259
+ const entry = (kind, color) => {
260
+ if (!counts[kind])
261
+ return;
262
+ parts.push(`${colored(color, KIND_GLYPH[kind])} ${style.dim(`${counts[kind]} ${KIND_LABEL[kind]}${counts[kind] === 1 ? "" : "s"}`)}`);
263
+ };
264
+ entry("project", KIND_COLORS.project);
265
+ entry("finding", "#46c8ff");
266
+ entry("task", KIND_COLORS["task-active"]);
267
+ entry("entity", KIND_COLORS.entity);
268
+ entry("reference", KIND_COLORS.reference);
269
+ const edges = controller.visible.links.length;
270
+ parts.push(style.dim(`${edges} edge${edges === 1 ? "" : "s"}`));
271
+ let line = ` ${parts.join(style.dim(" · "))}`;
272
+ if (displayWidth(line) > width)
273
+ line = ` ${parts.join(style.dim(" · "))}`;
274
+ return line;
275
+ }
276
+ function healthDot(node) {
277
+ return `${colored(HEALTH_COLOR[node.health], "●")} ${node.health}`;
278
+ }
279
+ function renderPane(controller, selected, width, height) {
280
+ const inner = width - 2;
281
+ const lines = [];
282
+ const push = (line = "") => { if (lines.length < height)
283
+ lines.push(` ${line}`); };
284
+ const row = (label, value) => push(`${style.dim(label.padEnd(9))}${value}`);
285
+ if (selected) {
286
+ const detail = controller.detail(selected.id);
287
+ push(`${colored(selected.kind === "project" ? KIND_COLORS.project : selected.baseColor, KIND_GLYPH[selected.kind])} ${style.bold(KIND_LABEL[selected.kind])}${selected.kind === "task" && selected.section ? style.dim(` ${selected.section.toLowerCase()}`) : ""}`);
288
+ for (const line of wrapText(selected.fullLabel || selected.label, inner, 4))
289
+ push(line);
290
+ push();
291
+ if (selected.kind !== "project" && selected.project)
292
+ row("project", style.cyan(selected.project));
293
+ if (selected.kind === "project") {
294
+ row("findings", String(selected.findingCount ?? 0));
295
+ row("tasks", String(selected.taskCount ?? 0));
296
+ if (selected.store && selected.store !== "primary")
297
+ row("store", selected.store);
298
+ }
299
+ if (selected.topicLabel || selected.topicSlug)
300
+ row("topic", colored(selected.baseColor, selected.topicLabel || selected.topicSlug || ""));
301
+ if (selected.entityType)
302
+ row("type", selected.entityType);
303
+ if (selected.priority)
304
+ row("priority", selected.priority);
305
+ if (selected.date)
306
+ row("date", selected.date);
307
+ row("health", healthDot(selected));
308
+ if (detail?.qualityScore != null)
309
+ row("quality", `${Math.round(detail.qualityScore * 100)}%`);
310
+ if (detail?.score?.helpful)
311
+ row("helpful", `${detail.score.helpful}×`);
312
+ if (detail) {
313
+ const c = detail.connections;
314
+ const bits = [
315
+ c.projects ? `${c.projects} proj` : "",
316
+ c.findings ? `${c.findings} find` : "",
317
+ c.tasks ? `${c.tasks} task` : "",
318
+ c.entities ? `${c.entities} frag` : "",
319
+ c.references ? `${c.references} ref` : "",
320
+ ].filter(Boolean);
321
+ row("links", `${c.total}${bits.length ? style.dim(` ${bits.join(" ")}`) : ""}`);
322
+ }
323
+ const docs = (selected.refDocs ?? []).map((ref) => ref.doc);
324
+ if (docs.length && selected.kind !== "finding" && selected.kind !== "task") {
325
+ row("docs", sliceWidth(docs[0], inner - 9));
326
+ for (const doc of docs.slice(1, 3))
327
+ push(`${" ".repeat(9)}${sliceWidth(doc, inner - 9)}`);
328
+ if (docs.length > 3)
329
+ push(`${" ".repeat(9)}${style.dim(`+${docs.length - 3} more`)}`);
330
+ }
331
+ const neighbors = controller.neighborsOf(selected.id);
332
+ if (neighbors.length) {
333
+ push();
334
+ push(style.dim(`neighbours ${style.dim(`(1-9 jump)`)}`));
335
+ const budget = Math.max(0, height - lines.length - 1);
336
+ neighbors.slice(0, Math.min(9, budget)).forEach((node, i) => {
337
+ push(`${style.boldCyan(String(i + 1))} ${colored(node.baseColor, KIND_GLYPH[node.kind])} ${sliceWidth(node.label, inner - 4)}`);
338
+ });
339
+ if (neighbors.length > 9)
340
+ push(style.dim(` +${neighbors.length - 9} more`));
341
+ }
342
+ }
343
+ else {
344
+ const total = controller.model.rawNodes.length;
345
+ const shown = controller.visible.nodes.length;
346
+ push(`${colored(ACCENT_CYAN, "❖")} ${style.bold("knowledge graph")}${controller.refreshing ? style.dim(" ⟳") : ""}`);
347
+ push(style.dim(shown === total ? `${shown} nodes · ${controller.visible.links.length} edges` : `${shown} of ${total} nodes · ${controller.visible.links.length} edges`));
348
+ push();
349
+ row("filter", `${controller.preset.name}${style.dim(" f")}`);
350
+ row("focus", `${controller.focusedProject ? style.cyan(controller.focusedProject) : style.dim("all projects")}${style.dim(" [ ]")}`);
351
+ row("search", controller.search.query
352
+ ? `${style.yellow(controller.search.query)} ${style.dim(`${controller.search.results.length} hit${controller.search.results.length === 1 ? "" : "s"}`)}`
353
+ : `${style.dim("—")}${style.dim(" /")}`);
354
+ push();
355
+ const projects = controller.projects;
356
+ if (projects.length) {
357
+ push(style.dim("projects"));
358
+ const budget = Math.max(0, height - lines.length - 9);
359
+ for (const project of projects.slice(0, budget)) {
360
+ const name = project.project || project.id;
361
+ const isFocus = controller.focusedProject === name;
362
+ push(`${colored(project.baseColor, KIND_GLYPH.project)} ${isFocus ? style.boldCyan(sliceWidth(name, inner - 12)) : sliceWidth(name, inner - 12)} ${style.dim(`${project.findingCount ?? 0}✦ ${project.taskCount ?? 0}▤`)}`);
363
+ }
364
+ if (projects.length > budget)
365
+ push(style.dim(` +${projects.length - budget} more`));
366
+ push();
367
+ }
368
+ const k = (s) => style.boldCyan(s);
369
+ const d = (s) => style.dim(s);
370
+ push(`${k("↑↓←→")} ${d("walk")} ${k("↵")} ${d("select")}`);
371
+ push(`${k("1-9")} ${d("jump to neighbour")}`);
372
+ push(`${k("/")} ${d("search")} ${k("n")}${d("/")}${k("N")} ${d("next/prev")}`);
373
+ push(`${k("f")} ${d("filter")} ${k("[ ]")} ${d("project")}`);
374
+ push(`${k("+ -")} ${d("zoom")} ${k("0")} ${d("fit")} ${k("r")} ${d("relayout")}`);
375
+ push(`${k("⇧↑↓←→")} ${d("pan")} ${k("o")} ${d("3D viewer")}`);
376
+ }
377
+ while (lines.length < height)
378
+ lines.push("");
379
+ return lines.slice(0, height);
380
+ }
381
+ function renderStrip(controller, selected, width, rows) {
382
+ const detail = controller.detail(selected.id);
383
+ const lines = [];
384
+ const head = [
385
+ `${colored(selected.baseColor, KIND_GLYPH[selected.kind])} ${style.bold(KIND_LABEL[selected.kind])}`,
386
+ selected.project && selected.kind !== "project" ? style.cyan(selected.project) : "",
387
+ selected.topicLabel || selected.topicSlug || "",
388
+ healthDot(selected),
389
+ detail ? style.dim(`${detail.connections.total} links`) : "",
390
+ ].filter(Boolean);
391
+ lines.push(` ${head.join(style.dim(" · "))}`);
392
+ for (const line of wrapText(selected.fullLabel || selected.label, width - 2, 2))
393
+ lines.push(` ${line}`);
394
+ const neighbors = controller.neighborsOf(selected.id).slice(0, 9);
395
+ if (neighbors.length) {
396
+ const items = neighbors.map((node, i) => `${style.boldCyan(String(i + 1))} ${colored(node.baseColor, KIND_GLYPH[node.kind])} ${sliceWidth(node.label, 14)}`);
397
+ let line = " ";
398
+ for (const item of items) {
399
+ if (displayWidth(line + item) + 2 > width)
400
+ break;
401
+ line += `${item} `;
402
+ }
403
+ lines.push(line.trimEnd());
404
+ }
405
+ while (lines.length < rows)
406
+ lines.push("");
407
+ return lines.slice(0, rows);
408
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Deterministic 2D force layout for the terminal graph view.
3
+ *
4
+ * The web viewer leans on 3d-force-graph; in the terminal we want something
5
+ * dependency-free, fast enough for a few hundred nodes, and — above all —
6
+ * deterministic, so the same store draws the same map every time the view
7
+ * opens. All jitter is derived from node ids via `seeded()`; nothing here
8
+ * calls Math.random.
9
+ *
10
+ * The store's topology is a star (project → findings/tasks/fragments/refs),
11
+ * so the simulation adds a gentle pull toward each node's home project. That
12
+ * keeps clusters readable instead of letting repulsion smear everything into
13
+ * one ring.
14
+ */
15
+ import type { NodeKind, RawLink } from "../../graph-core/types.js";
16
+ export interface LayoutNode {
17
+ id: string;
18
+ kind: NodeKind;
19
+ /** Owning project name, for the cluster pull. Projects own themselves. */
20
+ project?: string;
21
+ /** Visual size from `sizeForNode`; drives repulsion mass. */
22
+ size: number;
23
+ }
24
+ export interface Point {
25
+ x: number;
26
+ y: number;
27
+ }
28
+ /** Ideal edge length in world units. Everything else is scaled off this. */
29
+ export declare const IDEAL_DISTANCE = 12;
30
+ /**
31
+ * Starting positions: projects on a ring, leaves in a jittered blob around
32
+ * their home project, multi-home fragments at the centroid of their homes,
33
+ * orphans on an outer ring.
34
+ */
35
+ export declare function seedPositions(nodes: LayoutNode[], links: RawLink[]): Map<string, Point>;
36
+ export declare class ForceSim {
37
+ readonly positions: Map<string, Point>;
38
+ private readonly ids;
39
+ private readonly index;
40
+ private readonly mass;
41
+ private readonly anchors;
42
+ private readonly isProject;
43
+ private readonly links;
44
+ private temperature;
45
+ private readonly startTemperature;
46
+ constructor(nodes: LayoutNode[], links: RawLink[], seed?: Map<string, Point>);
47
+ /** 1 at the start, 0 when settled; mirrors d3's `alpha` for hosts that animate. */
48
+ get alpha(): number;
49
+ get settled(): boolean;
50
+ /**
51
+ * Reuse a previous layout's positions for nodes that survived a data
52
+ * refresh, and reheat only mildly so the map shifts instead of scrambling.
53
+ */
54
+ warmStart(previous: Map<string, Point>): void;
55
+ /** Reheat to the initial temperature (e.g. the `r` relayout key). */
56
+ reheat(): void;
57
+ tick(count?: number): void;
58
+ /** Run until settled or the tick budget is spent. */
59
+ settle(maxTicks?: number): void;
60
+ private step;
61
+ }
62
+ /** Axis-aligned bounds of a position set; null when empty. */
63
+ export declare function bounds(positions: Iterable<Point>): {
64
+ minX: number;
65
+ minY: number;
66
+ maxX: number;
67
+ maxY: number;
68
+ } | null;