A new Activity page on the rail (and the home page's recent list) shows, by day,
what the plugin changed. Record only; undo comes later (AD-018).
- api/activity_log.py keeps the newest 500 entries in the ComfyUI user folder.
A middleware records this plugin's and Anomalous_TTS's write requests after
they succeed (including the 200 + {"status": "error"} style as failure), from
one route table; the log never fails the request it records.
- activity_canvas.js: a press inside Anomalous snapshots the canvas; the next
press or key outside it (or the next press inside) logs the difference, so
every button, drag and dialog that writes nodes is covered and the user's own
edits are not. Opening another workflow is logged as that. <html> carries an
Anomalous class and does not count as the plugin's interface.
- activity_diff.js: pure snapshot and difference; activity_log.js: client and
wording; ui_activity.js: the page (filters, details, find on canvas, clear)
and the home list.
- Tests: tests/activity_diff.mjs, tests/test_activity_log.py (local).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
2.3 KiB
JavaScript
64 lines
2.3 KiB
JavaScript
/**
|
|
* Canvas snapshots and their difference, for the activity log. Pure: takes a graph-like
|
|
* object (`_nodes` or `nodes`, each with `id`, `type`, `title`, `widgets`), no DOM.
|
|
*/
|
|
|
|
/** Text form of a widget value, so values compare and store the same way. */
|
|
function valueText(value) {
|
|
if (typeof value === 'string') return value;
|
|
try {
|
|
return JSON.stringify(value) ?? '';
|
|
} catch (_) {
|
|
return String(value);
|
|
}
|
|
}
|
|
|
|
/** `Map(node id → { type, title, widgets: { name → text } })`; buttons have no value. */
|
|
export function snapshotGraph(graph) {
|
|
const nodes = new Map();
|
|
for (const node of graph?._nodes || graph?.nodes || []) {
|
|
if (node?.id === undefined || node.id === null) continue;
|
|
const widgets = {};
|
|
for (const widget of node.widgets || []) {
|
|
if (!widget?.name || widget.type === 'button') continue;
|
|
widgets[widget.name] = valueText(widget.value);
|
|
}
|
|
nodes.set(String(node.id), { type: node.type || '', title: node.title || node.type || '', widgets });
|
|
}
|
|
return nodes;
|
|
}
|
|
|
|
const nodeLabel = (id, node) => `${node.title} #${id}`;
|
|
|
|
/**
|
|
* What changed from `before` to `after` (both from snapshotGraph): widget values
|
|
* (`changed`), nodes `added` and `removed`, in canvas order.
|
|
*/
|
|
export function diffSnapshots(before, after) {
|
|
const changes = [];
|
|
for (const [id, now] of after) {
|
|
const was = before.get(id);
|
|
if (!was) {
|
|
changes.push({ kind: 'added', node: nodeLabel(id, now), type: now.type });
|
|
continue;
|
|
}
|
|
for (const name of new Set([...Object.keys(was.widgets), ...Object.keys(now.widgets)])) {
|
|
if (was.widgets[name] === now.widgets[name]) continue;
|
|
changes.push({
|
|
kind: 'changed', node: nodeLabel(id, now), type: now.type, widget: name,
|
|
before: was.widgets[name] ?? '', after: now.widgets[name] ?? '',
|
|
});
|
|
}
|
|
}
|
|
for (const [id, was] of before) {
|
|
if (!after.has(id)) changes.push({ kind: 'removed', node: nodeLabel(id, was), type: was.type });
|
|
}
|
|
return changes;
|
|
}
|
|
|
|
/** The node id in a change's `node` label (`KSampler #12` → `12`), or null. */
|
|
export function changeNodeId(change) {
|
|
const match = /#([^#\s]+)$/.exec(String(change?.node || ''));
|
|
return match ? match[1] : null;
|
|
}
|