@phren/cli 0.1.45 → 0.1.47

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 (52) hide show
  1. package/dist/agents/providers/herdr.d.ts +18 -0
  2. package/dist/agents/providers/herdr.js +94 -0
  3. package/dist/agents/providers/spawner.d.ts +13 -0
  4. package/dist/agents/providers/spawner.js +63 -0
  5. package/dist/agents/registry.d.ts +28 -0
  6. package/dist/agents/registry.js +82 -0
  7. package/dist/agents/types.d.ts +51 -0
  8. package/dist/agents/types.js +42 -0
  9. package/dist/cli/namespaces-utils.d.ts +5 -0
  10. package/dist/cli/namespaces-utils.js +12 -12
  11. package/dist/cli/search.js +29 -0
  12. package/dist/cli-registry.d.ts +1 -1
  13. package/dist/cli-registry.js +1 -0
  14. package/dist/content/learning.js +24 -1
  15. package/dist/editor/buffer.d.ts +48 -0
  16. package/dist/editor/buffer.js +312 -0
  17. package/dist/editor/launch.d.ts +41 -0
  18. package/dist/editor/launch.js +92 -0
  19. package/dist/editor/save.d.ts +15 -0
  20. package/dist/editor/save.js +70 -0
  21. package/dist/generated/memory-ui-graph.browser.js +69 -69
  22. package/dist/graph-core/model.js +99 -9
  23. package/dist/memory-ui-graph.runtime.js +69 -69
  24. package/dist/phren-art.d.ts +7 -0
  25. package/dist/phren-art.js +6 -41
  26. package/dist/shared/lookup-tail.d.ts +35 -0
  27. package/dist/shared/lookup-tail.js +100 -0
  28. package/dist/shell/editor-view.d.ts +8 -0
  29. package/dist/shell/editor-view.js +67 -0
  30. package/dist/shell/entry.js +31 -4
  31. package/dist/shell/graph/agents.d.ts +48 -0
  32. package/dist/shell/graph/agents.js +152 -0
  33. package/dist/shell/graph/controller.d.ts +40 -2
  34. package/dist/shell/graph/controller.js +149 -12
  35. package/dist/shell/graph/graph-view.d.ts +7 -0
  36. package/dist/shell/graph/graph-view.js +227 -50
  37. package/dist/shell/graph/layout.d.ts +21 -2
  38. package/dist/shell/graph/layout.js +79 -11
  39. package/dist/shell/graph/watch.d.ts +71 -0
  40. package/dist/shell/graph/watch.js +153 -0
  41. package/dist/shell/input.d.ts +24 -0
  42. package/dist/shell/input.js +76 -7
  43. package/dist/shell/render-api.js +1 -0
  44. package/dist/shell/render.js +12 -2
  45. package/dist/shell/shell.d.ts +25 -1
  46. package/dist/shell/shell.js +134 -5
  47. package/dist/shell/startup.d.ts +3 -0
  48. package/dist/shell/startup.js +8 -0
  49. package/dist/shell/view.d.ts +5 -1
  50. package/dist/shell/view.js +80 -75
  51. package/dist/ui/server.js +6 -56
  52. package/package.json +1 -1
@@ -11,9 +11,11 @@ import { nodeRank } from "../../graph-core/model.js";
11
11
  import { displayWidth, padToWidth, style } from "../render.js";
12
12
  import { BrailleCanvas, blendHex, hexToSgr } from "./canvas.js";
13
13
  import { graphGlyphs } from "./glyphs.js";
14
+ import { formatAge } from "./watch.js";
14
15
  const PANE_WIDTH = 34;
15
16
  const WIDE_BREAKPOINT = 100;
16
- const NARROW_STRIP_ROWS = 6;
17
+ /** Ceiling for the narrow-terminal detail strip; it only takes what it fills. */
18
+ const NARROW_STRIP_MAX = 6;
17
19
  const DIM_TARGET = "#3a3f55";
18
20
  /** Resolved per frame so PHREN_ICONS is honoured without a restart. */
19
21
  let KIND_GLYPH = graphGlyphs();
@@ -101,18 +103,17 @@ export function renderGraphView(controller, width, height) {
101
103
  ]);
102
104
  const wide = width >= WIDE_BREAKPOINT;
103
105
  const selected = controller.selectedId ? controller.model.nodeById.get(controller.selectedId) ?? null : null;
104
- const stripRows = !wide && selected ? NARROW_STRIP_ROWS : 0;
106
+ // Build the strip first so it takes only the rows it fills; every row it
107
+ // gives back goes to the graph, which is the part worth the space.
108
+ const strip = !wide && selected ? renderStrip(controller, selected, width, NARROW_STRIP_MAX) : [];
105
109
  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
+ const canvasRows = Math.max(4, height - strip.length);
111
+ const canvasLines = drawCanvas(controller, canvasCols, canvasRows, selected);
110
112
  if (wide) {
111
- const pane = renderPane(controller, selected, PANE_WIDTH, canvasRows + 1);
113
+ const pane = renderPane(controller, selected, PANE_WIDTH, canvasRows);
112
114
  const divider = style.dim("│");
113
115
  return canvasLines.map((line, i) => `${line}${divider}${padToWidth(pane[i] ?? "", PANE_WIDTH)}`);
114
116
  }
115
- const strip = selected ? renderStrip(controller, selected, width, stripRows) : [];
116
117
  return [...canvasLines, ...strip.map((line) => padToWidth(line, width))];
117
118
  }
118
119
  function centered(width, height, lines) {
@@ -156,44 +157,97 @@ function drawCanvas(controller, cols, rows, selected) {
156
157
  const color = edgeColor(controller, link, touchesSelected, isLit(link.source) && isLit(link.target));
157
158
  canvas.line(a.x, a.y, b.x, b.y, color, { z: touchesSelected ? 2 : 0, dotted: link.kind === "contradicts" });
158
159
  }
160
+ const watching = controller.watchEnabled && controller.watch.running;
161
+ const heatOf = (id) => (watching ? controller.watch.heatOf(id) : 0);
159
162
  for (const { node, x, y } of placed) {
160
163
  const isSelected = selected?.id === node.id;
164
+ const heat = heatOf(node.id);
161
165
  let color = node.baseColor;
162
166
  if (isSelected)
163
167
  color = ACCENT_AMBER;
164
168
  else if (searching && !matches.has(node.id))
165
169
  color = blendHex(node.baseColor, DIM_TARGET, 0.7);
166
- canvas.disc(x, y, dotRadius(node, isSelected), color, isSelected ? 4 : node.kind === "project" ? 3 : 1);
170
+ // A just-touched node pulses toward the live cyan and swells a little.
171
+ if (heat > 0)
172
+ color = blendHex(color, ACCENT_CYAN, 0.3 + heat * 0.55);
173
+ const radius = dotRadius(node, isSelected) + (heat > 0.35 ? 1 : 0);
174
+ canvas.disc(x, y, radius, color, isSelected ? 4 : heat > 0 ? 3 : node.kind === "project" ? 3 : 1);
175
+ // A ring around the hottest nodes, so a hit reads at a glance.
176
+ if (heat > 0.55) {
177
+ const r = radius + 2;
178
+ for (let a = 0; a < 16; a++) {
179
+ const t = (a / 16) * Math.PI * 2;
180
+ canvas.setDot(x + Math.cos(t) * r, y + Math.sin(t) * r * 0.9, blendHex(ACCENT_CYAN, BG_COLOR, 1 - heat), 2);
181
+ }
182
+ }
167
183
  }
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.
184
+ // Glyphs and labels are drawn in two separate passes, and the order matters.
185
+ // Drawing a glyph and its label per node let a later node's glyph land inside
186
+ // an earlier node's label, which is what produced `sear◉hweb` on a busy
187
+ // canvas. Every glyph goes down first; labels then treat those cells as
188
+ // occupied and route around them.
173
189
  const neighborIndex = new Map();
174
190
  if (selected)
175
191
  controller.neighborsOf(selected.id).slice(0, 9).forEach((node, i) => neighborIndex.set(node.id, i + 1));
176
192
  const currentHit = searching ? controller.search.results[controller.search.index]?.id : undefined;
177
- const zoomedIn = controller.camera.scale >= 5;
193
+ const zoomedIn = Math.min(controller.camera.scaleX, controller.camera.scaleY) >= 5;
178
194
  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) {
195
+ const onCanvas = ({ x, y }) => {
182
196
  const col = Math.floor(x / 2);
183
197
  const row = Math.floor(y / 4);
184
- if (col < 0 || col >= cols || row < 0 || row >= rows)
198
+ return col < 0 || col >= cols || row < 0 || row >= rows ? null : { col, row };
199
+ };
200
+ // Pass 1 — glyphs.
201
+ for (const item of ranked) {
202
+ const at = onCanvas(item);
203
+ if (!at)
185
204
  continue;
205
+ const { node } = item;
186
206
  const isSelected = selected?.id === node.id;
187
207
  const lit = isLit(node.id);
188
208
  const glyphColor = isSelected ? ACCENT_AMBER : lit ? node.baseColor : blendHex(node.baseColor, DIM_TARGET, 0.7);
189
209
  const number = neighborIndex.get(node.id);
190
210
  if (isSelected)
191
- canvas.putText(col, row, "◆", sgr(ACCENT_AMBER, "\x1b[1m"));
211
+ canvas.putText(at.col, at.row, "◆", sgr(ACCENT_AMBER, "\x1b[1m"));
192
212
  else if (node.kind === "project")
193
- canvas.putText(col, row, KIND_GLYPH.project, sgr(glyphColor, "\x1b[1m"));
213
+ canvas.putText(at.col, at.row, KIND_GLYPH.project, sgr(glyphColor, "\x1b[1m"));
194
214
  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;
215
+ canvas.putText(at.col, at.row, String(number), sgr(ACCENT_CYAN, "\x1b[1m"));
216
+ }
217
+ // Every project used to force a label, so forty of them piled into one
218
+ // unreadable heap. Only as many as the canvas can carry get named, largest
219
+ // first; the rest still show their glyph.
220
+ const projectLabelBudget = Math.max(4, Math.floor((cols * rows) / 120));
221
+ const namedProjects = new Set(placed
222
+ .filter(({ node }) => node.kind === "project")
223
+ .sort((a, b) => projectWeight(b.node) - projectWeight(a.node))
224
+ .slice(0, projectLabelBudget)
225
+ .map(({ node }) => node.id));
226
+ /** A label needs a clear cell either side, or two labels read as one word. */
227
+ const hasRoom = (col, row, w, avoidDots) => {
228
+ if (col < 0 || col + w > cols)
229
+ return false;
230
+ const start = Math.max(0, col - 1);
231
+ const end = Math.min(cols, col + w + 1);
232
+ return canvas.isFree(start, row, end - start, avoidDots);
233
+ };
234
+ // Pass 2 — labels.
235
+ const labelBudget = searching ? 14 : zoomedIn ? Math.max(8, Math.floor((cols * rows) / 60)) : Math.max(4, Math.floor((cols * rows) / 220));
236
+ let labels = 0;
237
+ for (const item of ranked) {
238
+ const at = onCanvas(item);
239
+ if (!at)
240
+ continue;
241
+ const { node } = item;
242
+ const { col, row } = at;
243
+ const isSelected = selected?.id === node.id;
244
+ const lit = isLit(node.id);
245
+ const glyphColor = isSelected ? ACCENT_AMBER : lit ? node.baseColor : blendHex(node.baseColor, DIM_TARGET, 0.7);
246
+ const number = neighborIndex.get(node.id);
247
+ const forced = isSelected
248
+ || node.id === currentHit
249
+ || heatOf(node.id) > 0
250
+ || (node.kind === "project" ? namedProjects.has(node.id) : node.forceLabel);
197
251
  const wanted = forced || number !== undefined || (lit && labels < labelBudget && (zoomedIn || searching));
198
252
  if (!wanted)
199
253
  continue;
@@ -208,14 +262,38 @@ function drawCanvas(controller, cols, rows, selected) {
208
262
  ? sgr(lit ? blendHex(node.baseColor, "#ffffff", 0.35) : blendHex(node.baseColor, DIM_TARGET, 0.6))
209
263
  : sgr(lit ? blendHex(node.baseColor, "#ffffff", 0.2) : blendHex(node.baseColor, DIM_TARGET, 0.6));
210
264
  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);
265
+ // Clean slots first (no text, no dots); forced labels may cover dots as a
266
+ // last resort, but never another label.
267
+ const placedAt = slots.find(([c, r]) => hasRoom(c, r, w, true)) ?? (forced ? slots.find(([c, r]) => hasRoom(c, r, w, false)) : undefined);
213
268
  if (!placedAt)
214
269
  continue;
215
270
  canvas.putText(placedAt[0], placedAt[1], text, labelSgr);
216
271
  if (!forced)
217
272
  labels++;
218
273
  }
274
+ // Agents sit beside the project they are working in. They are runtime state,
275
+ // not memory, so they decorate a node rather than becoming one.
276
+ if (controller.agents.enabled && controller.agents.agents.length) {
277
+ const highlighted = controller.agents.current;
278
+ for (const [project, agents] of controller.agents.byProject()) {
279
+ const p = positions.get(project);
280
+ if (!p)
281
+ continue;
282
+ const d = controller.project(p);
283
+ const col = Math.floor(d.x / 2);
284
+ const row = Math.floor(d.y / 4) - 1;
285
+ if (col < 0 || col >= cols || row < 0 || row >= rows)
286
+ continue;
287
+ const busiest = agents.find((a) => a.status === "working") ?? agents[0];
288
+ const isHighlighted = agents.some((a) => a.id === highlighted?.id);
289
+ const mark = agents.length > 1 ? `▲${agents.length}` : "▲";
290
+ const color = AGENT_STATUS_COLOR[busiest.status] ?? "#7f8db3";
291
+ const marker = isHighlighted
292
+ ? `${hexToSgr(BG_COLOR)}\x1b[48;2;58;227;116m\x1b[1m`
293
+ : sgr(color, "\x1b[1m");
294
+ canvas.putText(col, row, mark, marker);
295
+ }
296
+ }
219
297
  if (controller.refreshing) {
220
298
  const badge = " ⟳ refreshing ";
221
299
  canvas.putText(cols - displayWidth(badge), 0, badge, sgr(ACCENT_CYAN, "\x1b[2m"));
@@ -239,6 +317,10 @@ function edgeColor(controller, link, touchesSelected, lit) {
239
317
  }
240
318
  return lit ? base : blendHex(base, BG_COLOR, 0.6);
241
319
  }
320
+ /** How much of the store a project holds; decides which get named when space is short. */
321
+ function projectWeight(node) {
322
+ return (node.findingCount ?? 0) + (node.taskCount ?? 0) + (node.refCount ?? 0);
323
+ }
242
324
  function labelPriority(controller, node, selected, neighborIndex) {
243
325
  let score = nodeRank(node, controller.filters, controller.model.scores);
244
326
  if (selected?.id === node.id)
@@ -251,33 +333,30 @@ function labelPriority(controller, node, selected, neighborIndex) {
251
333
  score += 20000;
252
334
  return score;
253
335
  }
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;
336
+ /**
337
+ * The one line of graph state worth spending characters on, rendered into the
338
+ * shell header rather than a row of its own. A legend of kind counts told you
339
+ * nothing the colours on screen did not, but whether you are looking at your
340
+ * whole store or a sample of it changes how you read the picture.
341
+ */
342
+ export function graphSummary(controller) {
343
+ if (controller.status !== "ready")
344
+ return "";
345
+ const shown = controller.visible.nodes.length;
346
+ const total = controller.model.rawNodes.length;
347
+ const n = (v) => v.toLocaleString("en-US");
348
+ const capped = shown < total ? `${n(shown)} of ${n(total)} nodes` : `${n(shown)} nodes`;
349
+ const parts = [capped, `${n(controller.visible.links.length)} edges`];
350
+ if (controller.watchEnabled && controller.watch.running)
351
+ parts.push(`${colored(ACCENT_CYAN, "◉")}${style.dim(" live")}`);
352
+ return parts.join(style.dim(" · "));
275
353
  }
276
354
  function healthDot(node) {
277
355
  return `${colored(HEALTH_COLOR[node.health], "●")} ${node.health}`;
278
356
  }
279
357
  function renderPane(controller, selected, width, height) {
280
358
  const inner = width - 2;
359
+ const watching = controller.watchEnabled && controller.watch.running;
281
360
  const lines = [];
282
361
  const push = (line = "") => { if (lines.length < height)
283
362
  lines.push(` ${line}`); };
@@ -285,7 +364,7 @@ function renderPane(controller, selected, width, height) {
285
364
  if (selected) {
286
365
  const detail = controller.detail(selected.id);
287
366
  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))
367
+ for (const line of wrapText(selected.fullLabel || selected.label, inner, watching ? 7 : 4))
289
368
  push(line);
290
369
  push();
291
370
  if (selected.kind !== "project" && selected.project)
@@ -339,11 +418,21 @@ function renderPane(controller, selected, width, height) {
339
418
  if (neighbors.length > 9)
340
419
  push(style.dim(` +${neighbors.length - 9} more`));
341
420
  }
421
+ const agentBudget = height - lines.length - 1;
422
+ if (agentBudget > 3)
423
+ for (const line of agentLines(controller, inner, agentBudget))
424
+ push(line);
425
+ if (watching) {
426
+ const budget = height - lines.length - 1;
427
+ if (budget > 3)
428
+ for (const line of activityLines(controller, inner, budget))
429
+ push(line);
430
+ }
342
431
  }
343
432
  else {
344
433
  const total = controller.model.rawNodes.length;
345
434
  const shown = controller.visible.nodes.length;
346
- push(`${colored(ACCENT_CYAN, "❖")} ${style.bold("knowledge graph")}${controller.refreshing ? style.dim(" ⟳") : ""}`);
435
+ push(`${colored(ACCENT_CYAN, "❖")} ${style.bold("knowledge graph")}${controller.refreshing ? style.dim(" ⟳") : ""}${watching ? ` ${colored(ACCENT_CYAN, "◉")}${style.dim(" live")}` : ""}`);
347
436
  push(style.dim(shown === total ? `${shown} nodes · ${controller.visible.links.length} edges` : `${shown} of ${total} nodes · ${controller.visible.links.length} edges`));
348
437
  push();
349
438
  row("filter", `${controller.preset.name}${style.dim(" f")}`);
@@ -365,6 +454,20 @@ function renderPane(controller, selected, width, height) {
365
454
  push(style.dim(` +${projects.length - budget} more`));
366
455
  push();
367
456
  }
457
+ const agentBudget = height - lines.length - 1;
458
+ if (agentBudget > 3)
459
+ for (const line of agentLines(controller, inner, agentBudget))
460
+ push(line);
461
+ if (watching) {
462
+ const budget = height - lines.length - 1;
463
+ if (budget > 3) {
464
+ for (const line of activityLines(controller, inner, budget))
465
+ push(line);
466
+ while (lines.length < height)
467
+ lines.push("");
468
+ return lines.slice(0, height);
469
+ }
470
+ }
368
471
  const k = (s) => style.boldCyan(s);
369
472
  const d = (s) => style.dim(s);
370
473
  push(`${k("↑↓←→")} ${d("walk")} ${k("↵")} ${d("select")}`);
@@ -378,6 +481,82 @@ function renderPane(controller, selected, width, height) {
378
481
  lines.push("");
379
482
  return lines.slice(0, height);
380
483
  }
484
+ const AGENT_STATUS_COLOR = {
485
+ working: "#3ae374",
486
+ idle: "#48b2ff",
487
+ done: "#5c6b8a",
488
+ error: "#ff5470",
489
+ };
490
+ const SOURCE_COLOR = {
491
+ search: ACCENT_CYAN,
492
+ inject: ACCENT_AMBER,
493
+ write: "#3ae374",
494
+ };
495
+ /**
496
+ * The live feed: what phren has just landed on, newest first. Each event gets
497
+ * a meta line and as much of the memory's text as the pane can carry, because
498
+ * the point of watching is reading what was found, not just seeing it blink.
499
+ */
500
+ /**
501
+ * Who is working, and where. Rendered above the activity feed so the pane reads
502
+ * top to bottom as: what is selected, who is on it, what phren just touched.
503
+ */
504
+ function agentLines(controller, inner, budget) {
505
+ const agents = controller.agents.agents;
506
+ const out = [];
507
+ if (!controller.agents.enabled)
508
+ return out;
509
+ out.push("");
510
+ out.push(`${colored(agents.length ? "#3ae374" : "#5c6b8a", "▲")} ${style.dim(`agents${agents.length ? "" : " — none running"}`)}`);
511
+ const current = controller.agents.current;
512
+ for (const agent of agents) {
513
+ if (out.length >= budget - 1)
514
+ break;
515
+ const isCurrent = agent.id === current?.id;
516
+ const color = AGENT_STATUS_COLOR[agent.status] ?? "#7f8db3";
517
+ const marker = isCurrent ? style.boldCyan("›") : " ";
518
+ out.push(`${marker}${colored(color, "●")} ${sliceWidth(agent.label, inner - 3)}`);
519
+ if (out.length >= budget - 1)
520
+ break;
521
+ const where = agent.project ?? style.dim("outside phren");
522
+ out.push(` ${style.dim(agent.status)} ${style.dim("·")} ${agent.project ? style.cyan(where) : where}`);
523
+ }
524
+ if (agents.length)
525
+ out.push(style.dim(" tab cycle · ↵ focus"));
526
+ return out.slice(0, budget);
527
+ }
528
+ function activityLines(controller, inner, budget) {
529
+ const out = [];
530
+ const now = Date.now();
531
+ const live = controller.watch.hot;
532
+ out.push("");
533
+ out.push(`${colored(live ? ACCENT_CYAN : "#5c6b8a", live ? "◉" : "○")} ${style.dim("activity")}`);
534
+ if (!controller.watch.activity.length) {
535
+ out.push(style.dim(" nothing yet — run a search"));
536
+ out.push(style.dim(" in another terminal"));
537
+ return out.slice(0, budget);
538
+ }
539
+ for (const item of controller.watch.activity) {
540
+ if (out.length >= budget - 1)
541
+ break;
542
+ const age = item.historical ? "" : formatAge(now - item.seenAt);
543
+ const source = item.event.source || "lookup";
544
+ const color = SOURCE_COLOR[source] ?? "#7f8db3";
545
+ const heat = item.nodeId ? controller.watch.heatOf(item.nodeId) : 0;
546
+ const meta = `${style.dim(age.padEnd(4))}${colored(color, source)} ${style.dim("·")} ${style.cyan(sliceWidth(item.event.project, inner - age.length - source.length - 4))}`;
547
+ out.push(heat > 0.5 ? `${meta}` : meta);
548
+ const text = item.event.snippet || item.event.filename || "";
549
+ if (text && out.length < budget - 1) {
550
+ const wrapped = wrapText(text, inner - 2, heat > 0 ? 3 : 2);
551
+ for (const line of wrapped) {
552
+ if (out.length >= budget - 1)
553
+ break;
554
+ out.push(` ${heat > 0 ? colored(blendHex("#e2e8f0", ACCENT_CYAN, heat * 0.7), line) : style.dim(line)}`);
555
+ }
556
+ }
557
+ }
558
+ return out.slice(0, budget);
559
+ }
381
560
  function renderStrip(controller, selected, width, rows) {
382
561
  const detail = controller.detail(selected.id);
383
562
  const lines = [];
@@ -402,7 +581,5 @@ function renderStrip(controller, selected, width, rows) {
402
581
  }
403
582
  lines.push(line.trimEnd());
404
583
  }
405
- while (lines.length < rows)
406
- lines.push("");
407
584
  return lines.slice(0, rows);
408
585
  }
@@ -27,12 +27,20 @@ export interface Point {
27
27
  }
28
28
  /** Ideal edge length in world units. Everything else is scaled off this. */
29
29
  export declare const IDEAL_DISTANCE = 12;
30
+ /**
31
+ * A terminal canvas is far wider than it is tall. A layout that settles into a
32
+ * circle therefore strands most of the screen, so the simulation is told the
33
+ * canvas aspect and lays the graph out as a matching ellipse: the project ring
34
+ * is stretched horizontally and vertical drift is damped by the same factor.
35
+ */
36
+ export declare const DEFAULT_ASPECT = 2.4;
37
+ export declare function normalizeAspect(aspect: number | undefined): number;
30
38
  /**
31
39
  * Starting positions: projects on a ring, leaves in a jittered blob around
32
40
  * their home project, multi-home fragments at the centroid of their homes,
33
41
  * orphans on an outer ring.
34
42
  */
35
- export declare function seedPositions(nodes: LayoutNode[], links: RawLink[]): Map<string, Point>;
43
+ export declare function seedPositions(nodes: LayoutNode[], links: RawLink[], aspect?: number): Map<string, Point>;
36
44
  export declare class ForceSim {
37
45
  readonly positions: Map<string, Point>;
38
46
  private readonly ids;
@@ -43,7 +51,18 @@ export declare class ForceSim {
43
51
  private readonly links;
44
52
  private temperature;
45
53
  private readonly startTemperature;
46
- constructor(nodes: LayoutNode[], links: RawLink[], seed?: Map<string, Point>);
54
+ private readonly aspect;
55
+ /** How far apart projects push each other; scaled to the clusters they carry. */
56
+ private readonly projectCutoff;
57
+ /**
58
+ * The ring radius each project should sit at, measured in aspect-corrected
59
+ * space. Seeding a packed ring is not enough on its own: mutual repulsion
60
+ * between many projects expands it again, which is how a forty-project store
61
+ * ended up sprawling to nearly twice its seeded size. A radial spring holds
62
+ * each project at the radius the packing chose.
63
+ */
64
+ private readonly targetRadius;
65
+ constructor(nodes: LayoutNode[], links: RawLink[], seed?: Map<string, Point>, aspect?: number);
47
66
  /** 1 at the start, 0 when settled; mirrors d3's `alpha` for hosts that animate. */
48
67
  get alpha(): number;
49
68
  get settled(): boolean;
@@ -15,6 +15,19 @@
15
15
  import { seeded } from "../../graph-core/model.js";
16
16
  /** Ideal edge length in world units. Everything else is scaled off this. */
17
17
  export const IDEAL_DISTANCE = 12;
18
+ /**
19
+ * A terminal canvas is far wider than it is tall. A layout that settles into a
20
+ * circle therefore strands most of the screen, so the simulation is told the
21
+ * canvas aspect and lays the graph out as a matching ellipse: the project ring
22
+ * is stretched horizontally and vertical drift is damped by the same factor.
23
+ */
24
+ export const DEFAULT_ASPECT = 2.4;
25
+ const MAX_ASPECT = 3.5;
26
+ export function normalizeAspect(aspect) {
27
+ if (!aspect || !Number.isFinite(aspect) || aspect <= 0)
28
+ return DEFAULT_ASPECT;
29
+ return Math.max(1, Math.min(aspect, MAX_ASPECT));
30
+ }
18
31
  /** Spring strength by edge flavour: spokes hold the clusters, enrichment edges just nudge. */
19
32
  const LINK_STRENGTH = {
20
33
  star: 1,
@@ -22,6 +35,15 @@ const LINK_STRENGTH = {
22
35
  supersedes: 0.6,
23
36
  contradicts: 0.4,
24
37
  };
38
+ /**
39
+ * How far a project's own nodes sprawl from it, estimated from how many it has.
40
+ * The ring is sized from this so clusters end up close to touching; sizing the
41
+ * ring by project count alone left the same gap at every scale and the graph
42
+ * never filled more than about a seventh of its own bounds.
43
+ */
44
+ function clusterRadius(leafCount) {
45
+ return IDEAL_DISTANCE * (0.9 + 0.42 * Math.sqrt(Math.max(0, leafCount)));
46
+ }
25
47
  /** Project ids in stable order plus, for every node, the project(s) it hangs off. */
26
48
  function homes(nodes, links) {
27
49
  const byId = new Map(nodes.map((node) => [node.id, node]));
@@ -59,13 +81,29 @@ function pushUnique(list, value) {
59
81
  * their home project, multi-home fragments at the centroid of their homes,
60
82
  * orphans on an outer ring.
61
83
  */
62
- export function seedPositions(nodes, links) {
84
+ export function seedPositions(nodes, links, aspect = DEFAULT_ASPECT) {
63
85
  const positions = new Map();
86
+ const ratio = normalizeAspect(aspect);
64
87
  const { projects, homeOf } = homes(nodes, links);
65
- const ring = IDEAL_DISTANCE * Math.max(2.5, Math.sqrt(projects.length) * 2.2);
88
+ // Pack the ring so neighbouring clusters nearly touch: the circumference has
89
+ // to carry one cluster diameter per project, with a little air between.
90
+ const leavesPer = new Map();
91
+ for (const [id, hosts] of homeOf) {
92
+ if (hosts.length === 0)
93
+ continue;
94
+ const owner = hosts[0];
95
+ if (owner === id)
96
+ continue;
97
+ leavesPer.set(owner, (leavesPer.get(owner) ?? 0) + 1);
98
+ }
99
+ const spread = Math.max(...projects.map((p) => clusterRadius(leavesPer.get(p.id) ?? 0)), IDEAL_DISTANCE);
100
+ const packed = (projects.length * spread * 2.3) / (2 * Math.PI);
101
+ const ring = Math.max(IDEAL_DISTANCE * 2.2, packed);
66
102
  projects.forEach((project, i) => {
67
- const angle = (i / Math.max(1, projects.length)) * Math.PI * 2 - Math.PI / 2;
68
- positions.set(project.id, { x: Math.cos(angle) * ring, y: Math.sin(angle) * ring });
103
+ // Start a quarter turn in so two projects sit side by side rather than
104
+ // stacked, which is the worst case on a wide screen.
105
+ const angle = (i / Math.max(1, projects.length)) * Math.PI * 2;
106
+ positions.set(project.id, { x: Math.cos(angle) * ring * ratio, y: Math.sin(angle) * ring });
69
107
  });
70
108
  if (projects.length === 1)
71
109
  positions.set(projects[0].id, { x: 0, y: 0 });
@@ -76,7 +114,7 @@ export function seedPositions(nodes, links) {
76
114
  const home = (homeOf.get(node.id) ?? []).map((id) => positions.get(id)).filter((p) => Boolean(p));
77
115
  const angle = seeded(node.id, "angle") * Math.PI * 2;
78
116
  if (home.length === 0) {
79
- positions.set(node.id, { x: Math.cos(angle) * outer, y: Math.sin(angle) * outer });
117
+ positions.set(node.id, { x: Math.cos(angle) * outer * ratio, y: Math.sin(angle) * outer });
80
118
  continue;
81
119
  }
82
120
  const cx = home.reduce((sum, p) => sum + p.x, 0) / home.length;
@@ -96,7 +134,22 @@ export class ForceSim {
96
134
  links;
97
135
  temperature;
98
136
  startTemperature;
99
- constructor(nodes, links, seed) {
137
+ aspect;
138
+ /** How far apart projects push each other; scaled to the clusters they carry. */
139
+ projectCutoff;
140
+ /**
141
+ * The ring radius each project should sit at, measured in aspect-corrected
142
+ * space. Seeding a packed ring is not enough on its own: mutual repulsion
143
+ * between many projects expands it again, which is how a forty-project store
144
+ * ended up sprawling to nearly twice its seeded size. A radial spring holds
145
+ * each project at the radius the packing chose.
146
+ */
147
+ targetRadius;
148
+ constructor(nodes, links, seed, aspect = DEFAULT_ASPECT) {
149
+ this.aspect = normalizeAspect(aspect);
150
+ const leaves = nodes.filter((node) => node.kind !== "project").length;
151
+ const projectCount = Math.max(1, nodes.length - leaves);
152
+ this.projectCutoff = clusterRadius(leaves / projectCount) * 2.4;
100
153
  this.ids = nodes.map((node) => node.id);
101
154
  this.index = new Map(this.ids.map((id, i) => [id, i]));
102
155
  this.mass = nodes.map((node) => (node.kind === "project" ? 4 : 1) * Math.max(0.6, node.size / 12));
@@ -111,10 +164,16 @@ export class ForceSim {
111
164
  continue;
112
165
  this.links.push({ a, b, strength: LINK_STRENGTH[link.kind ?? "star"] });
113
166
  }
114
- const seeded = seedPositions(nodes, links);
167
+ const seeded = seedPositions(nodes, links, this.aspect);
115
168
  this.positions = new Map();
116
169
  for (const id of this.ids)
117
170
  this.positions.set(id, { ...(seed?.get(id) ?? seeded.get(id)) });
171
+ this.targetRadius = this.ids.map((id, i) => {
172
+ if (!this.isProject[i])
173
+ return 0;
174
+ const p = seeded.get(id);
175
+ return Math.hypot(p.x / this.aspect, p.y);
176
+ });
118
177
  this.startTemperature = IDEAL_DISTANCE * Math.max(1, Math.sqrt(nodes.length) / 4);
119
178
  this.temperature = this.startTemperature;
120
179
  }
@@ -187,7 +246,7 @@ export class ForceSim {
187
246
  dist2 = ddx * ddx + ddy * ddy || 0.01;
188
247
  }
189
248
  const dist = Math.sqrt(dist2);
190
- const cutoff = k * (this.isProject[i] || this.isProject[j] ? 14 : 6);
249
+ const cutoff = this.isProject[i] || this.isProject[j] ? this.projectCutoff : k * 6;
191
250
  if (dist > cutoff)
192
251
  continue;
193
252
  const force = (k2 / dist) * Math.sqrt(this.mass[i] * this.mass[j]);
@@ -215,8 +274,17 @@ export class ForceSim {
215
274
  // Cluster pull toward the home project(s); projects drift gently to the origin.
216
275
  for (let i = 0; i < count; i++) {
217
276
  if (this.isProject[i]) {
218
- dx[i] -= xs[i] * 0.02;
219
- dy[i] -= ys[i] * 0.02;
277
+ // Hold the project on its ring. The error is measured in
278
+ // aspect-corrected space so the restoring force preserves the wide
279
+ // ellipse rather than pulling the layout back into a circle.
280
+ const nx = xs[i] / this.aspect;
281
+ const ny = ys[i];
282
+ const radius = Math.hypot(nx, ny);
283
+ if (radius > 0.01) {
284
+ const pull = (this.targetRadius[i] - radius) * 0.18;
285
+ dx[i] += (nx / radius) * pull * this.aspect;
286
+ dy[i] += (ny / radius) * pull;
287
+ }
220
288
  continue;
221
289
  }
222
290
  const anchors = this.anchors[i];
@@ -231,7 +299,7 @@ export class ForceSim {
231
299
  ax /= anchors.length;
232
300
  ay /= anchors.length;
233
301
  dx[i] += (ax - xs[i]) * 0.08;
234
- dy[i] += (ay - ys[i]) * 0.08;
302
+ dy[i] += (ay - ys[i]) * 0.08 * Math.sqrt(this.aspect);
235
303
  }
236
304
  // Apply, capped by the current temperature.
237
305
  const cap = this.temperature;