@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
@@ -14,6 +14,8 @@ import { errorMessage } from "../../utils.js";
14
14
  import { logger } from "../../logger.js";
15
15
  import { style } from "../render.js";
16
16
  import { ForceSim, bounds } from "./layout.js";
17
+ import { GraphWatch } from "./watch.js";
18
+ import { GraphAgents } from "./agents.js";
17
19
  /** Nodes drawn at once. Terminals have far fewer pixels than a browser tab. */
18
20
  export const TUI_NODE_LIMIT = 350;
19
21
  const ALL_TYPES = { project: true, finding: true, task: true, entity: true, reference: true };
@@ -24,6 +26,8 @@ export const FILTER_PRESETS = [
24
26
  { name: "fragments", types: { project: true, entity: true, reference: true }, health: "all" },
25
27
  { name: "aging", types: ALL_TYPES, health: "aging" },
26
28
  ];
29
+ /** How far the x and y scales may diverge when filling the canvas. */
30
+ const MAX_STRETCH = 2.2;
27
31
  const DIRECTIONS = {
28
32
  up: { x: 0, y: -1 },
29
33
  down: { x: 0, y: 1 },
@@ -71,7 +75,7 @@ export class GraphController {
71
75
  presetIndex = 0;
72
76
  selectedId = null;
73
77
  search = { query: "", matchIds: new Set(), results: [], index: -1 };
74
- camera = { cx: 0, cy: 0, scale: 2 };
78
+ camera = { cx: 0, cy: 0, scaleX: 2, scaleY: 2 };
75
79
  sim = null;
76
80
  lastPositions = new Map();
77
81
  viewport = { width: 160, height: 80 };
@@ -87,12 +91,83 @@ export class GraphController {
87
91
  builder;
88
92
  tokenOf;
89
93
  frameMs;
94
+ /** Live tail of what phren is landing on, in this or any other terminal. */
95
+ watch;
96
+ /** Coding agents running on this machine, joined onto their projects. */
97
+ agents;
98
+ watchEnabled;
99
+ /**
100
+ * Wall-clock ms of the last navigation keypress. While the user is driving,
101
+ * incoming events still pulse and feed but do not steal the camera.
102
+ */
103
+ lastUserInputAt = 0;
90
104
  constructor(phrenPath, profile, opts = {}) {
91
105
  this.phrenPath = phrenPath;
92
106
  this.profile = profile;
93
107
  this.builder = opts.builder ?? ((p, prof) => buildGraph(p, prof, undefined, null, { includeFragmentEdges: true, includeLifecycleEdges: true }));
94
108
  this.tokenOf = opts.tokenOf ?? computePhrenLiveStateToken;
95
109
  this.frameMs = opts.frameMs ?? 50;
110
+ this.watch = opts.watch ?? new GraphWatch(phrenPath);
111
+ this.watchEnabled = opts.watchEnabled !== false;
112
+ this.agents = opts.agents ?? new GraphAgents(phrenPath, profile);
113
+ }
114
+ // ── Watch mode ──────────────────────────────────────────────────────────
115
+ /** Idempotent; called every render so the tail starts with the view. */
116
+ startWatch() {
117
+ if (!this.watchEnabled || this.watch.running)
118
+ return;
119
+ this.watch.start((items) => this.onWatchEvents(items));
120
+ }
121
+ stopWatch() {
122
+ this.watch.stop();
123
+ }
124
+ // ── Agents ──────────────────────────────────────────────────────────────
125
+ /** Idempotent; the poller only runs while the Graph view is open. */
126
+ startAgents() {
127
+ if (!this.agents.enabled || this.agents.running)
128
+ return;
129
+ this.agents.start(() => this.repaintHook?.());
130
+ }
131
+ toggleAgents() {
132
+ if (this.agents.enabled) {
133
+ this.agents.toggle();
134
+ return false;
135
+ }
136
+ this.agents.enabled = true;
137
+ this.agents.start(() => this.repaintHook?.());
138
+ return true;
139
+ }
140
+ toggleWatch() {
141
+ this.watchEnabled = !this.watchEnabled;
142
+ if (this.watchEnabled)
143
+ this.startWatch();
144
+ else
145
+ this.stopWatch();
146
+ return this.watchEnabled;
147
+ }
148
+ /** True while the user is actively driving, so the camera is left alone. */
149
+ get userDriving() {
150
+ return Date.now() - this.lastUserInputAt < 4000;
151
+ }
152
+ /**
153
+ * New events landed. Light every node they touch, then follow the newest
154
+ * one that is actually on screen — unless the user is mid-navigation.
155
+ */
156
+ onWatchEvents(items) {
157
+ let followed = false;
158
+ for (let i = items.length - 1; i >= 0 && !followed; i--) {
159
+ const nodeId = items[i].nodeId;
160
+ if (!nodeId || !this.model.nodeById.has(nodeId))
161
+ continue;
162
+ if (!this.userDriving) {
163
+ this.selectedId = nodeId;
164
+ this.flyTo(nodeId);
165
+ }
166
+ followed = true;
167
+ }
168
+ // Heat decays over several seconds, so keep painting even without a fly.
169
+ this.startAnimation();
170
+ this.repaintHook?.();
96
171
  }
97
172
  // ── Data ────────────────────────────────────────────────────────────────
98
173
  /**
@@ -128,6 +203,8 @@ export class GraphController {
128
203
  * through; otherwise the old picture stays up with a refreshing badge.
129
204
  */
130
205
  async ensureData() {
206
+ this.startWatch();
207
+ this.startAgents();
131
208
  const token = this.currentToken();
132
209
  if (this.payload && token === this.dataToken)
133
210
  return;
@@ -199,7 +276,8 @@ export class GraphController {
199
276
  this.lastPositions = new Map([...this.sim.positions].map(([id, p]) => [id, { ...p }]));
200
277
  const nodes = this.visible.nodes.map((node) => ({ id: node.id, kind: node.kind, project: node.project, size: node.size }));
201
278
  const links = this.visible.links;
202
- this.sim = new ForceSim(nodes, links);
279
+ // The layout is shaped to the canvas so it fills a wide terminal.
280
+ this.sim = new ForceSim(nodes, links, undefined, this.viewport.width / Math.max(1, this.viewport.height));
203
281
  if (warm && this.lastPositions.size)
204
282
  this.sim.warmStart(this.lastPositions);
205
283
  const fresh = !warm || !this.lastPositions.size;
@@ -240,8 +318,8 @@ export class GraphController {
240
318
  /** World → dot coordinates for the current camera. */
241
319
  project(p) {
242
320
  return {
243
- x: (p.x - this.camera.cx) * this.camera.scale + this.viewport.width / 2,
244
- y: (p.y - this.camera.cy) * this.camera.scale + this.viewport.height / 2,
321
+ x: (p.x - this.camera.cx) * this.camera.scaleX + this.viewport.width / 2,
322
+ y: (p.y - this.camera.cy) * this.camera.scaleY + this.viewport.height / 2,
245
323
  };
246
324
  }
247
325
  fitAll() {
@@ -250,23 +328,39 @@ export class GraphController {
250
328
  this.fitOnSettle = false;
251
329
  this.userMoved = false;
252
330
  if (!box) {
253
- this.camera = { cx: 0, cy: 0, scale: 2 };
331
+ this.camera = { cx: 0, cy: 0, scaleX: 2, scaleY: 2 };
254
332
  return;
255
333
  }
256
334
  const w = Math.max(1, box.maxX - box.minX);
257
335
  const h = Math.max(1, box.maxY - box.minY);
258
- const pad = 0.86;
259
- const scale = Math.min((this.viewport.width * pad) / w, (this.viewport.height * pad) / h);
260
- this.camera = { cx: (box.minX + box.maxX) / 2, cy: (box.minY + box.maxY) / 2, scale: Math.max(0.2, Math.min(scale, 12)) };
336
+ const pad = 0.92;
337
+ let sx = (this.viewport.width * pad) / w;
338
+ let sy = (this.viewport.height * pad) / h;
339
+ // Fill both axes rather than letting the shorter one strand the rest of
340
+ // the screen, but pull the looser axis back in once it would distort.
341
+ if (sx > sy * MAX_STRETCH)
342
+ sx = sy * MAX_STRETCH;
343
+ else if (sy > sx * MAX_STRETCH)
344
+ sy = sx * MAX_STRETCH;
345
+ const clamp01 = (v) => Math.max(0.2, Math.min(v, 12));
346
+ this.camera = {
347
+ cx: (box.minX + box.maxX) / 2,
348
+ cy: (box.minY + box.maxY) / 2,
349
+ scaleX: clamp01(sx),
350
+ scaleY: clamp01(sy),
351
+ };
261
352
  }
262
353
  zoom(factor) {
263
354
  this.userMoved = true;
264
- this.camera.scale = Math.max(0.2, Math.min(24, this.camera.scale * factor));
355
+ // Both axes move together, so a zoom never changes the shape on screen.
356
+ const clampZoom = (v) => Math.max(0.2, Math.min(24, v));
357
+ this.camera.scaleX = clampZoom(this.camera.scaleX * factor);
358
+ this.camera.scaleY = clampZoom(this.camera.scaleY * factor);
265
359
  }
266
360
  pan(direction) {
267
361
  const d = DIRECTIONS[direction];
268
- const stepX = (this.viewport.width * 0.12) / this.camera.scale;
269
- const stepY = (this.viewport.height * 0.12) / this.camera.scale;
362
+ const stepX = (this.viewport.width * 0.12) / this.camera.scaleX;
363
+ const stepY = (this.viewport.height * 0.12) / this.camera.scaleY;
270
364
  this.userMoved = true;
271
365
  this.cameraTarget = null;
272
366
  this.camera.cx += d.x * stepX;
@@ -319,7 +413,7 @@ export class GraphController {
319
413
  return this.timer !== null;
320
414
  }
321
415
  animationFrame() {
322
- let busy = false;
416
+ let busy = this.watch.hot;
323
417
  if (this.sim && !this.sim.settled) {
324
418
  this.sim.tick(3);
325
419
  busy = true;
@@ -348,6 +442,8 @@ export class GraphController {
348
442
  /** Called by the shell when the view changes away or the shell closes. */
349
443
  dispose() {
350
444
  this.stopAnimation();
445
+ this.stopWatch();
446
+ this.agents.stop();
351
447
  }
352
448
  // ── Selection / search / focus ──────────────────────────────────────────
353
449
  detail(nodeId) {
@@ -518,6 +614,8 @@ export class GraphController {
518
614
  */
519
615
  handleKey(rawKey, host) {
520
616
  const key = normalizeArrow(rawKey);
617
+ if (key !== "w" && key !== "W")
618
+ this.lastUserInputAt = Date.now();
521
619
  if (this.status !== "ready") {
522
620
  if (key === "r") {
523
621
  this.dataToken = "";
@@ -556,6 +654,15 @@ export class GraphController {
556
654
  return true;
557
655
  }
558
656
  if (key === "\r" || key === "\n") {
657
+ // A highlighted agent takes the Enter: bring it to the front.
658
+ const highlighted = this.agents.current;
659
+ if (highlighted) {
660
+ const focused = this.agents.focusCurrent();
661
+ host.setMessage(focused
662
+ ? ` ${style.boldCyan("→")} ${focused.label}`
663
+ : ` ${style.dim(highlighted.focus?.length ? "could not focus that agent" : "this agent's host cannot be focused")}`);
664
+ return true;
665
+ }
559
666
  if (!this.selectedId) {
560
667
  const node = this.nearestToCenter();
561
668
  if (node) {
@@ -611,11 +718,41 @@ export class GraphController {
611
718
  host.setMessage(name ? ` ${style.boldCyan("❖")} ${style.boldCyan(name)}` : ` ${style.dim("all projects")}`);
612
719
  return true;
613
720
  }
721
+ if (key === "a" || key === "A") {
722
+ const on = this.toggleAgents();
723
+ host.setMessage(on
724
+ ? ` ${style.boldCyan("◉ agents")} ${style.dim(`— ${this.agents.agents.length} running · tab to cycle, ↵ to focus`)}`
725
+ : ` ${style.dim("agents off")}`);
726
+ return true;
727
+ }
728
+ if (key === "\t" || key === "\x1b[Z") {
729
+ if (!this.agents.enabled || !this.agents.agents.length)
730
+ return undefined;
731
+ const agent = this.agents.cycle(key === "\t" ? 1 : -1);
732
+ if (agent) {
733
+ if (agent.project && this.model.nodeById.has(agent.project))
734
+ this.select(agent.project, { fly: true });
735
+ host.setMessage(` ${style.boldCyan(agent.label)} ${style.dim(`${agent.status}${agent.project ? ` · ${agent.project}` : " · outside phren"}`)}`);
736
+ }
737
+ return true;
738
+ }
739
+ if (key === "w" || key === "W") {
740
+ const on = this.toggleWatch();
741
+ host.setMessage(on
742
+ ? ` ${style.boldCyan("◉ watching")} ${style.dim("— lighting up what phren touches, anywhere on this machine")}`
743
+ : ` ${style.dim("watch off")}`);
744
+ return true;
745
+ }
614
746
  if (key === "o") {
615
747
  host.setMessage(` ${style.dim("open the 3D viewer in a browser:")} ${style.boldCyan("phren web-ui")}`);
616
748
  return true;
617
749
  }
618
750
  if (key === "\x1b") {
751
+ if (this.agents.current) {
752
+ this.agents.clearHighlight();
753
+ host.setMessage(` ${style.dim("agent released")}`);
754
+ return true;
755
+ }
619
756
  if (this.search.query) {
620
757
  this.clearSearch();
621
758
  host.setMessage(` ${style.dim("search cleared")}`);
@@ -10,3 +10,10 @@ import type { GraphController } from "./controller.js";
10
10
  /** Word-wrap plain text to `width` cells, at most `maxLines` lines, ellipsised. */
11
11
  export declare function wrapText(text: string, width: number, maxLines: number): string[];
12
12
  export declare function renderGraphView(controller: GraphController, width: number, height: number): string[];
13
+ /**
14
+ * The one line of graph state worth spending characters on, rendered into the
15
+ * shell header rather than a row of its own. A legend of kind counts told you
16
+ * nothing the colours on screen did not, but whether you are looking at your
17
+ * whole store or a sample of it changes how you read the picture.
18
+ */
19
+ export declare function graphSummary(controller: GraphController): string;