cladogram 0.6.0-beta.1 → 0.6.0-beta.10

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.
Files changed (39) hide show
  1. package/README.md +50 -47
  2. package/bin/clado.js +34 -2
  3. package/docs/agent-context.md +63 -0
  4. package/docs/agent-reference.md +219 -0
  5. package/docs/release.md +116 -0
  6. package/package.json +3 -1
  7. package/plugins/agent/index.js +2429 -723
  8. package/plugins/agent/settings.js +3592 -0
  9. package/plugins/agent/style.css +1327 -94
  10. package/plugins/view-controls/index.js +0 -11
  11. package/plugins/view-controls/style.css +7 -14
  12. package/skills/clado/SKILL.md +4 -2
  13. package/src/agent/automations.js +454 -0
  14. package/src/agent/clado-tools.js +597 -104
  15. package/src/agent/pi-bridge.js +2184 -112
  16. package/src/agent/pi-config.js +1889 -108
  17. package/src/agent/pi-hooks-perms.js +621 -0
  18. package/src/html/app-css.js +69 -1
  19. package/src/html/canvas-chain.js +32 -6
  20. package/src/html/canvas-focus.js +19 -13
  21. package/src/html/canvas-live-diff.js +1373 -0
  22. package/src/html/canvas-ui.css +503 -2
  23. package/src/html/canvas-wires.js +5 -1
  24. package/src/html/page.js +4 -2
  25. package/src/html/plugin-assets.js +5 -1
  26. package/src/html/plugin-ui.css +1 -1
  27. package/src/html/runtime-api.js +152 -10
  28. package/src/html/runtime.js +546 -37
  29. package/src/server/agent.js +594 -37
  30. package/src/server/assets/library-canvas.js +256 -9
  31. package/src/server/assets/library.css +567 -12
  32. package/src/server/assets/library.html +2 -0
  33. package/src/server/assets/library.js +1028 -32
  34. package/src/server/code-inspect.js +183 -0
  35. package/src/server/mcp.js +90 -22
  36. package/src/server/plugin-registry.js +664 -2
  37. package/src/server/workspace.js +551 -25
  38. package/src/workspace/graph-snapshot.js +695 -0
  39. package/src/workspace/service.js +201 -9
@@ -296,9 +296,77 @@ body.dragging, body.dragging *{user-select:none; -webkit-user-select:none}
296
296
  .zoomable foreignObject{overflow:visible; text-align:center}
297
297
  .zoomable foreignObject > div{text-align:center}
298
298
  /* 代码块也点得开 —— 代码可能写得很长,塞在卡片里只能看个开头 */
299
- .zoomable.zcode{padding:0; border:0; background:transparent; overflow:visible}
299
+ .zoomable.zcode{position:relative; padding:0; border:0; background:transparent; overflow:visible}
300
300
  .zoomable.zcode pre{margin:0 !important}
301
301
  .zoomable.zcode:hover pre{border-color:var(--accent)}
302
+ .zcode-preview-btn{
303
+ position:absolute; top:6px; right:6px; z-index:3;
304
+ appearance:none; border:1px solid var(--line-2); border-radius:6px;
305
+ background:color-mix(in srgb, var(--panel) 88%, transparent);
306
+ color:var(--fg-2); font:inherit; font-size:10.5px; font-weight:560;
307
+ padding:2px 7px; cursor:pointer; opacity:.82;
308
+ transition:opacity .12s, color .12s, border-color .12s, background-color .12s;
309
+ }
310
+ .zcode-preview-btn:hover{opacity:1; color:var(--accent); border-color:var(--accent); background:var(--panel)}
311
+
312
+ /* 富媒体块统一工具栏(SVG 矢量/动画、UI 原型沙盒、视频/音频交付件) */
313
+ .zblock-bar{
314
+ display:flex; align-items:center; justify-content:space-between; gap:8px;
315
+ padding:5px 8px; border-bottom:1px solid var(--line-2);
316
+ background:color-mix(in srgb, var(--panel) 84%, var(--bg));
317
+ font-size:10.5px; color:var(--fg-2); user-select:none;
318
+ }
319
+ .zblock-title{font-weight:600; letter-spacing:.01em; display:inline-flex; align-items:center; gap:5px}
320
+ .zblock-actions{display:inline-flex; align-items:center; gap:4px}
321
+ .zblock-btn{
322
+ appearance:none; border:1px solid transparent; border-radius:5px;
323
+ background:transparent; color:var(--fg-2); font:inherit; font-size:10.5px; font-weight:540;
324
+ padding:2px 6px; cursor:pointer; line-height:1.35;
325
+ transition:background-color .12s, color .12s, border-color .12s;
326
+ }
327
+ .zblock-btn:hover{background:var(--panel); color:var(--fg); border-color:var(--line-2)}
328
+ .zblock-btn.active{background:var(--accent-soft); color:var(--accent); border-color:color-mix(in srgb, var(--accent) 32%, transparent)}
329
+
330
+ .zoomable.zsvg{padding:0; background:var(--bg); cursor:default}
331
+ .zoomable.zsvg .zsvg-stage{padding:10px; cursor:zoom-in; background:var(--panel)}
332
+ .zoomable.zsvg .zsvg-stage svg{display:block; width:100%; height:auto; max-width:100%; margin:0 auto}
333
+ .zoomable.zsvg .zsvg-code{display:none; margin:0 !important; border:0 !important; border-radius:0 !important}
334
+ .zoomable.zsvg.is-code .zsvg-stage{display:none}
335
+ .zoomable.zsvg.is-code .zsvg-code{display:block}
336
+
337
+ .zoomable.zui{padding:0; background:var(--bg); cursor:default}
338
+ .zui-stage{padding:8px; background:var(--bg); display:flex; justify-content:center}
339
+ .zui-frame{
340
+ display:block; width:100%; height:260px; border:1px solid var(--line-2);
341
+ border-radius:7px; background:#fff; transition:width .18s ease, height .16s ease;
342
+ }
343
+ [data-theme="dark"] .zui-frame{background:#0f172a}
344
+ .zoomable.zui.is-mobile .zui-frame{width:375px; max-width:100%}
345
+ .zoomable.zui .zui-code{display:none; margin:0 !important; border:0 !important; border-radius:0 !important}
346
+ .zoomable.zui.is-code .zui-stage{display:none}
347
+ .zoomable.zui.is-code .zui-code{display:block}
348
+ #lensInner .zui-lens-frame{
349
+ display:block; width:min(960px, 84vw); height:min(640px, 76vh);
350
+ border:1px solid var(--line); border-radius:10px; background:#fff;
351
+ }
352
+ [data-theme="dark"] #lensInner .zui-lens-frame{background:#0f172a}
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
+
358
+ .zvideo,.zaudio{
359
+ margin-top:8px; border:1px solid var(--line-2); border-radius:8px;
360
+ overflow:hidden; background:var(--bg);
361
+ }
362
+ .zvideo video{display:block; width:100%; max-height:360px; background:#000}
363
+ .zaudio{padding:8px 10px}
364
+ .zaudio audio{display:block; width:100%; height:34px}
365
+ .zmedia-cap{
366
+ padding:5px 9px; font-size:11px; color:var(--fg-2);
367
+ border-top:1px solid var(--line-2); background:var(--panel);
368
+ }
369
+ .zaudio .zmedia-cap{border-top:0; padding:0 0 6px; background:transparent}
302
370
  #lensInner .markdown-body{background:transparent}
303
371
  #lensInner .markdown-body pre{
304
372
  margin:0 !important; padding:2px 4px !important;
@@ -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__ || '', __CLADO_RESOURCES__: window.__CLADO_RESOURCES__ || {}, __CLADO_OFFLINE__: !!window.__CLADO_OFFLINE__ };
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); });
@@ -114,8 +115,24 @@ function canvasChainPrepareTitles() {
114
115
  title.title = window.__CLADO_CHAIN__ ? '双击或 Enter 聚焦' : '双击或 Enter 聚焦,长按或 Shift+Enter 查看独立链路';
115
116
  });
116
117
  }
118
+ function canvasChainHasContentMutation(records) {
119
+ for (var i = 0; i < records.length; i++) {
120
+ var t = records[i].target;
121
+ if (!t || !t.closest) continue;
122
+ if (t.id === 'wires' || t.id === 'mwires' || t.closest('#wires,#mwires,.port,.clado-obj')) continue;
123
+ return true;
124
+ }
125
+ return false;
126
+ }
127
+ var canvasChainPrepRaf = 0;
117
128
  canvasChainPrepareTitles();
118
- new MutationObserver(canvasChainPrepareTitles).observe($('#world'), { childList: true, subtree: true });
129
+ new MutationObserver(function (records) {
130
+ if (!canvasChainHasContentMutation(records) || canvasChainPrepRaf) return;
131
+ canvasChainPrepRaf = requestAnimationFrame(function () {
132
+ canvasChainPrepRaf = 0;
133
+ canvasChainPrepareTitles();
134
+ });
135
+ }).observe($('#world'), { childList: true, subtree: true });
119
136
  document.addEventListener('pointerdown', function (event) {
120
137
  if (!event.isPrimary) { canvasChainCancelGesture(true); return; }
121
138
  if (window.__CLADO_CHAIN__ || canvasChainIsOpen() || event.button !== 0) return;
@@ -185,6 +202,7 @@ if (window.__CLADO_CHAIN__) {
185
202
  if (canvasRecords[id]) { flash(canvasRecords[id].card); canvasChainCenter(id); if (link.dataset.mediaPoint) canvasRevealMediaTarget(link, id); }
186
203
  return;
187
204
  }
205
+ if (event.target.closest('.zblock-btn:not([data-svg-zoom]):not([data-ui-zoom]),.zcode-preview-btn')) return;
188
206
  if (event.target.closest('.zoomable,a')) { event.preventDefault(); event.stopImmediatePropagation(); }
189
207
  }, true);
190
208
  function chainCenter() { canvasSetFocus(canvasChainInitialId); canvasChainCenter(canvasChainInitialId); }
@@ -204,18 +222,26 @@ if (window.__CLADO_CHAIN__) {
204
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();
205
223
  }
206
224
  function chainResources() {
207
- $$('img[src]:not([data-chain-resource])').forEach(function (img) {
208
- var href = img.getAttribute('src'); if (!href || /^(?:[a-z][a-z0-9+.-]*:|\/\/|\/)/i.test(href) || !window.__CLADO_FILE_PATH__) return;
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;
209
227
  try {
210
228
  var url = new URL(href, 'https://clado.local/documents/' + window.__CLADO_FILE_PATH__);
211
229
  if (!url.pathname.startsWith('/documents/')) return;
212
230
  var path = decodeURIComponent(url.pathname.slice('/documents/'.length)), resource = (window.__CLADO_RESOURCES__ || {})[path];
213
231
  var workspace = window.__CLADO_WORKSPACE_ID__ ? '&workspace=' + encodeURIComponent(window.__CLADO_WORKSPACE_ID__) : '';
214
- if (resource || !window.__CLADO_OFFLINE__) { img.src = resource || '/library/resource?file=' + encodeURIComponent(path) + workspace; img.dataset.chainResource = '1'; }
232
+ if (resource || !window.__CLADO_OFFLINE__) { el.src = resource || '/library/resource?file=' + encodeURIComponent(path) + workspace; el.dataset.chainResource = '1'; }
215
233
  } catch (_) {}
216
234
  });
217
235
  }
218
- chainResources(); new MutationObserver(chainResources).observe($('#world'), { childList: true, subtree: true });
236
+ var chainResRaf = 0;
237
+ chainResources();
238
+ new MutationObserver(function (records) {
239
+ if (!canvasChainHasContentMutation(records) || chainResRaf) return;
240
+ chainResRaf = requestAnimationFrame(function () {
241
+ chainResRaf = 0;
242
+ chainResources();
243
+ });
244
+ }).observe($('#world'), { childList: true, subtree: true });
219
245
  // 弹窗对提取出的卡片重新排布。
220
246
  if (document.body.dataset.mode === 'cards') {
221
247
  openEdge = {}; DOC.edges.forEach(function (edge) { openEdge[edgeKey(edge[0], edge[1])] = 1; });
@@ -1,6 +1,12 @@
1
1
  // 三视图共用内容 ID、聚焦范围与标题手势。
2
2
  var canvasRecords = {}, canvasDocPaths = {}, canvasMindPaths = {}, canvasFocusId = null;
3
- (function () {
3
+ var canvasOut = {}, canvasIn = {};
4
+ function canvasRebuildFocusIndex() {
5
+ canvasRecords = {};
6
+ canvasDocPaths = {};
7
+ canvasMindPaths = {};
8
+ canvasOut = {};
9
+ canvasIn = {};
4
10
  function add(n, docPath, parent, card) {
5
11
  var r = { id: n.id, title: n.title, markdown: n.md, parent: parent, card: card, docPath: docPath, mindPath: '0.' + docPath, kids: [] };
6
12
  r.titlePath = parent ? canvasRecords[parent].titlePath.concat(n.title) : [n.title];
@@ -9,19 +15,19 @@ var canvasRecords = {}, canvasDocPaths = {}, canvasMindPaths = {}, canvasFocusId
9
15
  (n.nodes || n.kids || []).forEach(function (child, i) { r.kids.push(child.id); add(child, docPath + '.' + i, r.id, card); });
10
16
  }
11
17
  DOC.cards.forEach(function (card, i) { add(card, String(i), null, card.id); });
12
- })();
13
- var canvasOut = {}, canvasIn = {};
14
- $$('#article .slice[data-path]').forEach(function (section) {
15
- var source = canvasDocPaths[section.dataset.path]; if (!source) return;
16
- $$('a.edge', section).forEach(function (link) {
17
- var target = canvasRecords[link.dataset.edge]; if (!target) return;
18
- if (link.dataset.anchorId) target = canvasRecords[link.dataset.anchorId] || target;
19
- else if (link.dataset.anchor) target = Object.values(canvasRecords).find(function (r) { return r.card === target.card && r.title === link.dataset.anchor; }) || target;
20
- if (source.id === target.id) return;
21
- (canvasOut[source.id] || (canvasOut[source.id] = new Set())).add(target.id);
22
- (canvasIn[target.id] || (canvasIn[target.id] = new Set())).add(source.id);
18
+ $$('#article .slice[data-path]').forEach(function (section) {
19
+ var source = canvasDocPaths[section.dataset.path]; if (!source) return;
20
+ $$('a.edge', section).forEach(function (link) {
21
+ var target = canvasRecords[link.dataset.edge]; if (!target) return;
22
+ if (link.dataset.anchorId) target = canvasRecords[link.dataset.anchorId] || target;
23
+ else if (link.dataset.anchor) target = Object.values(canvasRecords).find(function (r) { return r.card === target.card && r.title === link.dataset.anchor; }) || target;
24
+ if (source.id === target.id) return;
25
+ (canvasOut[source.id] || (canvasOut[source.id] = new Set())).add(target.id);
26
+ (canvasIn[target.id] || (canvasIn[target.id] = new Set())).add(source.id);
27
+ });
23
28
  });
24
- });
29
+ }
30
+ canvasRebuildFocusIndex();
25
31
  function canvasFocusSet(selected) {
26
32
  if (!selected) return null;
27
33
  if (selected === '__document') return new Set(Object.keys(canvasRecords));