@phren/cli 0.1.36 → 0.1.38
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.
- package/README.md +3 -2
- package/dist/cli/hooks.js +3 -0
- package/dist/cli/namespaces-notes.d.ts +1 -0
- package/dist/cli/namespaces-notes.js +142 -0
- package/dist/cli/namespaces-store.js +2 -3
- package/dist/cli/namespaces.d.ts +1 -0
- package/dist/cli/namespaces.js +1 -0
- package/dist/cli-hooks-git.d.ts +1 -1
- package/dist/cli-hooks-git.js +1 -0
- package/dist/cli-registry.js +19 -0
- package/dist/core/note.d.ts +9 -0
- package/dist/core/note.js +20 -0
- package/dist/data/notes.d.ts +28 -0
- package/dist/data/notes.js +193 -0
- package/dist/generated/memory-ui-graph.browser.js +561 -291
- package/dist/governance/rbac.d.ts +1 -1
- package/dist/governance/rbac.js +4 -0
- package/dist/index.js +2 -0
- package/dist/link/doctor.js +68 -0
- package/dist/link/link.js +17 -1
- package/dist/memory-ui-graph.runtime.js +561 -291
- package/dist/phren-core.d.ts +1 -1
- package/dist/phren-core.js +1 -1
- package/dist/shared/index.js +2 -0
- package/dist/store-registry.d.ts +1 -0
- package/dist/store-registry.js +1 -1
- package/dist/tools/notes.d.ts +3 -0
- package/dist/tools/notes.js +146 -0
- package/dist/ui/data.d.ts +2 -0
- package/dist/ui/data.js +7 -0
- package/dist/ui/graph-chrome.d.ts +1 -1
- package/dist/ui/graph-chrome.js +31 -0
- package/dist/ui/page.js +10 -2
- package/dist/ui/scripts.d.ts +2 -0
- package/dist/ui/scripts.js +466 -29
- package/dist/ui/server.js +89 -23
- package/dist/ui/styles.d.ts +2 -0
- package/dist/ui/styles.js +59 -0
- package/package.json +9 -1
package/dist/ui/scripts.js
CHANGED
|
@@ -84,6 +84,251 @@ export function renderProfileSwitcherScript(_authToken) {
|
|
|
84
84
|
}
|
|
85
85
|
})();`;
|
|
86
86
|
}
|
|
87
|
+
export function renderFindingCaptureEnhancementScript() {
|
|
88
|
+
return `(function() {
|
|
89
|
+
function selectedProject() {
|
|
90
|
+
var card = document.querySelector('.project-card.selected');
|
|
91
|
+
return card ? (card.getAttribute('data-project') || '') : '';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function findingsTab() {
|
|
95
|
+
return document.querySelector('.project-detail-tab[data-file="FINDINGS.md"]');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function wireCaptureBar() {
|
|
99
|
+
var container = document.getElementById('project-content');
|
|
100
|
+
var tab = findingsTab();
|
|
101
|
+
if (!container || !tab || !tab.classList.contains('active')) return;
|
|
102
|
+
|
|
103
|
+
container.querySelectorAll('.finding-detail-card summary').forEach(function(summary) {
|
|
104
|
+
summary.textContent = (summary.textContent || '').replace(/\\s*<!--.*?-->\\s*/g, ' ').trim();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
var input = document.getElementById('finding-add-input');
|
|
108
|
+
if (!input) {
|
|
109
|
+
var project = selectedProject();
|
|
110
|
+
if (!project || container.querySelector('.project-detail-empty')) return;
|
|
111
|
+
var bar = document.createElement('div');
|
|
112
|
+
bar.className = 'finding-capture-bar';
|
|
113
|
+
bar.innerHTML = '<input id="finding-add-input" type="text" placeholder="Record durable knowledge…" aria-label="Finding text">' +
|
|
114
|
+
'<button type="button" class="btn btn-sm btn-primary" data-finding-capture-submit>Add finding</button>';
|
|
115
|
+
container.insertBefore(bar, container.firstChild);
|
|
116
|
+
input = bar.querySelector('#finding-add-input');
|
|
117
|
+
} else {
|
|
118
|
+
var existingBar = input.parentElement;
|
|
119
|
+
if (existingBar) existingBar.classList.add('finding-capture-bar');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (!input || input.getAttribute('data-capture-wired') === 'true') return;
|
|
123
|
+
input.setAttribute('data-capture-wired', 'true');
|
|
124
|
+
input.setAttribute('placeholder', 'Record durable knowledge…');
|
|
125
|
+
input.addEventListener('keydown', function(event) {
|
|
126
|
+
if (event.key !== 'Enter') return;
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
window.phrenAddFinding(selectedProject());
|
|
129
|
+
});
|
|
130
|
+
var button = input.parentElement && input.parentElement.querySelector('button');
|
|
131
|
+
if (button) {
|
|
132
|
+
button.textContent = 'Add finding';
|
|
133
|
+
button.addEventListener('click', function(event) {
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
window.phrenAddFinding(selectedProject());
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
window.selectProjectFile = function(file) {
|
|
141
|
+
var tab = document.querySelector('.project-detail-tab[data-file="' + file + '"]');
|
|
142
|
+
if (tab && typeof window.loadProjectFile === 'function') window.loadProjectFile(file, tab);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
var baseSelectProject = window.selectProject;
|
|
146
|
+
if (typeof baseSelectProject === 'function') {
|
|
147
|
+
window.selectProject = function(name, el) {
|
|
148
|
+
baseSelectProject(name, el);
|
|
149
|
+
var header = document.querySelector('.project-detail-header');
|
|
150
|
+
if (header && !header.querySelector('.capture-finding-btn')) {
|
|
151
|
+
var button = document.createElement('button');
|
|
152
|
+
button.type = 'button';
|
|
153
|
+
button.className = 'btn btn-sm btn-primary capture-finding-btn';
|
|
154
|
+
button.textContent = '+ Add finding';
|
|
155
|
+
button.addEventListener('click', function() {
|
|
156
|
+
window.selectProjectFile('FINDINGS.md');
|
|
157
|
+
window.setTimeout(function() {
|
|
158
|
+
wireCaptureBar();
|
|
159
|
+
var input = document.getElementById('finding-add-input');
|
|
160
|
+
if (input) input.focus();
|
|
161
|
+
}, 0);
|
|
162
|
+
});
|
|
163
|
+
header.appendChild(button);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
var detailArea = document.getElementById('project-detail-area');
|
|
169
|
+
if (detailArea) {
|
|
170
|
+
new MutationObserver(function() { window.setTimeout(wireCaptureBar, 0); })
|
|
171
|
+
.observe(detailArea, { childList: true, subtree: true });
|
|
172
|
+
}
|
|
173
|
+
})();`;
|
|
174
|
+
}
|
|
175
|
+
export function renderNotesEnhancementScript() {
|
|
176
|
+
return `(function() {
|
|
177
|
+
var esc = window._phrenEsc;
|
|
178
|
+
var authUrl = window._phrenAuthUrl;
|
|
179
|
+
|
|
180
|
+
function selectedProject() {
|
|
181
|
+
var card = document.querySelector('.project-card.selected');
|
|
182
|
+
return card ? (card.getAttribute('data-project') || '') : '';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function request(project, method, values, done) {
|
|
186
|
+
window._phrenFetchCsrfToken(function(csrfToken) {
|
|
187
|
+
var body = new URLSearchParams(values || {});
|
|
188
|
+
if (csrfToken) body.set('_csrf', csrfToken);
|
|
189
|
+
fetch(authUrl('/api/notes/' + encodeURIComponent(project)), {
|
|
190
|
+
method: method,
|
|
191
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
192
|
+
body: window._phrenAuthBody(body.toString())
|
|
193
|
+
}).then(function(r) { return r.json(); }).then(function(data) {
|
|
194
|
+
if (!data.ok) throw new Error(data.error || 'Note operation failed');
|
|
195
|
+
done(data);
|
|
196
|
+
}).catch(function(err) { alert(String(err.message || err)); });
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function renderNotes(project, notes) {
|
|
201
|
+
var container = document.getElementById('project-content');
|
|
202
|
+
if (!container) return;
|
|
203
|
+
var today = new Date().toISOString().slice(0, 10);
|
|
204
|
+
var html = '<div class="notes-panel">' +
|
|
205
|
+
'<div class="note-capture">' +
|
|
206
|
+
'<textarea id="note-add-text" rows="3" placeholder="What happened today? Markdown is welcome." aria-label="Note text"></textarea>' +
|
|
207
|
+
'<div class="note-capture-actions"><input id="note-add-date" type="date" value="' + today + '" aria-label="Note date">' +
|
|
208
|
+
'<button type="button" class="btn btn-primary" data-note-action="add">Add note</button></div>' +
|
|
209
|
+
'</div>';
|
|
210
|
+
if (!notes.length) {
|
|
211
|
+
html += '<div class="project-detail-empty">No notes yet. Add a quick daily note above.</div>';
|
|
212
|
+
} else {
|
|
213
|
+
var lastDate = '';
|
|
214
|
+
notes.forEach(function(note) {
|
|
215
|
+
if (note.date !== lastDate) {
|
|
216
|
+
if (lastDate) html += '</div>';
|
|
217
|
+
lastDate = note.date;
|
|
218
|
+
html += '<div class="note-day"><div class="note-day-heading">' + esc(note.date) + '</div>';
|
|
219
|
+
}
|
|
220
|
+
html += '<article class="note-card" data-note-id="' + esc(note.id) + '">' +
|
|
221
|
+
'<div class="note-card-meta"><span>' + esc(String(note.time || '').slice(0, 5)) + '</span>' +
|
|
222
|
+
'<code>' + esc(note.id) + '</code>' +
|
|
223
|
+
(note.promoted ? '<span class="note-promoted">promoted</span>' : '') + '</div>' +
|
|
224
|
+
'<div class="note-card-text">' + esc(note.text).replace(/\\n/g, '<br>') + '</div>' +
|
|
225
|
+
'<div class="note-card-actions">' +
|
|
226
|
+
'<button type="button" class="btn btn-sm" data-note-action="edit">Edit</button>' +
|
|
227
|
+
(!note.promoted ? '<button type="button" class="btn btn-sm" data-note-action="promote">Promote to finding</button>' : '') +
|
|
228
|
+
'<button type="button" class="btn btn-sm note-remove" data-note-action="remove">Remove</button>' +
|
|
229
|
+
'</div>' +
|
|
230
|
+
'<textarea class="note-raw-text" hidden>' + esc(note.text) + '</textarea>' +
|
|
231
|
+
'</article>';
|
|
232
|
+
});
|
|
233
|
+
if (lastDate) html += '</div>';
|
|
234
|
+
}
|
|
235
|
+
container.innerHTML = html + '</div>';
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function loadNotes(focusCapture) {
|
|
239
|
+
var project = selectedProject();
|
|
240
|
+
var container = document.getElementById('project-content');
|
|
241
|
+
if (!project || !container) return;
|
|
242
|
+
container.innerHTML = '<div class="project-detail-empty">Loading notes...</div>';
|
|
243
|
+
fetch(authUrl('/api/notes/' + encodeURIComponent(project)))
|
|
244
|
+
.then(function(r) { return r.json(); })
|
|
245
|
+
.then(function(data) {
|
|
246
|
+
if (!data.ok) throw new Error(data.error || 'Failed to load notes');
|
|
247
|
+
renderNotes(project, (data.data && data.data.notes) || []);
|
|
248
|
+
if (focusCapture) {
|
|
249
|
+
var input = document.getElementById('note-add-text');
|
|
250
|
+
if (input) input.focus();
|
|
251
|
+
}
|
|
252
|
+
}).catch(function(err) {
|
|
253
|
+
container.innerHTML = '<div class="project-detail-empty">' + esc(err.message || err) + '</div>';
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
var baseSelectProject = window.selectProject;
|
|
258
|
+
if (typeof baseSelectProject === 'function') {
|
|
259
|
+
window.selectProject = function(name, el) {
|
|
260
|
+
baseSelectProject(name, el);
|
|
261
|
+
var tabs = document.querySelector('.project-detail-tabs');
|
|
262
|
+
if (tabs && !tabs.querySelector('[data-file="notes:daily"]')) {
|
|
263
|
+
var tab = document.createElement('button');
|
|
264
|
+
tab.type = 'button';
|
|
265
|
+
tab.className = 'project-detail-tab';
|
|
266
|
+
tab.setAttribute('data-ui-action', 'loadProjectFile');
|
|
267
|
+
tab.setAttribute('data-file', 'notes:daily');
|
|
268
|
+
tab.textContent = 'Notes';
|
|
269
|
+
var reference = tabs.querySelector('[data-file="reference:browser"]');
|
|
270
|
+
tabs.insertBefore(tab, reference);
|
|
271
|
+
}
|
|
272
|
+
var header = document.querySelector('.project-detail-header');
|
|
273
|
+
if (header && !header.querySelector('.capture-note-btn')) {
|
|
274
|
+
var button = document.createElement('button');
|
|
275
|
+
button.type = 'button';
|
|
276
|
+
button.className = 'btn btn-sm capture-note-btn';
|
|
277
|
+
button.textContent = '+ Add note';
|
|
278
|
+
button.addEventListener('click', function() {
|
|
279
|
+
window.selectProjectFile('notes:daily');
|
|
280
|
+
window.setTimeout(function() { loadNotes(true); }, 0);
|
|
281
|
+
});
|
|
282
|
+
header.appendChild(button);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
var baseLoadProjectFile = window.loadProjectFile;
|
|
288
|
+
window.loadProjectFile = function(file, btn) {
|
|
289
|
+
if (file !== 'notes:daily') return baseLoadProjectFile(file, btn);
|
|
290
|
+
document.querySelectorAll('.project-detail-tab').forEach(function(tab) { tab.classList.remove('active'); });
|
|
291
|
+
var notesTab = btn || document.querySelector('.project-detail-tab[data-file="notes:daily"]');
|
|
292
|
+
if (notesTab) notesTab.classList.add('active');
|
|
293
|
+
loadNotes(false);
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
document.addEventListener('click', function(event) {
|
|
297
|
+
var button = event.target && event.target.closest ? event.target.closest('[data-note-action]') : null;
|
|
298
|
+
if (!button) return;
|
|
299
|
+
var project = selectedProject();
|
|
300
|
+
if (!project) return;
|
|
301
|
+
var action = button.getAttribute('data-note-action');
|
|
302
|
+
if (action === 'add') {
|
|
303
|
+
var text = document.getElementById('note-add-text');
|
|
304
|
+
var date = document.getElementById('note-add-date');
|
|
305
|
+
if (!text || !text.value.trim()) return;
|
|
306
|
+
request(project, 'POST', { text: text.value.trim(), date: date ? date.value : '' }, function() { loadNotes(true); });
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
var card = button.closest('.note-card');
|
|
310
|
+
if (!card) return;
|
|
311
|
+
var note = card.getAttribute('data-note-id') || '';
|
|
312
|
+
var raw = card.querySelector('.note-raw-text');
|
|
313
|
+
var current = raw ? raw.value : '';
|
|
314
|
+
if (action === 'edit') {
|
|
315
|
+
var next = prompt('Edit note', current);
|
|
316
|
+
if (next === null || !next.trim() || next === current) return;
|
|
317
|
+
request(project, 'PUT', { note: note, text: next.trim() }, function() { loadNotes(false); });
|
|
318
|
+
} else if (action === 'remove') {
|
|
319
|
+
if (!confirm('Remove this note?')) return;
|
|
320
|
+
request(project, 'DELETE', { note: note }, function() { loadNotes(false); });
|
|
321
|
+
} else if (action === 'promote') {
|
|
322
|
+
var findingType = prompt('Finding type (optional): decision, pitfall, pattern, tradeoff, architecture, bug', '');
|
|
323
|
+
if (findingType === null) return;
|
|
324
|
+
findingType = findingType.trim().toLowerCase();
|
|
325
|
+
var valid = ['', 'decision', 'pitfall', 'pattern', 'tradeoff', 'architecture', 'bug'];
|
|
326
|
+
if (valid.indexOf(findingType) === -1) { alert('Unknown finding type.'); return; }
|
|
327
|
+
request(project, 'POST', { action: 'promote', note: note, finding_type: findingType }, function() { loadNotes(false); });
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
})();`;
|
|
331
|
+
}
|
|
87
332
|
export function renderSkillUiEnhancementScript(_authToken) {
|
|
88
333
|
return `(function() {
|
|
89
334
|
var _skillCurrent = null;
|
|
@@ -1764,6 +2009,36 @@ export function renderEventWiringScript() {
|
|
|
1764
2009
|
else if (action === 'clear') { clearBatchSelection(); }
|
|
1765
2010
|
});
|
|
1766
2011
|
|
|
2012
|
+
// The legacy hook rows use .hook-item rather than .split-item. Their original
|
|
2013
|
+
// delegated handler therefore passes null to selectHookFromEl; wire the actual
|
|
2014
|
+
// row here so lifecycle hook details remain selectable.
|
|
2015
|
+
document.addEventListener('click', function(e) {
|
|
2016
|
+
var target = e.target;
|
|
2017
|
+
if (!target || typeof target.closest !== 'function') return;
|
|
2018
|
+
var hook = target.closest('.hook-item[data-ui-action="selectHookFromEl"]');
|
|
2019
|
+
if (hook && typeof selectHookFromEl === 'function') selectHookFromEl(hook);
|
|
2020
|
+
});
|
|
2021
|
+
|
|
2022
|
+
// Keep review-card action metadata aligned with the queue line after an edit.
|
|
2023
|
+
// The base submit handler sends the old line first; this listener then updates
|
|
2024
|
+
// the DOM identity used by subsequent approve/reject actions.
|
|
2025
|
+
document.addEventListener('submit', function(e) {
|
|
2026
|
+
var form = e.target;
|
|
2027
|
+
if (!form || form.getAttribute('data-ui-action') !== 'reviewEditSubmit') return;
|
|
2028
|
+
var card = form.closest('.review-card');
|
|
2029
|
+
var textarea = form.querySelector('textarea[name="new_text"]');
|
|
2030
|
+
if (!card || !textarea) return;
|
|
2031
|
+
var oldLine = form.getAttribute('data-line') || '';
|
|
2032
|
+
var text = String(textarea.value || '').replace(/[\\r\\n]+/g, ' ').trim();
|
|
2033
|
+
if (!text) return;
|
|
2034
|
+
var dateMatch = oldLine.match(/^- \\[(\\d{4}-\\d{2}-\\d{2})\\]\\s*/);
|
|
2035
|
+
var updatedLine = dateMatch ? '- [' + dateMatch[1] + '] ' + text : '- ' + text;
|
|
2036
|
+
var project = card.getAttribute('data-project') || form.getAttribute('data-project') || '';
|
|
2037
|
+
card.setAttribute('data-key', project + '\\\\x00' + updatedLine);
|
|
2038
|
+
form.setAttribute('data-line', updatedLine);
|
|
2039
|
+
card.querySelectorAll('[data-line]').forEach(function(el) { el.setAttribute('data-line', updatedLine); });
|
|
2040
|
+
});
|
|
2041
|
+
|
|
1767
2042
|
// --- Graph controls ---
|
|
1768
2043
|
var graphZoomIn = document.getElementById('graph-zoom-in');
|
|
1769
2044
|
if (graphZoomIn) graphZoomIn.addEventListener('click', function() { graphZoom(1.2); });
|
|
@@ -1854,6 +2129,28 @@ export function renderGraphHostScript() {
|
|
|
1854
2129
|
}, 2600);
|
|
1855
2130
|
}
|
|
1856
2131
|
|
|
2132
|
+
function graphUndoToast(message, onUndo) {
|
|
2133
|
+
var container = document.getElementById('toast-container');
|
|
2134
|
+
if (!container) return;
|
|
2135
|
+
var toast = document.createElement('div');
|
|
2136
|
+
toast.className = 'toast';
|
|
2137
|
+
toast.style.display = 'flex';
|
|
2138
|
+
toast.style.alignItems = 'center';
|
|
2139
|
+
toast.style.gap = '10px';
|
|
2140
|
+
var msg = document.createElement('span');
|
|
2141
|
+
msg.textContent = message;
|
|
2142
|
+
var btn = document.createElement('button');
|
|
2143
|
+
btn.type = 'button';
|
|
2144
|
+
btn.textContent = 'Undo';
|
|
2145
|
+
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';
|
|
2146
|
+
var remove = function() { if (toast.parentNode) toast.parentNode.removeChild(toast); };
|
|
2147
|
+
btn.addEventListener('click', function() { remove(); onUndo(); });
|
|
2148
|
+
toast.appendChild(msg);
|
|
2149
|
+
toast.appendChild(btn);
|
|
2150
|
+
container.appendChild(toast);
|
|
2151
|
+
setTimeout(remove, 8000);
|
|
2152
|
+
}
|
|
2153
|
+
|
|
1857
2154
|
function fetchCsrfToken() {
|
|
1858
2155
|
return fetch(authUrl('/api/csrf-token')).then(function(r) { return r.json(); }).then(function(data) {
|
|
1859
2156
|
return data && data.ok ? (data.token || null) : null;
|
|
@@ -1892,6 +2189,33 @@ export function renderGraphHostScript() {
|
|
|
1892
2189
|
// The dossier docks to the right edge of the graph viewport — a stable
|
|
1893
2190
|
// reading pane instead of a cursor-chasing popover. Signature kept for
|
|
1894
2191
|
// callers; the x/y hint is no longer needed.
|
|
2192
|
+
function ensureDossierResize(popover) {
|
|
2193
|
+
if (!popover || popover.querySelector('.phren-dossier-resize')) return;
|
|
2194
|
+
var handle = document.createElement('div');
|
|
2195
|
+
handle.className = 'phren-dossier-resize';
|
|
2196
|
+
handle.setAttribute('aria-hidden', 'true');
|
|
2197
|
+
handle.addEventListener('pointerdown', function(ev) {
|
|
2198
|
+
ev.preventDefault();
|
|
2199
|
+
ev.stopPropagation();
|
|
2200
|
+
handle.classList.add('dragging');
|
|
2201
|
+
try { handle.setPointerCapture(ev.pointerId); } catch (_) { /* ignore */ }
|
|
2202
|
+
function move(e) {
|
|
2203
|
+
var rect = popover.getBoundingClientRect();
|
|
2204
|
+
var w = Math.max(280, Math.min(680, e.clientX - rect.left));
|
|
2205
|
+
popover.style.width = w + 'px';
|
|
2206
|
+
popover.style.maxWidth = 'none';
|
|
2207
|
+
}
|
|
2208
|
+
function up() {
|
|
2209
|
+
handle.classList.remove('dragging');
|
|
2210
|
+
window.removeEventListener('pointermove', move);
|
|
2211
|
+
window.removeEventListener('pointerup', up);
|
|
2212
|
+
}
|
|
2213
|
+
window.addEventListener('pointermove', move);
|
|
2214
|
+
window.addEventListener('pointerup', up);
|
|
2215
|
+
});
|
|
2216
|
+
popover.appendChild(handle);
|
|
2217
|
+
}
|
|
2218
|
+
|
|
1895
2219
|
function positionPopover(x, y) {
|
|
1896
2220
|
var popover = document.getElementById('graph-node-popover');
|
|
1897
2221
|
if (!popover) return;
|
|
@@ -1900,6 +2224,7 @@ export function renderGraphHostScript() {
|
|
|
1900
2224
|
popover.style.top = '';
|
|
1901
2225
|
popover.style.visibility = 'visible';
|
|
1902
2226
|
popover.style.display = 'block';
|
|
2227
|
+
ensureDossierResize(popover);
|
|
1903
2228
|
}
|
|
1904
2229
|
|
|
1905
2230
|
function currentPopoverPoint() {
|
|
@@ -2053,12 +2378,16 @@ export function renderGraphHostScript() {
|
|
|
2053
2378
|
// Server totals beat visible-adjacency counts (filters can hide nodes)
|
|
2054
2379
|
var findingTotal = typeof node.findingCount === 'number' && node.findingCount > counts.finding ? node.findingCount : counts.finding;
|
|
2055
2380
|
var taskTotal = typeof node.taskCount === 'number' && node.taskCount > counts.task ? node.taskCount : counts.task;
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
body += '
|
|
2381
|
+
// Compact stat line — the detailed findings/tasks browser lives in the
|
|
2382
|
+
// contents pane on the right, so the bulky card grid was redundant.
|
|
2383
|
+
var stat = function(n, label) {
|
|
2384
|
+
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>';
|
|
2385
|
+
};
|
|
2386
|
+
body += '<div style="display:flex;flex-wrap:wrap;gap:16px;padding:10px 0">'
|
|
2387
|
+
+ stat(findingTotal, 'findings') + stat(taskTotal, 'tasks')
|
|
2388
|
+
+ stat(counts.entity, 'fragments') + stat(counts.reference, 'refs')
|
|
2389
|
+
+ '</div>';
|
|
2390
|
+
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>';
|
|
2062
2391
|
} else if (node.kind === 'finding') {
|
|
2063
2392
|
// GraphRAG-style stats row: links / project / helpful
|
|
2064
2393
|
var conn = node.connections || {};
|
|
@@ -2243,34 +2572,131 @@ export function renderGraphHostScript() {
|
|
|
2243
2572
|
});
|
|
2244
2573
|
}
|
|
2245
2574
|
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
if (
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
if (!result || !result.ok) throw new Error(result && result.error ? result.error : 'Delete failed');
|
|
2255
|
-
graphToast('Finding deleted', 'ok');
|
|
2256
|
-
return reloadGraph(null);
|
|
2257
|
-
}).catch(function(err) {
|
|
2258
|
-
graphToast('Delete failed: ' + err.message, 'err');
|
|
2575
|
+
// Fire the delete API for one node (no confirm, no reload) — reused by single
|
|
2576
|
+
// and batch delete so a bulk prune reloads the graph just once at the end.
|
|
2577
|
+
function deleteNodeRequest(node) {
|
|
2578
|
+
if (!node) return Promise.resolve({ ok: false, error: 'no node' });
|
|
2579
|
+
if (node.kind === 'finding') {
|
|
2580
|
+
return graphRequest('/api/findings/' + encodeURIComponent(node.projectName), 'DELETE', {
|
|
2581
|
+
text: node.tooltipLabel || node.fullLabel || '',
|
|
2582
|
+
score_key: node.scoreKey || ''
|
|
2259
2583
|
});
|
|
2260
|
-
return;
|
|
2261
2584
|
}
|
|
2262
|
-
if (
|
|
2263
|
-
graphRequest('/api/tasks/remove', 'POST', {
|
|
2264
|
-
project:
|
|
2265
|
-
item:
|
|
2266
|
-
})
|
|
2267
|
-
|
|
2268
|
-
|
|
2585
|
+
if (node.kind === 'task') {
|
|
2586
|
+
return graphRequest('/api/tasks/remove', 'POST', {
|
|
2587
|
+
project: node.projectName,
|
|
2588
|
+
item: node.stableId || node.id || node.tooltipLabel || node.fullLabel || node.displayLabel || ''
|
|
2589
|
+
});
|
|
2590
|
+
}
|
|
2591
|
+
return Promise.resolve({ ok: false, error: 'unsupported' });
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2594
|
+
function deleteNode(node) {
|
|
2595
|
+
if (!node) return;
|
|
2596
|
+
if (!confirm('Delete this ' + (node.kind || 'node') + '?')) return;
|
|
2597
|
+
deleteNodeRequest(node).then(function(result) {
|
|
2598
|
+
if (!result || !result.ok) throw new Error(result && result.error ? result.error : 'Delete failed');
|
|
2599
|
+
graphToast(node.kind === 'task' ? 'Task removed' : 'Finding deleted', 'ok');
|
|
2600
|
+
return reloadGraph(null);
|
|
2601
|
+
}).catch(function(err) {
|
|
2602
|
+
graphToast('Delete failed: ' + err.message, 'err');
|
|
2603
|
+
});
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
function reAddNodes(items) {
|
|
2607
|
+
return Promise.all(items.map(function(it) {
|
|
2608
|
+
if (it.kind === 'finding') {
|
|
2609
|
+
return graphRequest('/api/findings/' + encodeURIComponent(it.projectName), 'POST', { text: it.text }).catch(function() { return { ok: false }; });
|
|
2610
|
+
}
|
|
2611
|
+
if (it.kind === 'task') {
|
|
2612
|
+
return graphRequest('/api/tasks/add', 'POST', { project: it.projectName, item: it.item }).catch(function() { return { ok: false }; });
|
|
2613
|
+
}
|
|
2614
|
+
return Promise.resolve({ ok: false });
|
|
2615
|
+
})).then(function() {
|
|
2616
|
+
graphToast('Restored ' + items.length + ' items', 'ok');
|
|
2617
|
+
return reloadGraph(null);
|
|
2618
|
+
});
|
|
2619
|
+
}
|
|
2620
|
+
|
|
2621
|
+
function deleteNodes(nodes) {
|
|
2622
|
+
if (!nodes || !nodes.length) return;
|
|
2623
|
+
if (nodes.length === 1) { deleteNode(nodes[0]); return; }
|
|
2624
|
+
if (!confirm('Delete ' + nodes.length + ' items?')) return;
|
|
2625
|
+
var undoItems = nodes.map(function(n) {
|
|
2626
|
+
return {
|
|
2627
|
+
kind: n.kind, projectName: n.projectName,
|
|
2628
|
+
text: n.tooltipLabel || n.fullLabel || '',
|
|
2629
|
+
item: n.stableId || n.id || n.tooltipLabel || n.fullLabel || n.displayLabel || ''
|
|
2630
|
+
};
|
|
2631
|
+
});
|
|
2632
|
+
Promise.all(nodes.map(function(n) {
|
|
2633
|
+
return deleteNodeRequest(n).catch(function() { return { ok: false }; });
|
|
2634
|
+
})).then(function(results) {
|
|
2635
|
+
var ok = results.filter(function(r) { return r && r.ok; }).length;
|
|
2636
|
+
return reloadGraph(null).then(function() {
|
|
2637
|
+
graphUndoToast('Deleted ' + ok + ' item' + (ok === 1 ? '' : 's'), function() { reAddNodes(undoItems); });
|
|
2638
|
+
});
|
|
2639
|
+
});
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
// Merge two same-project findings into one: remove the originals, then add
|
|
2643
|
+
// their joined text as a single finding. Offers an Undo that restores the
|
|
2644
|
+
// originals and removes the merged bullet.
|
|
2645
|
+
function mergeNodes(nodes) {
|
|
2646
|
+
if (!nodes || nodes.length !== 2) return;
|
|
2647
|
+
var proj = nodes[0].projectName;
|
|
2648
|
+
var t1 = nodes[0].tooltipLabel || nodes[0].fullLabel || '';
|
|
2649
|
+
var t2 = nodes[1].tooltipLabel || nodes[1].fullLabel || '';
|
|
2650
|
+
if (!t1 || !t2) return;
|
|
2651
|
+
if (!confirm('Merge these 2 findings into one?')) return;
|
|
2652
|
+
var merged = t1 + '\\n' + t2;
|
|
2653
|
+
Promise.all(nodes.map(function(n) {
|
|
2654
|
+
return deleteNodeRequest(n).catch(function() { return { ok: false }; });
|
|
2655
|
+
})).then(function() {
|
|
2656
|
+
return graphRequest('/api/findings/' + encodeURIComponent(proj), 'POST', { text: merged });
|
|
2657
|
+
}).then(function(r) {
|
|
2658
|
+
if (!r || !r.ok) throw new Error(r && r.error ? r.error : 'add failed');
|
|
2659
|
+
return reloadGraph(null).then(function() {
|
|
2660
|
+
graphUndoToast('Merged 2 findings', function() { undoMerge(proj, merged, t1, t2); });
|
|
2661
|
+
});
|
|
2662
|
+
}).catch(function(err) {
|
|
2663
|
+
graphToast('Merge failed: ' + err.message, 'err');
|
|
2664
|
+
return reloadGraph(null);
|
|
2665
|
+
});
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2668
|
+
// Reverse a merge: remove the combined bullet, restore the two originals.
|
|
2669
|
+
function undoMerge(proj, merged, t1, t2) {
|
|
2670
|
+
graphRequest('/api/findings/' + encodeURIComponent(proj), 'DELETE', { text: merged, score_key: '' })
|
|
2671
|
+
.then(function() { return graphRequest('/api/findings/' + encodeURIComponent(proj), 'POST', { text: t1 }); })
|
|
2672
|
+
.then(function() { return graphRequest('/api/findings/' + encodeURIComponent(proj), 'POST', { text: t2 }); })
|
|
2673
|
+
.then(function() {
|
|
2674
|
+
graphToast('Merge undone', 'ok');
|
|
2269
2675
|
return reloadGraph(null);
|
|
2270
2676
|
}).catch(function(err) {
|
|
2271
|
-
graphToast('
|
|
2677
|
+
graphToast('Undo failed: ' + err.message, 'err');
|
|
2678
|
+
return reloadGraph(null);
|
|
2272
2679
|
});
|
|
2273
|
-
|
|
2680
|
+
}
|
|
2681
|
+
|
|
2682
|
+
function deleteCurrentNode() {
|
|
2683
|
+
deleteNode(currentNode);
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
// Open the dossier in edit mode for a finding/task chosen in the contents pane.
|
|
2687
|
+
function editNodeFromPane(node) {
|
|
2688
|
+
if (!node || (node.kind !== 'finding' && node.kind !== 'task')) return;
|
|
2689
|
+
var api = graphApi();
|
|
2690
|
+
if (api && api.selectNode) api.selectNode(node.id);
|
|
2691
|
+
setTimeout(function() {
|
|
2692
|
+
if (currentNode && currentNode.id === node.id) {
|
|
2693
|
+
editMode = currentNode.kind === 'task' ? 'task' : 'finding';
|
|
2694
|
+
var point = currentPopoverPoint();
|
|
2695
|
+
renderPopover(currentNode, point.x, point.y);
|
|
2696
|
+
var editor = document.getElementById('graph-node-editor');
|
|
2697
|
+
if (editor) editor.focus();
|
|
2698
|
+
}
|
|
2699
|
+
}, 220);
|
|
2274
2700
|
}
|
|
2275
2701
|
|
|
2276
2702
|
function completeCurrentTask() {
|
|
@@ -2388,6 +2814,14 @@ export function renderGraphHostScript() {
|
|
|
2388
2814
|
if (popover) popover.style.display = 'none';
|
|
2389
2815
|
});
|
|
2390
2816
|
}
|
|
2817
|
+
if (typeof api.onItemAction === 'function') {
|
|
2818
|
+
api.onItemAction(function(payload, action) {
|
|
2819
|
+
if (action === 'delete') deleteNode(payload);
|
|
2820
|
+
else if (action === 'delete-batch') deleteNodes(payload);
|
|
2821
|
+
else if (action === 'edit') editNodeFromPane(payload);
|
|
2822
|
+
else if (action === 'merge') mergeNodes(payload);
|
|
2823
|
+
});
|
|
2824
|
+
}
|
|
2391
2825
|
return true;
|
|
2392
2826
|
}
|
|
2393
2827
|
|
|
@@ -2395,6 +2829,9 @@ export function renderGraphHostScript() {
|
|
|
2395
2829
|
var popover = document.getElementById('graph-node-popover-card');
|
|
2396
2830
|
if (!currentNode || !popover) return;
|
|
2397
2831
|
if (popover.contains(event.target)) return;
|
|
2832
|
+
// Renderer-owned HUD overlays are legitimate UI, not a click-away dismiss.
|
|
2833
|
+
var t = event.target;
|
|
2834
|
+
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;
|
|
2398
2835
|
hidePopover();
|
|
2399
2836
|
}
|
|
2400
2837
|
|