@phren/cli 0.1.45 → 0.1.46

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 (38) 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/search.js +29 -0
  10. package/dist/cli-registry.d.ts +1 -1
  11. package/dist/cli-registry.js +1 -0
  12. package/dist/content/learning.js +24 -1
  13. package/dist/generated/memory-ui-graph.browser.js +69 -69
  14. package/dist/graph-core/model.js +99 -9
  15. package/dist/memory-ui-graph.runtime.js +69 -69
  16. package/dist/phren-art.d.ts +7 -0
  17. package/dist/phren-art.js +6 -41
  18. package/dist/shared/lookup-tail.d.ts +35 -0
  19. package/dist/shared/lookup-tail.js +100 -0
  20. package/dist/shell/graph/agents.d.ts +48 -0
  21. package/dist/shell/graph/agents.js +152 -0
  22. package/dist/shell/graph/controller.d.ts +40 -2
  23. package/dist/shell/graph/controller.js +149 -12
  24. package/dist/shell/graph/graph-view.d.ts +7 -0
  25. package/dist/shell/graph/graph-view.js +227 -50
  26. package/dist/shell/graph/layout.d.ts +21 -2
  27. package/dist/shell/graph/layout.js +79 -11
  28. package/dist/shell/graph/watch.d.ts +71 -0
  29. package/dist/shell/graph/watch.js +153 -0
  30. package/dist/shell/input.js +3 -1
  31. package/dist/shell/render.js +3 -0
  32. package/dist/shell/shell.d.ts +2 -0
  33. package/dist/shell/shell.js +9 -4
  34. package/dist/shell/startup.d.ts +3 -0
  35. package/dist/shell/startup.js +8 -0
  36. package/dist/shell/view.js +61 -73
  37. package/dist/ui/server.js +6 -56
  38. package/package.json +1 -1
@@ -288,6 +288,83 @@ export function nodeRank(node, filters, scores) {
288
288
  rank += 120;
289
289
  return rank;
290
290
  }
291
+ /**
292
+ * Split a budget across buckets so every one gets a share. Buckets smaller than
293
+ * an even share release what they cannot use, and the surplus goes round again,
294
+ * so a store of many small projects and a few huge ones still spends the whole
295
+ * budget without starving the small ones.
296
+ */
297
+ function allocateQuotas(buckets, budget) {
298
+ const quotas = new Map();
299
+ let hungry = [...buckets.keys()];
300
+ let remaining = budget;
301
+ while (hungry.length > 0 && remaining > 0) {
302
+ const share = Math.floor(remaining / hungry.length);
303
+ if (share < 1)
304
+ break;
305
+ const next = [];
306
+ for (const key of hungry) {
307
+ const taken = quotas.get(key) ?? 0;
308
+ const want = buckets.get(key).length - taken;
309
+ const give = Math.min(share, want);
310
+ if (give > 0) {
311
+ quotas.set(key, taken + give);
312
+ remaining -= give;
313
+ }
314
+ if (want > give)
315
+ next.push(key);
316
+ }
317
+ if (next.length === hungry.length && next.length > 0 && remaining === budget)
318
+ break;
319
+ hungry = next;
320
+ }
321
+ // Hand out the indivisible remainder one at a time, largest bucket first.
322
+ if (remaining > 0 && hungry.length > 0) {
323
+ const bySize = hungry.slice().sort((a, b) => buckets.get(b).length - buckets.get(a).length);
324
+ for (const key of bySize) {
325
+ if (remaining <= 0)
326
+ break;
327
+ const taken = quotas.get(key) ?? 0;
328
+ if (taken >= buckets.get(key).length)
329
+ continue;
330
+ quotas.set(key, taken + 1);
331
+ remaining--;
332
+ }
333
+ }
334
+ return quotas;
335
+ }
336
+ /**
337
+ * Fill a bucket's quota by taking the best of each kind in turn rather than the
338
+ * best overall, so a project's tasks and reference docs cannot be crowded out
339
+ * by its own findings.
340
+ */
341
+ function pickAcrossKinds(nodes, quota, filters, scores) {
342
+ if (quota <= 0)
343
+ return [];
344
+ if (nodes.length <= quota)
345
+ return nodes;
346
+ const byKind = new Map();
347
+ for (const node of nodes) {
348
+ const list = byKind.get(node.kind);
349
+ if (list)
350
+ list.push(node);
351
+ else
352
+ byKind.set(node.kind, [node]);
353
+ }
354
+ for (const list of byKind.values())
355
+ list.sort((a, b) => nodeRank(b, filters, scores) - nodeRank(a, filters, scores));
356
+ const queues = [...byKind.values()];
357
+ const picked = [];
358
+ let cursor = 0;
359
+ while (picked.length < quota && queues.some((q) => q.length > 0)) {
360
+ const queue = queues[cursor % queues.length];
361
+ const node = queue.shift();
362
+ if (node)
363
+ picked.push(node);
364
+ cursor++;
365
+ }
366
+ return picked;
367
+ }
291
368
  /**
292
369
  * Apply structural filters + the node cap. Projects and the selected node are
293
370
  * always kept when the cap trims the list.
@@ -296,17 +373,30 @@ export function buildVisibleData(model, filters, selectedId) {
296
373
  const filteredNodes = model.rawNodes.filter((node) => nodeMatchesFilters(node, filters));
297
374
  let limitedNodes = filteredNodes.slice();
298
375
  if (limitedNodes.length > filters.nodeLimit) {
299
- const sorted = limitedNodes.slice().sort((a, b) => nodeRank(b, filters, model.scores) - nodeRank(a, filters, model.scores));
300
- const keepIds = new Set();
301
- for (const node of sorted) {
302
- if (keepIds.size >= filters.nodeLimit)
303
- break;
304
- keepIds.add(node.id);
305
- }
306
- model.rawNodes.forEach((node) => {
376
+ // Taking the globally highest-ranked nodes concentrates the whole budget on
377
+ // whichever projects happen to rank well: on a 40-project store two of them
378
+ // took every slot and the other 38 showed as bare dots, which makes the map
379
+ // misrepresent the store. Give every project a share instead.
380
+ const projects = filteredNodes.filter((node) => node.kind === "project");
381
+ const buckets = new Map();
382
+ for (const node of filteredNodes) {
307
383
  if (node.kind === "project")
384
+ continue;
385
+ // Fragments carry no project of their own; they bucket together so
386
+ // cross-project structure survives the cap.
387
+ const key = node.project || "";
388
+ const list = buckets.get(key);
389
+ if (list)
390
+ list.push(node);
391
+ else
392
+ buckets.set(key, [node]);
393
+ }
394
+ const quotas = allocateQuotas(buckets, Math.max(0, filters.nodeLimit - projects.length));
395
+ const keepIds = new Set(projects.map((node) => node.id));
396
+ for (const [key, list] of buckets) {
397
+ for (const node of pickAcrossKinds(list, quotas.get(key) ?? 0, filters, model.scores))
308
398
  keepIds.add(node.id);
309
- });
399
+ }
310
400
  if (selectedId)
311
401
  keepIds.add(selectedId);
312
402
  limitedNodes = filteredNodes.filter((node) => keepIds.has(node.id));