@phren/cli 0.1.34 → 0.1.36

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.
@@ -1889,22 +1889,17 @@ export function renderGraphHostScript() {
1889
1889
  if (typeof window.graphClearSelection === 'function') window.graphClearSelection();
1890
1890
  }
1891
1891
 
1892
+ // The dossier docks to the right edge of the graph viewport — a stable
1893
+ // reading pane instead of a cursor-chasing popover. Signature kept for
1894
+ // callers; the x/y hint is no longer needed.
1892
1895
  function positionPopover(x, y) {
1893
1896
  var popover = document.getElementById('graph-node-popover');
1894
- var card = document.getElementById('graph-node-popover-card');
1895
- var container = document.querySelector('#tab-graph .graph-container');
1896
- if (!popover || !card || !container) return;
1897
+ if (!popover) return;
1898
+ popover.classList.add('phren-docked');
1899
+ popover.style.left = '';
1900
+ popover.style.top = '';
1901
+ popover.style.visibility = 'visible';
1897
1902
  popover.style.display = 'block';
1898
- popover.style.visibility = 'hidden';
1899
- requestAnimationFrame(function() {
1900
- var containerRect = container.getBoundingClientRect();
1901
- var cardRect = card.getBoundingClientRect();
1902
- var left = Math.min(Math.max(12, x + 18), Math.max(12, containerRect.width - cardRect.width - 12));
1903
- var top = Math.min(Math.max(12, y + 18), Math.max(12, containerRect.height - cardRect.height - 12));
1904
- popover.style.left = left + 'px';
1905
- popover.style.top = top + 'px';
1906
- popover.style.visibility = 'visible';
1907
- });
1908
1903
  }
1909
1904
 
1910
1905
  function currentPopoverPoint() {
@@ -1955,6 +1950,68 @@ export function renderGraphHostScript() {
1955
1950
  return node.kind || 'Node';
1956
1951
  }
1957
1952
 
1953
+ function findingSiblings(node) {
1954
+ var data = graphData();
1955
+ return (data.nodes || []).filter(function(candidate) {
1956
+ return candidate.kind === 'finding' && candidate.projectName === node.projectName;
1957
+ }).sort(function(a, b) { return a.id < b.id ? -1 : a.id > b.id ? 1 : 0; });
1958
+ }
1959
+
1960
+ function findingNav(node) {
1961
+ var list = findingSiblings(node);
1962
+ var index = -1;
1963
+ for (var i = 0; i < list.length; i++) {
1964
+ if (list[i].id === node.id) { index = i; break; }
1965
+ }
1966
+ return { list: list, index: index, total: list.length };
1967
+ }
1968
+
1969
+ function relatedFindings(node) {
1970
+ return findingSiblings(node).filter(function(candidate) {
1971
+ return candidate.id !== node.id && candidate.topicSlug && candidate.topicSlug === node.topicSlug;
1972
+ }).slice(0, 4);
1973
+ }
1974
+
1975
+ // Neighbors of the node from the live graph links, scored so the panel can
1976
+ // list "strongest relationships" like GraphRAG. Entities/findings first.
1977
+ function strongestRelationships(node) {
1978
+ var map = nodeMap();
1979
+ var ids = neighborIds(node.id);
1980
+ var out = [];
1981
+ for (var i = 0; i < ids.length; i++) {
1982
+ var nb = map[ids[i]];
1983
+ if (!nb || nb.kind === 'project') continue;
1984
+ var w = 0.6;
1985
+ if (nb.kind === 'entity') w = 0.7 + Math.min(0.28, (nb.refCount || 0) * 0.03);
1986
+ else if (nb.kind === 'finding') w = typeof nb.qualityScore === 'number' ? 0.55 + nb.qualityScore * 0.4 : 0.6;
1987
+ var name = nb.displayLabel || nb.label || nb.id;
1988
+ var sub = nb.kind === 'entity' ? ((nb.refCount || 0) + ' references') : (nb.tooltipLabel || nb.fullLabel || '');
1989
+ if (sub === name) sub = '';
1990
+ out.push({ id: nb.id, name: name, sub: sub, w: w });
1991
+ }
1992
+ // same-topic siblings that aren't already linked, as softer relationships.
1993
+ // Dedupe by display TEXT too — stores can hold near-duplicate findings and
1994
+ // two identical rows read as a rendering bug.
1995
+ var seen = {}; var seenName = {};
1996
+ out.forEach(function(r) { seen[r.id] = true; seenName[r.name.toLowerCase()] = true; });
1997
+ relatedFindings(node).forEach(function(rel) {
1998
+ if (seen[rel.id]) return;
1999
+ var relName = rel.displayLabel || rel.label || rel.id;
2000
+ if (seenName[relName.toLowerCase()]) return;
2001
+ seenName[relName.toLowerCase()] = true;
2002
+ var relSub = 'same topic' + (rel.projectName && rel.projectName !== node.projectName ? ' · ' + rel.projectName : '');
2003
+ out.push({ id: rel.id, name: relName, sub: relSub, w: 0.5 });
2004
+ });
2005
+ out.sort(function(a, b) { return b.w - a.w; });
2006
+ return out.slice(0, 6);
2007
+ }
2008
+
2009
+ function gotoChip(label, nodeId, accent) {
2010
+ var border = accent ? 'var(--accent)' : 'var(--border)';
2011
+ var bg = accent ? 'var(--accent-dim)' : 'var(--surface-raised)';
2012
+ return '<span data-graph-goto="' + esc(nodeId) + '" role="button" tabindex="0" style="display:inline-flex;align-items:center;gap:6px;padding:4px 9px;border-radius:999px;border:1px solid ' + border + ';background:' + bg + ';font-size:11px;color:var(--ink);cursor:pointer;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">' + esc(label) + '</span>';
2013
+ }
2014
+
1958
2015
  function chip(text, accent) {
1959
2016
  var border = accent ? 'var(--accent)' : 'var(--border)';
1960
2017
  var bg = accent ? 'var(--accent-dim)' : 'var(--surface-raised)';
@@ -1984,22 +2041,51 @@ export function renderGraphHostScript() {
1984
2041
  if (node.kind === 'task' && node.section) meta.push(node.section);
1985
2042
  if (node.kind === 'task' && node.priority) meta.push('Priority ' + node.priority);
1986
2043
  if (node.kind === 'finding' && node.topicLabel) meta.push(node.topicLabel);
2044
+ if (node.kind === 'finding' && node.date) meta.push(node.date);
1987
2045
 
1988
- var header = '<div style="display:flex;flex-direction:column;gap:8px;padding-right:44px"><div style="font-size:11px;letter-spacing:.06em;text-transform:uppercase;color:var(--muted)">' + esc(kindLabel(node)) + '</div><div style="font-size:var(--text-lg);font-weight:600;line-height:1.2">' + esc(title) + '</div><div style="display:flex;flex-wrap:wrap;gap:8px">' + meta.filter(Boolean).map(function(item, index) { return chip(item, index === 0); }).join('') + scoreLine(node) + '</div></div>';
2046
+ var header = '<div style="display:flex;flex-direction:column;gap:8px;padding-right:44px"><div class="phren-dossier-kind" style="font-size:11px;letter-spacing:.06em;text-transform:uppercase;color:var(--muted)">' + esc(kindLabel(node)) + '</div><div style="font-size:var(--text-lg);font-weight:600;line-height:1.2">' + esc(title) + '</div><div style="display:flex;flex-wrap:wrap;gap:8px">' + meta.filter(Boolean).map(function(item, index) { return chip(item, index === 0); }).join('') + scoreLine(node) + '</div></div>';
1989
2047
 
1990
2048
  var body = '';
1991
2049
  var actions = [];
1992
2050
 
1993
2051
  if (node.kind === 'project') {
1994
2052
  var counts = projectCounts(node);
2053
+ // Server totals beat visible-adjacency counts (filters can hide nodes)
2054
+ var findingTotal = typeof node.findingCount === 'number' && node.findingCount > counts.finding ? node.findingCount : counts.finding;
2055
+ var taskTotal = typeof node.taskCount === 'number' && node.taskCount > counts.task ? node.taskCount : counts.task;
1995
2056
  body += '<div style="display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px">';
1996
- body += '<div class="card" style="padding:12px"><div style="font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.05em">Findings</div><div style="font-size:var(--text-lg);font-weight:600;margin-top:4px">' + counts.finding + '</div></div>';
1997
- body += '<div class="card" style="padding:12px"><div style="font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.05em">Tasks</div><div style="font-size:var(--text-lg);font-weight:600;margin-top:4px">' + counts.task + '</div></div>';
2057
+ body += '<div class="card" style="padding:12px"><div style="font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.05em">Findings</div><div style="font-size:var(--text-lg);font-weight:600;margin-top:4px">' + findingTotal + '</div></div>';
2058
+ body += '<div class="card" style="padding:12px"><div style="font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.05em">Tasks</div><div style="font-size:var(--text-lg);font-weight:600;margin-top:4px">' + taskTotal + '</div></div>';
1998
2059
  body += '<div class="card" style="padding:12px"><div style="font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.05em">Fragments</div><div style="font-size:var(--text-lg);font-weight:600;margin-top:4px">' + counts.entity + '</div></div>';
1999
2060
  body += '<div class="card" style="padding:12px"><div style="font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.05em">References</div><div style="font-size:var(--text-lg);font-weight:600;margin-top:4px">' + counts.reference + '</div></div>';
2000
2061
  body += '</div>';
2001
2062
  } else if (node.kind === 'finding') {
2002
- body += '<div id="graph-node-text" style="white-space:pre-wrap;line-height:1.65;font-size:var(--text-base)">' + esc(node.tooltipLabel || node.fullLabel || title) + '</div>';
2063
+ // GraphRAG-style stats row: links / project / helpful
2064
+ var conn = node.connections || {};
2065
+ var helpful = node.score && typeof node.score.helpful === 'number' ? node.score.helpful : 0;
2066
+ body += '<div class="phren-dossier-stats">'
2067
+ + '<div><div class="k">Links</div><div class="v">' + (conn.total || 0) + '</div></div>'
2068
+ + '<div><div class="k">Project</div><div class="v" style="font-size:11px;letter-spacing:.04em;text-transform:none">' + esc(node.projectName || '—') + '</div></div>'
2069
+ + '<div><div class="k">Helpful</div><div class="v">' + helpful + '</div></div>'
2070
+ + '</div>';
2071
+ body += '<div class="phren-dossier-section">◈ Description</div>';
2072
+ body += '<div id="graph-node-text" class="phren-dossier-text">' + esc(node.tooltipLabel || node.fullLabel || title) + '</div>';
2073
+ // Strongest relationships — related same-topic findings + entity neighbors
2074
+ var rels = strongestRelationships(node);
2075
+ if (rels.length) {
2076
+ body += '<div class="phren-dossier-section">⟿ Strongest relationships · ' + rels.length + '</div>';
2077
+ body += '<div style="margin-top:8px">' + rels.map(function(r) {
2078
+ return '<div class="phren-rel-row" data-graph-goto="' + esc(r.id) + '"><div class="n">' + esc(r.name) + (r.sub ? '<small>' + esc(r.sub) + '</small>' : '') + '</div><div class="w">' + r.w.toFixed(2) + '</div></div>';
2079
+ }).join('') + '</div>';
2080
+ }
2081
+ if (node.projectName) {
2082
+ body += '<div class="phren-dossier-section">Community</div>';
2083
+ body += '<div style="display:flex;flex-wrap:wrap;gap:8px;margin-top:6px">' + gotoChip(node.projectName, node.projectName, true) + '</div>';
2084
+ }
2085
+ var nav = findingNav(node);
2086
+ if (nav.total > 1 && nav.index !== -1) {
2087
+ actions.push('<span class="phren-dossier-nav"><button type="button" data-graph-action="prev-finding" title="Previous finding in project">‹</button><span>' + (nav.index + 1) + ' of ' + nav.total + '</span><button type="button" data-graph-action="next-finding" title="Next finding in project">›</button></span>');
2088
+ }
2003
2089
  actions.push('<button type="button" class="btn btn-sm" data-graph-action="edit">Edit</button>');
2004
2090
  actions.push('<button type="button" class="btn btn-sm" data-graph-action="delete" style="border-color:var(--danger);color:var(--danger)">Delete</button>');
2005
2091
  } else if (node.kind === 'task') {
@@ -2111,7 +2197,8 @@ export function renderGraphHostScript() {
2111
2197
  }
2112
2198
  graphRequest('/api/findings/' + encodeURIComponent(currentNode.projectName), 'PUT', {
2113
2199
  old_text: currentNode.tooltipLabel || currentNode.fullLabel || '',
2114
- new_text: nextText
2200
+ new_text: nextText,
2201
+ score_key: currentNode.scoreKey || ''
2115
2202
  }).then(function(result) {
2116
2203
  if (!result || !result.ok) throw new Error(result && result.error ? result.error : 'Save failed');
2117
2204
  graphToast('Finding updated', 'ok');
@@ -2161,7 +2248,8 @@ export function renderGraphHostScript() {
2161
2248
  if (!confirm('Delete this ' + (currentNode.kind || 'node') + '?')) return;
2162
2249
  if (currentNode.kind === 'finding') {
2163
2250
  graphRequest('/api/findings/' + encodeURIComponent(currentNode.projectName), 'DELETE', {
2164
- text: currentNode.tooltipLabel || currentNode.fullLabel || ''
2251
+ text: currentNode.tooltipLabel || currentNode.fullLabel || '',
2252
+ score_key: currentNode.scoreKey || ''
2165
2253
  }).then(function(result) {
2166
2254
  if (!result || !result.ok) throw new Error(result && result.error ? result.error : 'Delete failed');
2167
2255
  graphToast('Finding deleted', 'ok');
@@ -2232,9 +2320,28 @@ export function renderGraphHostScript() {
2232
2320
  });
2233
2321
  });
2234
2322
 
2323
+ // Related-node chips — fly to the referenced node
2324
+ document.querySelectorAll('[data-graph-goto]').forEach(function(chipEl) {
2325
+ chipEl.addEventListener('click', function() {
2326
+ var target = chipEl.getAttribute('data-graph-goto') || '';
2327
+ var api = graphApi();
2328
+ if (target && api && api.focusNode) api.focusNode(target);
2329
+ });
2330
+ });
2331
+
2235
2332
  document.querySelectorAll('[data-graph-action]').forEach(function(button) {
2236
2333
  button.addEventListener('click', function() {
2237
2334
  var action = button.getAttribute('data-graph-action');
2335
+ if (action === 'prev-finding' || action === 'next-finding') {
2336
+ if (!currentNode) return;
2337
+ var nav = findingNav(currentNode);
2338
+ if (nav.total < 2 || nav.index === -1) return;
2339
+ var step = action === 'next-finding' ? 1 : -1;
2340
+ var nextIndex = (nav.index + step + nav.total) % nav.total;
2341
+ var api = graphApi();
2342
+ if (api && api.focusNode) api.focusNode(nav.list[nextIndex].id);
2343
+ return;
2344
+ }
2238
2345
  if (action === 'edit') {
2239
2346
  editMode = currentNode && (currentNode.kind === 'finding' || currentNode.kind === 'task') ? currentNode.kind : null;
2240
2347
  var point = currentPopoverPoint();
package/dist/ui/server.js CHANGED
@@ -8,6 +8,7 @@ import { spawn, execFileSync } from "child_process";
8
8
  import { computePhrenLiveStateToken, getProjectDirs, } from "../shared.js";
9
9
  import { getNonPrimaryStores, subscribeStoreProjects, unsubscribeStoreProjects } from "../store-registry.js";
10
10
  import { editFinding, readReviewQueue, removeFinding, readFindings, addFinding as addFindingStore, readTasksAcrossProjects, addTask as addTaskStore, completeTask as completeTaskStore, removeTask as removeTaskStore, updateTask as updateTaskStore, TASKS_FILENAME, FINDINGS_FILENAME, } from "../data/access.js";
11
+ import { entryScoreKey } from "../governance/scores.js";
11
12
  import { isValidProjectName, errorMessage, queueFilePath, safeProjectPath } from "../utils.js";
12
13
  import { readInstallPreferences, writeInstallPreferences, writeGovernanceInstallPreferences } from "../init/preferences.js";
13
14
  import { buildGraph, collectProjectsForUI, collectSkillsForUI, getHooksData, isAllowedSkillPath, readSyncSnapshot, recentAccepted, recentLookups, recentUsage, } from "./data.js";
@@ -1201,6 +1202,33 @@ function handlePostSettingsProjectOverrides(req, res, url, ctx) {
1201
1202
  }
1202
1203
  });
1203
1204
  }
1205
+ /**
1206
+ * Resolve a graph node's score_key back to the exact FINDINGS.md bullet text
1207
+ * (including its [tag] prefix). Score keys are minted per-bullet by the graph
1208
+ * builder, so this pins the precise entry even when display texts are
1209
+ * ambiguous (e.g. two findings differing only by tag). Returns null when the
1210
+ * key doesn't resolve — callers fall back to text matching.
1211
+ */
1212
+ function findBulletTextByScoreKey(phrenPath, project, scoreKey) {
1213
+ try {
1214
+ const file = path.join(phrenPath, project, FINDINGS_FILENAME);
1215
+ if (!fs.existsSync(file))
1216
+ return null;
1217
+ for (const line of fs.readFileSync(file, "utf8").split("\n")) {
1218
+ const tag = line.match(/^-\s+\[([a-z_-]+)\]\s+(.+?)(?:\s*<!--.*-->)?$/);
1219
+ const plain = tag ? null : line.match(/^-\s+(.+?)(?:\s*<!--.*-->)?$/);
1220
+ const entry = tag ? `[${tag[1]}] ${tag[2].trim()}` : plain ? plain[1].trim() : null;
1221
+ if (!entry)
1222
+ continue;
1223
+ if (entryScoreKey(project, FINDINGS_FILENAME, entry) === scoreKey)
1224
+ return entry;
1225
+ }
1226
+ }
1227
+ catch {
1228
+ // unreadable file — fall back to text matching
1229
+ }
1230
+ return null;
1231
+ }
1204
1232
  function handleFindingsWrite(req, res, url, pathname, ctx) {
1205
1233
  const project = decodeURIComponent(pathname.slice("/api/findings/".length));
1206
1234
  if (!project || !isValidProjectName(project))
@@ -1220,7 +1248,9 @@ function handleFindingsWrite(req, res, url, pathname, ctx) {
1220
1248
  const newText = String(parsed.new_text || "");
1221
1249
  if (!oldText || !newText)
1222
1250
  return jsonErr(res, "old_text and new_text are required");
1223
- const result = editFinding(ctx.phrenPath, project, oldText, newText);
1251
+ const scoreKey = String(parsed.score_key || "");
1252
+ const resolved = scoreKey ? findBulletTextByScoreKey(ctx.phrenPath, project, scoreKey) : null;
1253
+ const result = editFinding(ctx.phrenPath, project, resolved || oldText, newText);
1224
1254
  jsonOk(res, { ok: result.ok, error: result.ok ? undefined : result.error });
1225
1255
  });
1226
1256
  }
@@ -1230,7 +1260,9 @@ function handleFindingsWrite(req, res, url, pathname, ctx) {
1230
1260
  const text = String(parsed.text || "");
1231
1261
  if (!text)
1232
1262
  return jsonErr(res, "text is required");
1233
- const result = removeFinding(ctx.phrenPath, project, text);
1263
+ const scoreKey = String(parsed.score_key || "");
1264
+ const resolved = scoreKey ? findBulletTextByScoreKey(ctx.phrenPath, project, scoreKey) : null;
1265
+ const result = removeFinding(ctx.phrenPath, project, resolved || text);
1234
1266
  jsonOk(res, { ok: result.ok, error: result.ok ? undefined : result.error });
1235
1267
  });
1236
1268
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phren/cli",
3
- "version": "0.1.34",
3
+ "version": "0.1.36",
4
4
  "description": "Knowledge layer for AI agents — CLI, MCP server, and data layer",
5
5
  "type": "module",
6
6
  "bin": {
@@ -74,15 +74,14 @@
74
74
  "preuninstall": "node scripts/preuninstall.mjs"
75
75
  },
76
76
  "dependencies": {
77
+ "3d-force-graph": "^1.80.0",
77
78
  "@modelcontextprotocol/sdk": "^1.29.0",
78
79
  "chalk": "^5.6.2",
79
80
  "glob": "^13.0.6",
80
- "graphology": "^0.26.0",
81
- "graphology-layout-forceatlas2": "^0.10.1",
82
81
  "inquirer": "^14.0.2",
83
82
  "js-yaml": "^4.2.0",
84
- "sigma": "^3.0.3",
85
83
  "sql.js-fts5": "^1.4.0",
84
+ "three": "^0.184.0",
86
85
  "zod": "^4.4.3"
87
86
  },
88
87
  "engines": {