@phren/cli 0.1.35 → 0.1.37

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.
@@ -1854,6 +1854,28 @@ export function renderGraphHostScript() {
1854
1854
  }, 2600);
1855
1855
  }
1856
1856
 
1857
+ function graphUndoToast(message, onUndo) {
1858
+ var container = document.getElementById('toast-container');
1859
+ if (!container) return;
1860
+ var toast = document.createElement('div');
1861
+ toast.className = 'toast';
1862
+ toast.style.display = 'flex';
1863
+ toast.style.alignItems = 'center';
1864
+ toast.style.gap = '10px';
1865
+ var msg = document.createElement('span');
1866
+ msg.textContent = message;
1867
+ var btn = document.createElement('button');
1868
+ btn.type = 'button';
1869
+ btn.textContent = 'Undo';
1870
+ btn.style.cssText = 'cursor:pointer;border:1px solid var(--accent,#67e8f9);background:transparent;color:var(--accent,#67e8f9);border-radius:6px;padding:2px 10px;font:inherit;font-size:12px';
1871
+ var remove = function() { if (toast.parentNode) toast.parentNode.removeChild(toast); };
1872
+ btn.addEventListener('click', function() { remove(); onUndo(); });
1873
+ toast.appendChild(msg);
1874
+ toast.appendChild(btn);
1875
+ container.appendChild(toast);
1876
+ setTimeout(remove, 8000);
1877
+ }
1878
+
1857
1879
  function fetchCsrfToken() {
1858
1880
  return fetch(authUrl('/api/csrf-token')).then(function(r) { return r.json(); }).then(function(data) {
1859
1881
  return data && data.ok ? (data.token || null) : null;
@@ -1889,22 +1911,45 @@ export function renderGraphHostScript() {
1889
1911
  if (typeof window.graphClearSelection === 'function') window.graphClearSelection();
1890
1912
  }
1891
1913
 
1914
+ // The dossier docks to the right edge of the graph viewport — a stable
1915
+ // reading pane instead of a cursor-chasing popover. Signature kept for
1916
+ // callers; the x/y hint is no longer needed.
1917
+ function ensureDossierResize(popover) {
1918
+ if (!popover || popover.querySelector('.phren-dossier-resize')) return;
1919
+ var handle = document.createElement('div');
1920
+ handle.className = 'phren-dossier-resize';
1921
+ handle.setAttribute('aria-hidden', 'true');
1922
+ handle.addEventListener('pointerdown', function(ev) {
1923
+ ev.preventDefault();
1924
+ ev.stopPropagation();
1925
+ handle.classList.add('dragging');
1926
+ try { handle.setPointerCapture(ev.pointerId); } catch (_) { /* ignore */ }
1927
+ function move(e) {
1928
+ var rect = popover.getBoundingClientRect();
1929
+ var w = Math.max(280, Math.min(680, e.clientX - rect.left));
1930
+ popover.style.width = w + 'px';
1931
+ popover.style.maxWidth = 'none';
1932
+ }
1933
+ function up() {
1934
+ handle.classList.remove('dragging');
1935
+ window.removeEventListener('pointermove', move);
1936
+ window.removeEventListener('pointerup', up);
1937
+ }
1938
+ window.addEventListener('pointermove', move);
1939
+ window.addEventListener('pointerup', up);
1940
+ });
1941
+ popover.appendChild(handle);
1942
+ }
1943
+
1892
1944
  function positionPopover(x, y) {
1893
1945
  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;
1946
+ if (!popover) return;
1947
+ popover.classList.add('phren-docked');
1948
+ popover.style.left = '';
1949
+ popover.style.top = '';
1950
+ popover.style.visibility = 'visible';
1897
1951
  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
- });
1952
+ ensureDossierResize(popover);
1908
1953
  }
1909
1954
 
1910
1955
  function currentPopoverPoint() {
@@ -1955,6 +2000,68 @@ export function renderGraphHostScript() {
1955
2000
  return node.kind || 'Node';
1956
2001
  }
1957
2002
 
2003
+ function findingSiblings(node) {
2004
+ var data = graphData();
2005
+ return (data.nodes || []).filter(function(candidate) {
2006
+ return candidate.kind === 'finding' && candidate.projectName === node.projectName;
2007
+ }).sort(function(a, b) { return a.id < b.id ? -1 : a.id > b.id ? 1 : 0; });
2008
+ }
2009
+
2010
+ function findingNav(node) {
2011
+ var list = findingSiblings(node);
2012
+ var index = -1;
2013
+ for (var i = 0; i < list.length; i++) {
2014
+ if (list[i].id === node.id) { index = i; break; }
2015
+ }
2016
+ return { list: list, index: index, total: list.length };
2017
+ }
2018
+
2019
+ function relatedFindings(node) {
2020
+ return findingSiblings(node).filter(function(candidate) {
2021
+ return candidate.id !== node.id && candidate.topicSlug && candidate.topicSlug === node.topicSlug;
2022
+ }).slice(0, 4);
2023
+ }
2024
+
2025
+ // Neighbors of the node from the live graph links, scored so the panel can
2026
+ // list "strongest relationships" like GraphRAG. Entities/findings first.
2027
+ function strongestRelationships(node) {
2028
+ var map = nodeMap();
2029
+ var ids = neighborIds(node.id);
2030
+ var out = [];
2031
+ for (var i = 0; i < ids.length; i++) {
2032
+ var nb = map[ids[i]];
2033
+ if (!nb || nb.kind === 'project') continue;
2034
+ var w = 0.6;
2035
+ if (nb.kind === 'entity') w = 0.7 + Math.min(0.28, (nb.refCount || 0) * 0.03);
2036
+ else if (nb.kind === 'finding') w = typeof nb.qualityScore === 'number' ? 0.55 + nb.qualityScore * 0.4 : 0.6;
2037
+ var name = nb.displayLabel || nb.label || nb.id;
2038
+ var sub = nb.kind === 'entity' ? ((nb.refCount || 0) + ' references') : (nb.tooltipLabel || nb.fullLabel || '');
2039
+ if (sub === name) sub = '';
2040
+ out.push({ id: nb.id, name: name, sub: sub, w: w });
2041
+ }
2042
+ // same-topic siblings that aren't already linked, as softer relationships.
2043
+ // Dedupe by display TEXT too — stores can hold near-duplicate findings and
2044
+ // two identical rows read as a rendering bug.
2045
+ var seen = {}; var seenName = {};
2046
+ out.forEach(function(r) { seen[r.id] = true; seenName[r.name.toLowerCase()] = true; });
2047
+ relatedFindings(node).forEach(function(rel) {
2048
+ if (seen[rel.id]) return;
2049
+ var relName = rel.displayLabel || rel.label || rel.id;
2050
+ if (seenName[relName.toLowerCase()]) return;
2051
+ seenName[relName.toLowerCase()] = true;
2052
+ var relSub = 'same topic' + (rel.projectName && rel.projectName !== node.projectName ? ' · ' + rel.projectName : '');
2053
+ out.push({ id: rel.id, name: relName, sub: relSub, w: 0.5 });
2054
+ });
2055
+ out.sort(function(a, b) { return b.w - a.w; });
2056
+ return out.slice(0, 6);
2057
+ }
2058
+
2059
+ function gotoChip(label, nodeId, accent) {
2060
+ var border = accent ? 'var(--accent)' : 'var(--border)';
2061
+ var bg = accent ? 'var(--accent-dim)' : 'var(--surface-raised)';
2062
+ 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>';
2063
+ }
2064
+
1958
2065
  function chip(text, accent) {
1959
2066
  var border = accent ? 'var(--accent)' : 'var(--border)';
1960
2067
  var bg = accent ? 'var(--accent-dim)' : 'var(--surface-raised)';
@@ -1984,22 +2091,55 @@ export function renderGraphHostScript() {
1984
2091
  if (node.kind === 'task' && node.section) meta.push(node.section);
1985
2092
  if (node.kind === 'task' && node.priority) meta.push('Priority ' + node.priority);
1986
2093
  if (node.kind === 'finding' && node.topicLabel) meta.push(node.topicLabel);
2094
+ if (node.kind === 'finding' && node.date) meta.push(node.date);
1987
2095
 
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>';
2096
+ 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
2097
 
1990
2098
  var body = '';
1991
2099
  var actions = [];
1992
2100
 
1993
2101
  if (node.kind === 'project') {
1994
2102
  var counts = projectCounts(node);
1995
- 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>';
1998
- 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
- 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
- body += '</div>';
2103
+ // Server totals beat visible-adjacency counts (filters can hide nodes)
2104
+ var findingTotal = typeof node.findingCount === 'number' && node.findingCount > counts.finding ? node.findingCount : counts.finding;
2105
+ var taskTotal = typeof node.taskCount === 'number' && node.taskCount > counts.task ? node.taskCount : counts.task;
2106
+ // Compact stat line — the detailed findings/tasks browser lives in the
2107
+ // contents pane on the right, so the bulky card grid was redundant.
2108
+ var stat = function(n, label) {
2109
+ return '<span style="display:inline-flex;align-items:baseline;gap:5px"><b style="font-size:var(--text-md);font-weight:700;color:var(--ink)">' + n + '</b><span style="font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.05em">' + label + '</span></span>';
2110
+ };
2111
+ body += '<div style="display:flex;flex-wrap:wrap;gap:16px;padding:10px 0">'
2112
+ + stat(findingTotal, 'findings') + stat(taskTotal, 'tasks')
2113
+ + stat(counts.entity, 'fragments') + stat(counts.reference, 'refs')
2114
+ + '</div>';
2115
+ body += '<div class="text-muted" style="font-size:var(--text-sm)">Browse and prune this project\\'s findings and tasks in the contents pane →</div>';
2001
2116
  } 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>';
2117
+ // GraphRAG-style stats row: links / project / helpful
2118
+ var conn = node.connections || {};
2119
+ var helpful = node.score && typeof node.score.helpful === 'number' ? node.score.helpful : 0;
2120
+ body += '<div class="phren-dossier-stats">'
2121
+ + '<div><div class="k">Links</div><div class="v">' + (conn.total || 0) + '</div></div>'
2122
+ + '<div><div class="k">Project</div><div class="v" style="font-size:11px;letter-spacing:.04em;text-transform:none">' + esc(node.projectName || '—') + '</div></div>'
2123
+ + '<div><div class="k">Helpful</div><div class="v">' + helpful + '</div></div>'
2124
+ + '</div>';
2125
+ body += '<div class="phren-dossier-section">◈ Description</div>';
2126
+ body += '<div id="graph-node-text" class="phren-dossier-text">' + esc(node.tooltipLabel || node.fullLabel || title) + '</div>';
2127
+ // Strongest relationships — related same-topic findings + entity neighbors
2128
+ var rels = strongestRelationships(node);
2129
+ if (rels.length) {
2130
+ body += '<div class="phren-dossier-section">⟿ Strongest relationships · ' + rels.length + '</div>';
2131
+ body += '<div style="margin-top:8px">' + rels.map(function(r) {
2132
+ 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>';
2133
+ }).join('') + '</div>';
2134
+ }
2135
+ if (node.projectName) {
2136
+ body += '<div class="phren-dossier-section">Community</div>';
2137
+ body += '<div style="display:flex;flex-wrap:wrap;gap:8px;margin-top:6px">' + gotoChip(node.projectName, node.projectName, true) + '</div>';
2138
+ }
2139
+ var nav = findingNav(node);
2140
+ if (nav.total > 1 && nav.index !== -1) {
2141
+ 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>');
2142
+ }
2003
2143
  actions.push('<button type="button" class="btn btn-sm" data-graph-action="edit">Edit</button>');
2004
2144
  actions.push('<button type="button" class="btn btn-sm" data-graph-action="delete" style="border-color:var(--danger);color:var(--danger)">Delete</button>');
2005
2145
  } else if (node.kind === 'task') {
@@ -2111,7 +2251,8 @@ export function renderGraphHostScript() {
2111
2251
  }
2112
2252
  graphRequest('/api/findings/' + encodeURIComponent(currentNode.projectName), 'PUT', {
2113
2253
  old_text: currentNode.tooltipLabel || currentNode.fullLabel || '',
2114
- new_text: nextText
2254
+ new_text: nextText,
2255
+ score_key: currentNode.scoreKey || ''
2115
2256
  }).then(function(result) {
2116
2257
  if (!result || !result.ok) throw new Error(result && result.error ? result.error : 'Save failed');
2117
2258
  graphToast('Finding updated', 'ok');
@@ -2156,33 +2297,131 @@ export function renderGraphHostScript() {
2156
2297
  });
2157
2298
  }
2158
2299
 
2159
- function deleteCurrentNode() {
2160
- if (!currentNode) return;
2161
- if (!confirm('Delete this ' + (currentNode.kind || 'node') + '?')) return;
2162
- if (currentNode.kind === 'finding') {
2163
- graphRequest('/api/findings/' + encodeURIComponent(currentNode.projectName), 'DELETE', {
2164
- text: currentNode.tooltipLabel || currentNode.fullLabel || ''
2165
- }).then(function(result) {
2166
- if (!result || !result.ok) throw new Error(result && result.error ? result.error : 'Delete failed');
2167
- graphToast('Finding deleted', 'ok');
2168
- return reloadGraph(null);
2169
- }).catch(function(err) {
2170
- graphToast('Delete failed: ' + err.message, 'err');
2300
+ // Fire the delete API for one node (no confirm, no reload) — reused by single
2301
+ // and batch delete so a bulk prune reloads the graph just once at the end.
2302
+ function deleteNodeRequest(node) {
2303
+ if (!node) return Promise.resolve({ ok: false, error: 'no node' });
2304
+ if (node.kind === 'finding') {
2305
+ return graphRequest('/api/findings/' + encodeURIComponent(node.projectName), 'DELETE', {
2306
+ text: node.tooltipLabel || node.fullLabel || '',
2307
+ score_key: node.scoreKey || ''
2171
2308
  });
2172
- return;
2173
2309
  }
2174
- if (currentNode.kind === 'task') {
2175
- graphRequest('/api/tasks/remove', 'POST', {
2176
- project: currentNode.projectName,
2177
- item: currentNode.stableId || currentNode.id || currentNode.tooltipLabel || currentNode.fullLabel || currentNode.displayLabel || ''
2178
- }).then(function(result) {
2179
- if (!result || !result.ok) throw new Error(result && result.error ? result.error : 'Delete failed');
2180
- graphToast('Task removed', 'ok');
2310
+ if (node.kind === 'task') {
2311
+ return graphRequest('/api/tasks/remove', 'POST', {
2312
+ project: node.projectName,
2313
+ item: node.stableId || node.id || node.tooltipLabel || node.fullLabel || node.displayLabel || ''
2314
+ });
2315
+ }
2316
+ return Promise.resolve({ ok: false, error: 'unsupported' });
2317
+ }
2318
+
2319
+ function deleteNode(node) {
2320
+ if (!node) return;
2321
+ if (!confirm('Delete this ' + (node.kind || 'node') + '?')) return;
2322
+ deleteNodeRequest(node).then(function(result) {
2323
+ if (!result || !result.ok) throw new Error(result && result.error ? result.error : 'Delete failed');
2324
+ graphToast(node.kind === 'task' ? 'Task removed' : 'Finding deleted', 'ok');
2325
+ return reloadGraph(null);
2326
+ }).catch(function(err) {
2327
+ graphToast('Delete failed: ' + err.message, 'err');
2328
+ });
2329
+ }
2330
+
2331
+ function reAddNodes(items) {
2332
+ return Promise.all(items.map(function(it) {
2333
+ if (it.kind === 'finding') {
2334
+ return graphRequest('/api/findings/' + encodeURIComponent(it.projectName), 'POST', { text: it.text }).catch(function() { return { ok: false }; });
2335
+ }
2336
+ if (it.kind === 'task') {
2337
+ return graphRequest('/api/tasks/add', 'POST', { project: it.projectName, item: it.item }).catch(function() { return { ok: false }; });
2338
+ }
2339
+ return Promise.resolve({ ok: false });
2340
+ })).then(function() {
2341
+ graphToast('Restored ' + items.length + ' items', 'ok');
2342
+ return reloadGraph(null);
2343
+ });
2344
+ }
2345
+
2346
+ function deleteNodes(nodes) {
2347
+ if (!nodes || !nodes.length) return;
2348
+ if (nodes.length === 1) { deleteNode(nodes[0]); return; }
2349
+ if (!confirm('Delete ' + nodes.length + ' items?')) return;
2350
+ var undoItems = nodes.map(function(n) {
2351
+ return {
2352
+ kind: n.kind, projectName: n.projectName,
2353
+ text: n.tooltipLabel || n.fullLabel || '',
2354
+ item: n.stableId || n.id || n.tooltipLabel || n.fullLabel || n.displayLabel || ''
2355
+ };
2356
+ });
2357
+ Promise.all(nodes.map(function(n) {
2358
+ return deleteNodeRequest(n).catch(function() { return { ok: false }; });
2359
+ })).then(function(results) {
2360
+ var ok = results.filter(function(r) { return r && r.ok; }).length;
2361
+ return reloadGraph(null).then(function() {
2362
+ graphUndoToast('Deleted ' + ok + ' item' + (ok === 1 ? '' : 's'), function() { reAddNodes(undoItems); });
2363
+ });
2364
+ });
2365
+ }
2366
+
2367
+ // Merge two same-project findings into one: remove the originals, then add
2368
+ // their joined text as a single finding. Offers an Undo that restores the
2369
+ // originals and removes the merged bullet.
2370
+ function mergeNodes(nodes) {
2371
+ if (!nodes || nodes.length !== 2) return;
2372
+ var proj = nodes[0].projectName;
2373
+ var t1 = nodes[0].tooltipLabel || nodes[0].fullLabel || '';
2374
+ var t2 = nodes[1].tooltipLabel || nodes[1].fullLabel || '';
2375
+ if (!t1 || !t2) return;
2376
+ if (!confirm('Merge these 2 findings into one?')) return;
2377
+ var merged = t1 + '\\n' + t2;
2378
+ Promise.all(nodes.map(function(n) {
2379
+ return deleteNodeRequest(n).catch(function() { return { ok: false }; });
2380
+ })).then(function() {
2381
+ return graphRequest('/api/findings/' + encodeURIComponent(proj), 'POST', { text: merged });
2382
+ }).then(function(r) {
2383
+ if (!r || !r.ok) throw new Error(r && r.error ? r.error : 'add failed');
2384
+ return reloadGraph(null).then(function() {
2385
+ graphUndoToast('Merged 2 findings', function() { undoMerge(proj, merged, t1, t2); });
2386
+ });
2387
+ }).catch(function(err) {
2388
+ graphToast('Merge failed: ' + err.message, 'err');
2389
+ return reloadGraph(null);
2390
+ });
2391
+ }
2392
+
2393
+ // Reverse a merge: remove the combined bullet, restore the two originals.
2394
+ function undoMerge(proj, merged, t1, t2) {
2395
+ graphRequest('/api/findings/' + encodeURIComponent(proj), 'DELETE', { text: merged, score_key: '' })
2396
+ .then(function() { return graphRequest('/api/findings/' + encodeURIComponent(proj), 'POST', { text: t1 }); })
2397
+ .then(function() { return graphRequest('/api/findings/' + encodeURIComponent(proj), 'POST', { text: t2 }); })
2398
+ .then(function() {
2399
+ graphToast('Merge undone', 'ok');
2181
2400
  return reloadGraph(null);
2182
2401
  }).catch(function(err) {
2183
- graphToast('Delete failed: ' + err.message, 'err');
2402
+ graphToast('Undo failed: ' + err.message, 'err');
2403
+ return reloadGraph(null);
2184
2404
  });
2185
- }
2405
+ }
2406
+
2407
+ function deleteCurrentNode() {
2408
+ deleteNode(currentNode);
2409
+ }
2410
+
2411
+ // Open the dossier in edit mode for a finding/task chosen in the contents pane.
2412
+ function editNodeFromPane(node) {
2413
+ if (!node || (node.kind !== 'finding' && node.kind !== 'task')) return;
2414
+ var api = graphApi();
2415
+ if (api && api.selectNode) api.selectNode(node.id);
2416
+ setTimeout(function() {
2417
+ if (currentNode && currentNode.id === node.id) {
2418
+ editMode = currentNode.kind === 'task' ? 'task' : 'finding';
2419
+ var point = currentPopoverPoint();
2420
+ renderPopover(currentNode, point.x, point.y);
2421
+ var editor = document.getElementById('graph-node-editor');
2422
+ if (editor) editor.focus();
2423
+ }
2424
+ }, 220);
2186
2425
  }
2187
2426
 
2188
2427
  function completeCurrentTask() {
@@ -2232,9 +2471,28 @@ export function renderGraphHostScript() {
2232
2471
  });
2233
2472
  });
2234
2473
 
2474
+ // Related-node chips — fly to the referenced node
2475
+ document.querySelectorAll('[data-graph-goto]').forEach(function(chipEl) {
2476
+ chipEl.addEventListener('click', function() {
2477
+ var target = chipEl.getAttribute('data-graph-goto') || '';
2478
+ var api = graphApi();
2479
+ if (target && api && api.focusNode) api.focusNode(target);
2480
+ });
2481
+ });
2482
+
2235
2483
  document.querySelectorAll('[data-graph-action]').forEach(function(button) {
2236
2484
  button.addEventListener('click', function() {
2237
2485
  var action = button.getAttribute('data-graph-action');
2486
+ if (action === 'prev-finding' || action === 'next-finding') {
2487
+ if (!currentNode) return;
2488
+ var nav = findingNav(currentNode);
2489
+ if (nav.total < 2 || nav.index === -1) return;
2490
+ var step = action === 'next-finding' ? 1 : -1;
2491
+ var nextIndex = (nav.index + step + nav.total) % nav.total;
2492
+ var api = graphApi();
2493
+ if (api && api.focusNode) api.focusNode(nav.list[nextIndex].id);
2494
+ return;
2495
+ }
2238
2496
  if (action === 'edit') {
2239
2497
  editMode = currentNode && (currentNode.kind === 'finding' || currentNode.kind === 'task') ? currentNode.kind : null;
2240
2498
  var point = currentPopoverPoint();
@@ -2281,6 +2539,14 @@ export function renderGraphHostScript() {
2281
2539
  if (popover) popover.style.display = 'none';
2282
2540
  });
2283
2541
  }
2542
+ if (typeof api.onItemAction === 'function') {
2543
+ api.onItemAction(function(payload, action) {
2544
+ if (action === 'delete') deleteNode(payload);
2545
+ else if (action === 'delete-batch') deleteNodes(payload);
2546
+ else if (action === 'edit') editNodeFromPane(payload);
2547
+ else if (action === 'merge') mergeNodes(payload);
2548
+ });
2549
+ }
2284
2550
  return true;
2285
2551
  }
2286
2552
 
@@ -2288,6 +2554,9 @@ export function renderGraphHostScript() {
2288
2554
  var popover = document.getElementById('graph-node-popover-card');
2289
2555
  if (!currentNode || !popover) return;
2290
2556
  if (popover.contains(event.target)) return;
2557
+ // Renderer-owned HUD overlays are legitimate UI, not a click-away dismiss.
2558
+ var t = event.target;
2559
+ if (t && t.closest && t.closest('.phren-project-panel, .phren-project-nav, .phren-pp-reopen, #graph-filter, .graph-controls, .phren-hud-legend, .phren-hud-stats')) return;
2291
2560
  hidePopover();
2292
2561
  }
2293
2562
 
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.35",
3
+ "version": "0.1.37",
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": {