cladogram 0.6.0-beta.4 → 0.6.0-beta.6
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 +50 -47
- package/docs/agent-context.md +3 -2
- package/docs/agent-reference.md +11 -0
- package/docs/release.md +36 -0
- package/package.json +1 -1
- package/plugins/agent/index.js +932 -153
- package/plugins/agent/style.css +142 -33
- package/plugins/view-controls/index.js +0 -11
- package/plugins/view-controls/style.css +0 -7
- package/skills/clado/SKILL.md +4 -2
- package/src/agent/automations.js +474 -0
- package/src/agent/clado-tools.js +160 -1
- package/src/agent/pi-bridge.js +788 -61
- package/src/html/app-css.js +4 -0
- package/src/html/canvas-chain.js +6 -4
- package/src/html/canvas-live-diff.js +208 -91
- package/src/html/canvas-ui.css +3 -10
- package/src/html/runtime-api.js +6 -0
- package/src/html/runtime.js +179 -73
- package/src/server/agent.js +242 -9
- package/src/server/assets/library-canvas.js +4 -0
- package/src/server/assets/library.css +139 -0
- package/src/server/assets/library.js +281 -23
- package/src/server/mcp.js +88 -20
- package/src/server/workspace.js +165 -3
- package/src/workspace/service.js +190 -8
package/src/html/app-css.js
CHANGED
|
@@ -351,6 +351,10 @@ body.dragging, body.dragging *{user-select:none; -webkit-user-select:none}
|
|
|
351
351
|
}
|
|
352
352
|
[data-theme="dark"] #lensInner .zui-lens-frame{background:#0f172a}
|
|
353
353
|
|
|
354
|
+
.zoomable.zimg{padding:0; background:var(--panel); cursor:zoom-in}
|
|
355
|
+
.zoomable.zimg img{display:block; width:100%; height:auto; max-width:100%; margin:0 auto}
|
|
356
|
+
.zoomable.zimg:hover{border-color:var(--accent)}
|
|
357
|
+
|
|
354
358
|
.zvideo,.zaudio{
|
|
355
359
|
margin-top:8px; border:1px solid var(--line-2); border-radius:8px;
|
|
356
360
|
overflow:hidden; background:var(--bg);
|
package/src/html/canvas-chain.js
CHANGED
|
@@ -63,7 +63,8 @@ function canvasChainDocument(subset, selected) {
|
|
|
63
63
|
var data = child.createElement('script');
|
|
64
64
|
var values = { __CLADO__: subset, __CLADO_CHAIN__: { id: selected, mode: mode }, __CLADO_LIVE__: true,
|
|
65
65
|
__CLADO_DIAGNOSTICS__: [], __CLADO_FILE__: window.__CLADO_FILE__ || '',
|
|
66
|
-
__CLADO_FILE_PATH__: window.__CLADO_FILE_PATH__ || '',
|
|
66
|
+
__CLADO_FILE_PATH__: window.__CLADO_FILE_PATH__ || '', __CLADO_WORKSPACE_ID__: window.__CLADO_WORKSPACE_ID__ || '',
|
|
67
|
+
__CLADO_RESOURCES__: window.__CLADO_RESOURCES__ || {}, __CLADO_OFFLINE__: !!window.__CLADO_OFFLINE__ };
|
|
67
68
|
data.textContent = Object.keys(values).map(function (key) { return 'window.' + key + '=' + JSON.stringify(values[key]).replace(/</g, '\\u003c').replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029') + ';'; }).join('\n');
|
|
68
69
|
child.body.appendChild(data);
|
|
69
70
|
[runtime, ui].forEach(function (source) { var script = child.createElement('script'); script.id = source.id; script.textContent = source.textContent; child.body.appendChild(script); });
|
|
@@ -201,6 +202,7 @@ if (window.__CLADO_CHAIN__) {
|
|
|
201
202
|
if (canvasRecords[id]) { flash(canvasRecords[id].card); canvasChainCenter(id); if (link.dataset.mediaPoint) canvasRevealMediaTarget(link, id); }
|
|
202
203
|
return;
|
|
203
204
|
}
|
|
205
|
+
if (event.target.closest('.zblock-btn:not([data-svg-zoom]):not([data-ui-zoom]),.zcode-preview-btn')) return;
|
|
204
206
|
if (event.target.closest('.zoomable,a')) { event.preventDefault(); event.stopImmediatePropagation(); }
|
|
205
207
|
}, true);
|
|
206
208
|
function chainCenter() { canvasSetFocus(canvasChainInitialId); canvasChainCenter(canvasChainInitialId); }
|
|
@@ -220,14 +222,14 @@ if (window.__CLADO_CHAIN__) {
|
|
|
220
222
|
tx = mx - (mx - tx) * next / scale; ty = my - (my - ty) * next / scale; scale = next; apply(); if (document.body.dataset.mode === 'mindmap') drawMindWires(); else drawWires();
|
|
221
223
|
}
|
|
222
224
|
function chainResources() {
|
|
223
|
-
$$('img[src]:not([data-chain-resource])').forEach(function (
|
|
224
|
-
var href =
|
|
225
|
+
$$('img[src]:not([data-chain-resource]),video[src]:not([data-chain-resource]),audio[src]:not([data-chain-resource])').forEach(function (el) {
|
|
226
|
+
var href = el.getAttribute('src'); if (!href || /^(?:[a-z][a-z0-9+.-]*:|\/\/|\/)/i.test(href) || !window.__CLADO_FILE_PATH__) return;
|
|
225
227
|
try {
|
|
226
228
|
var url = new URL(href, 'https://clado.local/documents/' + window.__CLADO_FILE_PATH__);
|
|
227
229
|
if (!url.pathname.startsWith('/documents/')) return;
|
|
228
230
|
var path = decodeURIComponent(url.pathname.slice('/documents/'.length)), resource = (window.__CLADO_RESOURCES__ || {})[path];
|
|
229
231
|
var workspace = window.__CLADO_WORKSPACE_ID__ ? '&workspace=' + encodeURIComponent(window.__CLADO_WORKSPACE_ID__) : '';
|
|
230
|
-
if (resource || !window.__CLADO_OFFLINE__) {
|
|
232
|
+
if (resource || !window.__CLADO_OFFLINE__) { el.src = resource || '/library/resource?file=' + encodeURIComponent(path) + workspace; el.dataset.chainResource = '1'; }
|
|
231
233
|
} catch (_) {}
|
|
232
234
|
});
|
|
233
235
|
}
|
|
@@ -928,42 +928,67 @@ function startCanvasLinkPick(sourceSpec) {
|
|
|
928
928
|
}
|
|
929
929
|
|
|
930
930
|
/* ── 多角色卡片空间协同(方案 1 · 底部一体状态栏 + 1px 发丝光 + 向下垂落呼吸柔光) ── */
|
|
931
|
-
var cladoPresenceStore = new Map(); //
|
|
932
|
-
var cladoPresenceAfterglowMs =
|
|
933
|
-
var
|
|
931
|
+
var cladoPresenceStore = new Map(); // rawCardKey -> Map<sessionId, entry>
|
|
932
|
+
var cladoPresenceAfterglowMs = 30000;
|
|
933
|
+
var CLADO_PRESENCE_HARD_MAX_MS = 30 * 60 * 1000;
|
|
934
934
|
var cladoPresenceRotTick = 0;
|
|
935
935
|
var cladoPresenceRotTimer = 0;
|
|
936
936
|
var cladoPresenceSweepTimer = 0;
|
|
937
|
+
var cladoPresenceInteractionBound = false;
|
|
938
|
+
var cladoPresenceLastInteractPostAt = 0;
|
|
937
939
|
|
|
938
940
|
function cladoNormalizeTone(tone) {
|
|
939
941
|
return (tone === 'sky' || tone === 'emerald' || tone === 'violet' || tone === 'amber') ? tone : 'sky';
|
|
940
942
|
}
|
|
941
943
|
|
|
942
|
-
function
|
|
943
|
-
var
|
|
944
|
-
if (!
|
|
944
|
+
function cladoToAfterglowLabel(activeLabel, fallback) {
|
|
945
|
+
var raw = String(activeLabel || '').trim();
|
|
946
|
+
if (!raw) return fallback || '刚刚编辑了';
|
|
947
|
+
if (raw.indexOf('刚刚') === 0) return raw;
|
|
948
|
+
if (/^正在(?:新建|创建)/.test(raw)) return '刚刚新建了';
|
|
949
|
+
if (/^正在删除/.test(raw)) return '刚刚删除了';
|
|
950
|
+
if (/^正在移除连线/.test(raw)) return '刚刚移除了连线';
|
|
951
|
+
if (/^正在连线/.test(raw)) return '刚刚连线了';
|
|
952
|
+
if (/^正在调整/.test(raw)) return '刚刚调整了';
|
|
953
|
+
if (/^正在修改\s+(.+)$/.test(raw)) return raw.replace(/^正在修改\s+/, '刚刚修改了 ');
|
|
954
|
+
if (/^正在查看\s+(.+)$/.test(raw)) return raw.replace(/^正在查看\s+/, '刚刚查看了 ');
|
|
955
|
+
if (/^正在查看/.test(raw)) return '刚刚查看了';
|
|
956
|
+
if (/^正在编辑/.test(raw)) return '刚刚编辑了';
|
|
957
|
+
if (/^修改\s+(.+)$/.test(raw)) return raw.replace(/^修改\s+/, '刚刚修改了 ');
|
|
958
|
+
if (/^查看\s+(.+)$/.test(raw)) return raw.replace(/^查看\s+/, '刚刚查看了 ');
|
|
959
|
+
return fallback || '刚刚编辑了';
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
function cladoResolveSingleCardId(raw) {
|
|
963
|
+
var path = Array.isArray(raw) ? raw : (typeof raw === 'string' && raw.trim() ? [raw.trim()] : []);
|
|
964
|
+
if (!path.length) return '';
|
|
945
965
|
var records = Object.values(canvasRecords || {});
|
|
946
|
-
var
|
|
947
|
-
var
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
966
|
+
var rootTitle = String(path[0] || '').trim();
|
|
967
|
+
var match = records.find(function (r) {
|
|
968
|
+
return !r.parent && (r.title === rootTitle || r.id === rootTitle || r.fullPath === rootTitle);
|
|
969
|
+
});
|
|
970
|
+
if (!match) {
|
|
971
|
+
match = records.find(function (r) {
|
|
972
|
+
return r.titlePath.length === path.length && path.every(function (p, i) { return p === r.titlePath[i]; });
|
|
973
|
+
}) || records.find(function (r) { return r.title === path[path.length - 1]; });
|
|
974
|
+
}
|
|
975
|
+
return match ? (match.card || match.id) : '';
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
function cladoNormalizeCardKey(raw) {
|
|
979
|
+
if (Array.isArray(raw)) return String(raw[0] || '').trim();
|
|
980
|
+
return String(raw || '').trim();
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
function cladoHasUnarmedAfterglow() {
|
|
984
|
+
var found = false;
|
|
985
|
+
cladoPresenceStore.forEach(function (map) {
|
|
986
|
+
if (found || !map) return;
|
|
987
|
+
map.forEach(function (entry) {
|
|
988
|
+
if (entry && entry.phase === 'afterglow' && !entry.armedAt) found = true;
|
|
954
989
|
});
|
|
955
|
-
if (!match) {
|
|
956
|
-
match = records.find(function (r) {
|
|
957
|
-
return r.titlePath.length === path.length && path.every(function (p, i) { return p === r.titlePath[i]; });
|
|
958
|
-
}) || records.find(function (r) { return r.title === path[path.length - 1]; });
|
|
959
|
-
}
|
|
960
|
-
var cid = match ? (match.card || match.id) : '';
|
|
961
|
-
if (cid && !seen.has(cid)) {
|
|
962
|
-
seen.add(cid);
|
|
963
|
-
ids.push(cid);
|
|
964
|
-
}
|
|
965
990
|
});
|
|
966
|
-
return
|
|
991
|
+
return found;
|
|
967
992
|
}
|
|
968
993
|
|
|
969
994
|
function cladoEnsurePresenceTimers() {
|
|
@@ -992,24 +1017,17 @@ function cladoEnsurePresenceTimers() {
|
|
|
992
1017
|
function cladoSweepExpiredPresence() {
|
|
993
1018
|
var now = Date.now();
|
|
994
1019
|
var changed = false;
|
|
995
|
-
cladoPresenceStore.forEach(function (map,
|
|
1020
|
+
cladoPresenceStore.forEach(function (map, cardKey) {
|
|
996
1021
|
map.forEach(function (entry, sid) {
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
} else {
|
|
1001
|
-
entry.phase = 'afterglow';
|
|
1002
|
-
entry.label = '超时自动释放';
|
|
1003
|
-
entry.expiresAt = now + cladoPresenceAfterglowMs;
|
|
1004
|
-
}
|
|
1005
|
-
changed = true;
|
|
1006
|
-
} else if (entry.phase === 'afterglow' && entry.expiresAt && now >= entry.expiresAt) {
|
|
1022
|
+
var hardCap = entry.hardExpiresAt || ((entry.ts || now) + CLADO_PRESENCE_HARD_MAX_MS);
|
|
1023
|
+
var exp = entry.expiresAt || hardCap;
|
|
1024
|
+
if (now >= hardCap || (entry.phase === 'afterglow' && entry.armedAt && now >= exp)) {
|
|
1007
1025
|
map.delete(sid);
|
|
1008
1026
|
changed = true;
|
|
1009
1027
|
}
|
|
1010
1028
|
});
|
|
1011
1029
|
if (!map.size) {
|
|
1012
|
-
cladoPresenceStore.delete(
|
|
1030
|
+
cladoPresenceStore.delete(cardKey);
|
|
1013
1031
|
changed = true;
|
|
1014
1032
|
}
|
|
1015
1033
|
});
|
|
@@ -1017,15 +1035,67 @@ function cladoSweepExpiredPresence() {
|
|
|
1017
1035
|
if (changed) cladoSyncAllCardPresenceDom();
|
|
1018
1036
|
}
|
|
1019
1037
|
|
|
1020
|
-
function
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1038
|
+
function cladoArmCanvasAfterglow(notifyParent) {
|
|
1039
|
+
var now = Date.now();
|
|
1040
|
+
var changed = false;
|
|
1041
|
+
var hadUnarmed = false;
|
|
1042
|
+
cladoPresenceStore.forEach(function (map, cardKey) {
|
|
1043
|
+
map.forEach(function (entry, sid) {
|
|
1044
|
+
if (entry.phase !== 'afterglow' || entry.armedAt) return;
|
|
1045
|
+
hadUnarmed = true;
|
|
1046
|
+
if (cladoPresenceAfterglowMs <= 0) {
|
|
1047
|
+
map.delete(sid);
|
|
1048
|
+
} else {
|
|
1049
|
+
entry.armedAt = now;
|
|
1050
|
+
var hardCap = entry.hardExpiresAt || (now + CLADO_PRESENCE_HARD_MAX_MS);
|
|
1051
|
+
entry.expiresAt = Math.min(hardCap, now + cladoPresenceAfterglowMs);
|
|
1052
|
+
}
|
|
1053
|
+
changed = true;
|
|
1054
|
+
});
|
|
1055
|
+
if (!map.size) cladoPresenceStore.delete(cardKey);
|
|
1056
|
+
});
|
|
1057
|
+
if (changed) {
|
|
1058
|
+
cladoEnsurePresenceTimers();
|
|
1059
|
+
cladoSyncAllCardPresenceDom();
|
|
1060
|
+
}
|
|
1061
|
+
if (notifyParent !== false && (hadUnarmed || now - cladoPresenceLastInteractPostAt > 1200)) {
|
|
1062
|
+
cladoPresenceLastInteractPostAt = now;
|
|
1063
|
+
try {
|
|
1064
|
+
if (window.parent && window.parent !== window) {
|
|
1065
|
+
window.parent.postMessage({ type: 'clado-library:canvas-interacted' }, '*');
|
|
1066
|
+
}
|
|
1067
|
+
} catch (e) {}
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
function cladoBindCanvasInteractionArming() {
|
|
1072
|
+
if (cladoPresenceInteractionBound || typeof document === 'undefined') return;
|
|
1073
|
+
cladoPresenceInteractionBound = true;
|
|
1074
|
+
var onInteract = function (ev) {
|
|
1075
|
+
if (ev && ev.isTrusted === false) return;
|
|
1076
|
+
var tgt = ev && ev.target;
|
|
1077
|
+
if (tgt && typeof tgt.closest === 'function' && tgt.closest('.clado-presence-bar')) return;
|
|
1078
|
+
if (!cladoHasUnarmedAfterglow()) return;
|
|
1079
|
+
cladoArmCanvasAfterglow(true);
|
|
1080
|
+
};
|
|
1081
|
+
document.addEventListener('pointerdown', onInteract, { capture: true, passive: true });
|
|
1082
|
+
document.addEventListener('wheel', onInteract, { capture: true, passive: true });
|
|
1083
|
+
document.addEventListener('touchstart', onInteract, { capture: true, passive: true });
|
|
1084
|
+
document.addEventListener('keydown', function (ev) {
|
|
1085
|
+
if (ev && ev.isTrusted === false) return;
|
|
1086
|
+
var k = ev && ev.key;
|
|
1087
|
+
if (k === 'ArrowUp' || k === 'ArrowDown' || k === 'ArrowLeft' || k === 'ArrowRight' || k === '+' || k === '-' || k === '=' || k === '0' || k === ' ') {
|
|
1088
|
+
onInteract(ev);
|
|
1089
|
+
}
|
|
1090
|
+
}, true);
|
|
1091
|
+
var docEl = document.getElementById('doc');
|
|
1092
|
+
if (docEl) {
|
|
1093
|
+
docEl.addEventListener('scroll', onInteract, { passive: true });
|
|
1094
|
+
}
|
|
1025
1095
|
}
|
|
1026
1096
|
|
|
1027
1097
|
function cladoRenderCardPresenceDom(cardId, cardEl, entries) {
|
|
1028
|
-
if (!cardEl) return;
|
|
1098
|
+
if (!cardEl) return false;
|
|
1029
1099
|
if (!entries || !entries.length) {
|
|
1030
1100
|
var had = cardEl.classList.contains('clado-has-presence');
|
|
1031
1101
|
cardEl.classList.remove('clado-has-presence', 'is-afterglow');
|
|
@@ -1062,12 +1132,6 @@ function cladoRenderCardPresenceDom(cardId, cardEl, entries) {
|
|
|
1062
1132
|
if (rz) cardEl.insertBefore(bar, rz);
|
|
1063
1133
|
else cardEl.appendChild(bar);
|
|
1064
1134
|
bar.addEventListener('click', function (ev) {
|
|
1065
|
-
if (ev.target.closest('.clado-presence-dismiss')) {
|
|
1066
|
-
ev.preventDefault();
|
|
1067
|
-
ev.stopPropagation();
|
|
1068
|
-
cladoClearCardPresenceByCardId(cardId);
|
|
1069
|
-
return;
|
|
1070
|
-
}
|
|
1071
1135
|
ev.preventDefault();
|
|
1072
1136
|
ev.stopPropagation();
|
|
1073
1137
|
var targetRow = ev.target.closest('.clado-presence-tip-row');
|
|
@@ -1090,7 +1154,7 @@ function cladoRenderCardPresenceDom(cardId, cardEl, entries) {
|
|
|
1090
1154
|
|
|
1091
1155
|
var actionText = cur.label
|
|
1092
1156
|
? (cur.roleName + ' · ' + cur.label)
|
|
1093
|
-
: (cur.roleName + (cur.phase === 'active' ? ' ·
|
|
1157
|
+
: (cur.roleName + (cur.phase === 'active' ? ' · 正在编辑' : ' · 刚刚编辑了'));
|
|
1094
1158
|
var multiHtml = '';
|
|
1095
1159
|
if (sorted.length >= 2) {
|
|
1096
1160
|
var dots = sorted.map(function (item) {
|
|
@@ -1101,7 +1165,7 @@ function cladoRenderCardPresenceDom(cardId, cardEl, entries) {
|
|
|
1101
1165
|
}
|
|
1102
1166
|
var tipRows = sorted.map(function (item) {
|
|
1103
1167
|
var itemTone = cladoNormalizeTone(item.tone);
|
|
1104
|
-
var statusLabel = item.phase === 'active' ? '进行中' : '
|
|
1168
|
+
var statusLabel = item.phase === 'active' ? '进行中' : (item.armedAt ? '即将消退' : '刚刚变更');
|
|
1105
1169
|
return '<div class="clado-presence-tip-row" data-sid="' + esc(item.sessionId || '') + '" data-rid="' + esc(item.roleId || '') + '" data-code-path="' + esc(item.codePath || '') + '">'
|
|
1106
1170
|
+ '<span class="clado-presence-tip-main"><i class="clado-presence-mdot is-cur" data-tone="' + esc(itemTone) + '"></i><strong>' + esc(item.roleName || '角色') + '</strong>' + (item.label ? ' · ' + esc(item.label) : '') + '</span>'
|
|
1107
1171
|
+ '<span class="clado-presence-tip-phase">' + statusLabel + '</span>'
|
|
@@ -1113,10 +1177,7 @@ function cladoRenderCardPresenceDom(cardId, cardEl, entries) {
|
|
|
1113
1177
|
+ '<i class="clado-presence-dot" aria-hidden="true"></i>'
|
|
1114
1178
|
+ '<span class="clado-presence-text">' + esc(actionText) + '</span>'
|
|
1115
1179
|
+ '</div>'
|
|
1116
|
-
+ '<div class="clado-presence-right">'
|
|
1117
|
-
+ multiHtml
|
|
1118
|
-
+ '<button type="button" class="clado-presence-dismiss" title="清除此卡协同提示">×</button>'
|
|
1119
|
-
+ '</div>'
|
|
1180
|
+
+ (multiHtml ? '<div class="clado-presence-right">' + multiHtml + '</div>' : '')
|
|
1120
1181
|
+ '<div class="clado-presence-tip">' + tipRows + '</div>';
|
|
1121
1182
|
|
|
1122
1183
|
if (!cardEl.querySelector(':scope > .clado-presence-line')) {
|
|
@@ -1135,11 +1196,26 @@ function cladoRenderCardPresenceDom(cardId, cardEl, entries) {
|
|
|
1135
1196
|
}
|
|
1136
1197
|
|
|
1137
1198
|
function cladoSyncAllCardPresenceDom() {
|
|
1199
|
+
var resolvedByCardId = new Map();
|
|
1200
|
+
cladoPresenceStore.forEach(function (map, cardKey) {
|
|
1201
|
+
var cid = cladoResolveSingleCardId(cardKey);
|
|
1202
|
+
if (!cid || !map) return;
|
|
1203
|
+
var bucket = resolvedByCardId.get(cid);
|
|
1204
|
+
if (!bucket) {
|
|
1205
|
+
bucket = new Map();
|
|
1206
|
+
resolvedByCardId.set(cid, bucket);
|
|
1207
|
+
}
|
|
1208
|
+
map.forEach(function (entry, sid) {
|
|
1209
|
+
var prev = bucket.get(sid);
|
|
1210
|
+
if (!prev || (entry.ts || 0) >= (prev.ts || 0)) bucket.set(sid, entry);
|
|
1211
|
+
});
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1138
1214
|
var anyLayoutDelta = false;
|
|
1139
1215
|
Object.keys(render.card || {}).forEach(function (cardId) {
|
|
1140
1216
|
var cardEl = render.card[cardId];
|
|
1141
1217
|
if (!cardEl) return;
|
|
1142
|
-
var map =
|
|
1218
|
+
var map = resolvedByCardId.get(cardId);
|
|
1143
1219
|
var entries = map ? Array.from(map.values()) : [];
|
|
1144
1220
|
if (cladoRenderCardPresenceDom(cardId, cardEl, entries)) anyLayoutDelta = true;
|
|
1145
1221
|
});
|
|
@@ -1153,40 +1229,82 @@ function cladoSetPresenceConfig(cfg) {
|
|
|
1153
1229
|
if (typeof cfg.afterglowMs === 'number' && isFinite(cfg.afterglowMs) && cfg.afterglowMs >= 0) {
|
|
1154
1230
|
cladoPresenceAfterglowMs = Math.min(300000, Math.round(cfg.afterglowMs));
|
|
1155
1231
|
var now = Date.now();
|
|
1156
|
-
cladoPresenceStore.forEach(function (map,
|
|
1232
|
+
cladoPresenceStore.forEach(function (map, cardKey) {
|
|
1157
1233
|
map.forEach(function (entry, sid) {
|
|
1158
1234
|
if (entry.phase === 'afterglow') {
|
|
1159
|
-
if (cladoPresenceAfterglowMs <= 0)
|
|
1160
|
-
|
|
1235
|
+
if (cladoPresenceAfterglowMs <= 0) {
|
|
1236
|
+
map.delete(sid);
|
|
1237
|
+
} else if (entry.armedAt) {
|
|
1238
|
+
var hardCap = entry.hardExpiresAt || (now + CLADO_PRESENCE_HARD_MAX_MS);
|
|
1239
|
+
entry.expiresAt = Math.min(hardCap, entry.armedAt + cladoPresenceAfterglowMs);
|
|
1240
|
+
}
|
|
1161
1241
|
}
|
|
1162
1242
|
});
|
|
1163
|
-
if (!map.size) cladoPresenceStore.delete(
|
|
1243
|
+
if (!map.size) cladoPresenceStore.delete(cardKey);
|
|
1164
1244
|
});
|
|
1165
1245
|
cladoEnsurePresenceTimers();
|
|
1166
1246
|
cladoSyncAllCardPresenceDom();
|
|
1167
1247
|
}
|
|
1168
1248
|
}
|
|
1169
1249
|
|
|
1250
|
+
function cladoSyncCardPresenceSnapshot(entries) {
|
|
1251
|
+
cladoBindCanvasInteractionArming();
|
|
1252
|
+
cladoPresenceStore.clear();
|
|
1253
|
+
var list = Array.isArray(entries) ? entries : [];
|
|
1254
|
+
var now = Date.now();
|
|
1255
|
+
list.forEach(function (item) {
|
|
1256
|
+
if (!item || typeof item !== 'object') return;
|
|
1257
|
+
var cardKey = cladoNormalizeCardKey(item.cardKey || item.card);
|
|
1258
|
+
var sid = String(item.sessionId || item.roleId || 'agent');
|
|
1259
|
+
if (!cardKey) return;
|
|
1260
|
+
var hardCap = Number(item.hardExpiresAt) || ((Number(item.ts) || now) + CLADO_PRESENCE_HARD_MAX_MS);
|
|
1261
|
+
var exp = Number(item.expiresAt) || hardCap;
|
|
1262
|
+
if (now >= hardCap || (item.phase === 'afterglow' && item.armedAt && now >= exp)) return;
|
|
1263
|
+
var m = cladoPresenceStore.get(cardKey);
|
|
1264
|
+
if (!m) {
|
|
1265
|
+
m = new Map();
|
|
1266
|
+
cladoPresenceStore.set(cardKey, m);
|
|
1267
|
+
}
|
|
1268
|
+
m.set(sid, {
|
|
1269
|
+
cardKey: cardKey,
|
|
1270
|
+
sessionId: sid,
|
|
1271
|
+
roleId: String(item.roleId || ''),
|
|
1272
|
+
roleName: String(item.roleName || 'AI 角色'),
|
|
1273
|
+
tone: cladoNormalizeTone(item.tone),
|
|
1274
|
+
label: String(item.label || ''),
|
|
1275
|
+
codePath: String(item.codePath || ''),
|
|
1276
|
+
phase: item.phase === 'afterglow' ? 'afterglow' : 'active',
|
|
1277
|
+
ts: Number(item.ts) || now,
|
|
1278
|
+
armedAt: Number(item.armedAt) || 0,
|
|
1279
|
+
hardExpiresAt: hardCap,
|
|
1280
|
+
expiresAt: exp,
|
|
1281
|
+
});
|
|
1282
|
+
});
|
|
1283
|
+
cladoEnsurePresenceTimers();
|
|
1284
|
+
cladoSyncAllCardPresenceDom();
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1170
1287
|
function cladoSetCardPresence(ev) {
|
|
1171
1288
|
if (!ev || typeof ev !== 'object') return;
|
|
1289
|
+
cladoBindCanvasInteractionArming();
|
|
1172
1290
|
var sid = String(ev.sessionId || ev.roleId || 'agent');
|
|
1173
1291
|
var phase = ev.phase || 'active';
|
|
1174
1292
|
var now = Date.now();
|
|
1175
1293
|
|
|
1176
1294
|
if (phase === 'clear') {
|
|
1177
|
-
var
|
|
1178
|
-
if (
|
|
1179
|
-
|
|
1180
|
-
var m = cladoPresenceStore.get(
|
|
1295
|
+
var clearKeys = (Array.isArray(ev.cards) ? ev.cards : []).map(cladoNormalizeCardKey).filter(Boolean);
|
|
1296
|
+
if (clearKeys.length) {
|
|
1297
|
+
clearKeys.forEach(function (k) {
|
|
1298
|
+
var m = cladoPresenceStore.get(k);
|
|
1181
1299
|
if (m) {
|
|
1182
1300
|
m.delete(sid);
|
|
1183
|
-
if (!m.size) cladoPresenceStore.delete(
|
|
1301
|
+
if (!m.size) cladoPresenceStore.delete(k);
|
|
1184
1302
|
}
|
|
1185
1303
|
});
|
|
1186
1304
|
} else {
|
|
1187
|
-
cladoPresenceStore.forEach(function (m,
|
|
1305
|
+
cladoPresenceStore.forEach(function (m, k) {
|
|
1188
1306
|
m.delete(sid);
|
|
1189
|
-
if (!m.size) cladoPresenceStore.delete(
|
|
1307
|
+
if (!m.size) cladoPresenceStore.delete(k);
|
|
1190
1308
|
});
|
|
1191
1309
|
}
|
|
1192
1310
|
cladoEnsurePresenceTimers();
|
|
@@ -1195,16 +1313,19 @@ function cladoSetCardPresence(ev) {
|
|
|
1195
1313
|
}
|
|
1196
1314
|
|
|
1197
1315
|
if (phase === 'afterglow') {
|
|
1198
|
-
cladoPresenceStore.forEach(function (m,
|
|
1316
|
+
cladoPresenceStore.forEach(function (m, k) {
|
|
1199
1317
|
var existing = m.get(sid);
|
|
1200
|
-
if (!existing) return;
|
|
1318
|
+
if (!existing || existing.phase !== 'active') return;
|
|
1201
1319
|
if (cladoPresenceAfterglowMs <= 0) {
|
|
1202
1320
|
m.delete(sid);
|
|
1203
|
-
if (!m.size) cladoPresenceStore.delete(
|
|
1321
|
+
if (!m.size) cladoPresenceStore.delete(k);
|
|
1204
1322
|
} else {
|
|
1205
1323
|
existing.phase = 'afterglow';
|
|
1206
|
-
existing.
|
|
1207
|
-
|
|
1324
|
+
existing.label = cladoToAfterglowLabel(existing.label, ev.label || '刚刚编辑了');
|
|
1325
|
+
existing.ts = now;
|
|
1326
|
+
existing.armedAt = 0;
|
|
1327
|
+
existing.hardExpiresAt = now + CLADO_PRESENCE_HARD_MAX_MS;
|
|
1328
|
+
existing.expiresAt = existing.hardExpiresAt;
|
|
1208
1329
|
}
|
|
1209
1330
|
});
|
|
1210
1331
|
cladoEnsurePresenceTimers();
|
|
@@ -1212,42 +1333,38 @@ function cladoSetCardPresence(ev) {
|
|
|
1212
1333
|
return;
|
|
1213
1334
|
}
|
|
1214
1335
|
|
|
1215
|
-
// phase === 'active'
|
|
1216
|
-
var
|
|
1217
|
-
if (!
|
|
1218
|
-
var targetSet = new Set(targetIds);
|
|
1336
|
+
// phase === 'active': accumulate ALL cards touched in this turn (do NOT drop earlier cards mid-turn)
|
|
1337
|
+
var rawCards = (Array.isArray(ev.cards) ? ev.cards : []).map(cladoNormalizeCardKey).filter(Boolean);
|
|
1338
|
+
if (!rawCards.length) return;
|
|
1219
1339
|
|
|
1220
|
-
//
|
|
1221
|
-
cladoPresenceStore.forEach(function (m
|
|
1222
|
-
if (targetSet.has(cid)) return;
|
|
1340
|
+
// Refresh 30m hard cap on other still-active cards of this same session
|
|
1341
|
+
cladoPresenceStore.forEach(function (m) {
|
|
1223
1342
|
var existing = m.get(sid);
|
|
1224
1343
|
if (existing && existing.phase === 'active') {
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
if (!m.size) cladoPresenceStore.delete(cid);
|
|
1228
|
-
} else {
|
|
1229
|
-
existing.phase = 'afterglow';
|
|
1230
|
-
existing.expiresAt = now + cladoPresenceAfterglowMs;
|
|
1231
|
-
}
|
|
1344
|
+
existing.hardExpiresAt = now + CLADO_PRESENCE_HARD_MAX_MS;
|
|
1345
|
+
existing.expiresAt = existing.hardExpiresAt;
|
|
1232
1346
|
}
|
|
1233
1347
|
});
|
|
1234
1348
|
|
|
1235
|
-
|
|
1236
|
-
var m = cladoPresenceStore.get(
|
|
1349
|
+
rawCards.forEach(function (cardKey) {
|
|
1350
|
+
var m = cladoPresenceStore.get(cardKey);
|
|
1237
1351
|
if (!m) {
|
|
1238
1352
|
m = new Map();
|
|
1239
|
-
cladoPresenceStore.set(
|
|
1353
|
+
cladoPresenceStore.set(cardKey, m);
|
|
1240
1354
|
}
|
|
1241
1355
|
m.set(sid, {
|
|
1356
|
+
cardKey: cardKey,
|
|
1242
1357
|
sessionId: sid,
|
|
1243
1358
|
roleId: String(ev.roleId || ''),
|
|
1244
1359
|
roleName: String(ev.roleName || 'AI 角色'),
|
|
1245
1360
|
tone: cladoNormalizeTone(ev.tone),
|
|
1246
|
-
label: String(ev.label || ''),
|
|
1361
|
+
label: String(ev.label || '正在编辑'),
|
|
1247
1362
|
codePath: String(ev.codePath || ''),
|
|
1248
1363
|
phase: 'active',
|
|
1249
1364
|
ts: now,
|
|
1250
|
-
|
|
1365
|
+
armedAt: 0,
|
|
1366
|
+
hardExpiresAt: now + CLADO_PRESENCE_HARD_MAX_MS,
|
|
1367
|
+
expiresAt: now + CLADO_PRESENCE_HARD_MAX_MS,
|
|
1251
1368
|
});
|
|
1252
1369
|
});
|
|
1253
1370
|
|
package/src/html/canvas-ui.css
CHANGED
|
@@ -27,8 +27,9 @@
|
|
|
27
27
|
/* 长按标题提取关联链路,主画布和子画布分别保存各自的取景。 */
|
|
28
28
|
.card-title h1,.slice-head,#toc a{touch-action:none;cursor:text;user-select:text;-webkit-user-select:text}
|
|
29
29
|
.card-title h1:focus-visible,.slice-head:focus-visible,#toc a:focus-visible{outline:2px solid var(--accent);outline-offset:3px;border-radius:3px}
|
|
30
|
-
.canvas-chain-dialog{position:fixed;inset:0;width:min(1440px,calc(100vw - 48px));height:calc(100dvh - 64px);max-width:none;max-height:none;margin:auto;padding:0;overflow:hidden}
|
|
31
|
-
.canvas-chain-bar{height:61px;display:flex;align-items:center;gap:14px;padding:0 17px;background
|
|
30
|
+
.canvas-chain-dialog{position:fixed;inset:0;width:min(1440px,calc(100vw - 48px));height:calc(100dvh - 64px);max-width:none;max-height:none;margin:auto;padding:0;overflow:hidden;background:var(--bg);color:var(--fg)}
|
|
31
|
+
.canvas-chain-bar{height:61px;display:flex;align-items:center;gap:14px;padding:0 17px;background:var(--panel);color:var(--fg);border-bottom:1px solid var(--line);--clado-ui-muted:var(--fg-2);--clado-ui-accent:var(--accent);--clado-ui-edge:var(--line);--clado-ui-active:var(--bg)}
|
|
32
|
+
[data-theme="dark"] .canvas-chain-bar{background:#161b22;color:#e6edf3;border-bottom-color:rgba(148,163,184,.2);--clado-ui-muted:#94a3b8;--clado-ui-accent:#60a5fa;--clado-ui-edge:rgba(148,163,184,.24);--clado-ui-active:rgba(255,255,255,.08)}
|
|
32
33
|
.canvas-chain-heading{flex:1;min-width:0;display:flex;flex-direction:column;gap:4px}.canvas-chain-heading strong{font-size:14px;font-weight:600;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.canvas-chain-meta{font-size:11px;color:var(--clado-ui-muted)}
|
|
33
34
|
.canvas-chain-controls{display:flex;align-items:center;gap:6px}.canvas-chain-controls button{width:30px;min-height:30px;padding:0;display:grid;place-items:center;border-radius:7px;font-size:17px}.canvas-chain-dialog iframe{display:block;width:100%;height:calc(100% - 62px);border:0;background:var(--bg)}
|
|
34
35
|
@media(max-width:650px){.canvas-chain-dialog{width:calc(100vw - 16px);height:calc(100dvh - 24px);border-radius:10px}.canvas-chain-bar{padding-inline:10px;gap:8px}.canvas-chain-meta{font-size:10px}}
|
|
@@ -724,14 +725,6 @@ body.clado-link-picking .clado-tag:hover{
|
|
|
724
725
|
.clado-presence-count{
|
|
725
726
|
font-size:10px;opacity:.72;font-weight:520;
|
|
726
727
|
}
|
|
727
|
-
.clado-presence-dismiss{
|
|
728
|
-
appearance:none;border:0;background:transparent;color:currentColor;
|
|
729
|
-
width:16px;height:16px;padding:0;border-radius:50%;
|
|
730
|
-
display:grid;place-items:center;font-size:12px;line-height:1;
|
|
731
|
-
opacity:0;cursor:pointer;transition:opacity 140ms ease,background-color 140ms ease;
|
|
732
|
-
}
|
|
733
|
-
.clado-presence-bar:hover .clado-presence-dismiss{opacity:.65}
|
|
734
|
-
.clado-presence-dismiss:hover{opacity:1!important;background:rgba(var(--p-rgb),.18)}
|
|
735
728
|
.clado-presence-tip{
|
|
736
729
|
position:absolute;left:10px;right:10px;bottom:calc(100% + 6px);z-index:12;
|
|
737
730
|
padding:8px 10px;border-radius:10px;
|
package/src/html/runtime-api.js
CHANGED
|
@@ -294,6 +294,12 @@
|
|
|
294
294
|
setCardPresence: function (ev) {
|
|
295
295
|
if (typeof cladoSetCardPresence === 'function') cladoSetCardPresence(ev);
|
|
296
296
|
},
|
|
297
|
+
syncCardPresence: function (entries) {
|
|
298
|
+
if (typeof cladoSyncCardPresenceSnapshot === 'function') cladoSyncCardPresenceSnapshot(entries);
|
|
299
|
+
},
|
|
300
|
+
armPresenceAfterglow: function () {
|
|
301
|
+
if (typeof cladoArmCanvasAfterglow === 'function') cladoArmCanvasAfterglow(false);
|
|
302
|
+
},
|
|
297
303
|
setPresenceConfig: function (cfg) {
|
|
298
304
|
if (typeof cladoSetPresenceConfig === 'function') cladoSetPresenceConfig(cfg);
|
|
299
305
|
},
|