cladogram 0.6.0-beta.3 → 0.6.0-beta.5

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.
@@ -62,10 +62,14 @@
62
62
  let text = normalized.replace(/```([a-zA-Z0-9_+-]*)[ \t]*\n([\s\S]*?)(?:```|$)/g, (_, lang, code) => {
63
63
  const idx = fences.length;
64
64
  const cleanCode = code.replace(/\n$/, '');
65
+ const lowLang = String(lang || '').toLowerCase();
66
+ const canPreview = lowLang === 'svg' || lowLang === 'ui' || lowLang === 'html' || lowLang === 'html-preview';
65
67
  fences.push(
66
68
  `<div class="clado-md-pre">`
67
69
  + `<div class="clado-md-pre-head"><span>${esc(lang || 'code')}</span>`
68
- + `<button type="button" class="clado-dock-mini-btn" data-copy-code style="padding:1px 6px;font-size:10.5px;">复制</button></div>`
70
+ + `<span style="display:inline-flex;align-items:center;gap:4px;">`
71
+ + (canPreview ? `<button type="button" class="clado-dock-mini-btn" data-preview-code="${esc(lowLang)}" style="padding:1px 6px;font-size:10.5px;">预览放大</button>` : '')
72
+ + `<button type="button" class="clado-dock-mini-btn" data-copy-code style="padding:1px 6px;font-size:10.5px;">复制</button></span></div>`
69
73
  + `<pre class="clado-scroll"><code>${esc(cleanCode)}</code></pre></div>`
70
74
  );
71
75
  return `\n\u0000FENCE${idx}\u0000\n`;
@@ -233,13 +237,6 @@
233
237
  </div>
234
238
  <div class="clado-session-pop" data-session-pop hidden></div>
235
239
  <div class="clado-dock-stream clado-scroll" data-stream></div>
236
- <div class="clado-dock-handoff">
237
- <span style="color:var(--clado-ui-subtle);">流转至下一阶段</span>
238
- <div style="display:flex;align-items:center;gap:6px;">
239
- <button type="button" class="clado-dock-mini-btn" style="border-color:var(--clado-ui-well-border);background:var(--clado-ui-well);" data-quick-handoff="developer">交给开发落地</button>
240
- <button type="button" class="clado-dock-mini-btn" style="border-color:var(--clado-ui-well-border);background:var(--clado-ui-well);" data-quick-handoff="tester">交给测试验证</button>
241
- </div>
242
- </div>
243
240
  </div>
244
241
  </div>
245
242
 
@@ -452,11 +449,21 @@
452
449
 
453
450
  function renderRoleStrip() {
454
451
  stripEl.replaceChildren();
455
- const visible = sessions.filter(s => !s.archived);
452
+ const visible = sessions
453
+ .filter(s => !s.archived)
454
+ .slice()
455
+ .sort((a, b) => {
456
+ const aRun = a.status === 'running' ? 1 : 0;
457
+ const bRun = b.status === 'running' ? 1 : 0;
458
+ if (aRun !== bRun) return bRun - aRun;
459
+ return String(b.updatedAt || '').localeCompare(String(a.updatedAt || ''));
460
+ });
456
461
  for (const s of visible) {
457
462
  const btn = document.createElement('button');
458
463
  btn.type = 'button';
459
- btn.className = 'clado-role-pill' + (s.id === activeSessionId ? ' active' : '');
464
+ btn.className = 'clado-role-pill'
465
+ + (s.id === activeSessionId ? ' active' : '')
466
+ + (s.status === 'running' ? ' running' : '');
460
467
  btn.dataset.tone = s.tone || 'sky';
461
468
  const badge = s.status === 'running' ? ' · 运行中' : (s.summaryBadge ? ' · ' + s.summaryBadge : '');
462
469
  btn.textContent = s.title + badge;
@@ -847,7 +854,7 @@
847
854
  if (!msgs.length) {
848
855
  const empty = document.createElement('div');
849
856
  empty.className = 'clado-dock-empty';
850
- empty.innerHTML = `当前会话:<strong>${esc(s.title)}</strong>(Pi 1.0 引擎)<br/>可直接描述架构修改、输入 <code>/</code> 调命令,或在画布选中卡片派活交付。<br/>拖动顶部居中横条可调整窗口高度,点击标题可切换或新建会话。`;
857
+ empty.innerHTML = `当前会话:<strong>${esc(s.title)}</strong>(Pi 1.0 引擎)<br/>可直接描述需求、输入 <code>/</code> 调命令,或在画布选中卡片发给当前会话。<br/>拖动顶部居中横条可调整窗口高度,点击标题可切换或新建会话。`;
851
858
  streamEl.append(empty);
852
859
  return;
853
860
  }
@@ -860,14 +867,14 @@
860
867
  if (m.role === 'user') {
861
868
  const div = document.createElement('div');
862
869
  div.className = 'clado-msg-user' + (m.isSteer ? ' is-steer' : '');
863
- const prefix = m.isSteer ? '[中途纠偏] ' : (m.handoffFrom ? `[交接自 ${m.handoffFrom}]\n` : '');
870
+ const prefix = m.isSteer ? '[中途插话] ' : (m.handoffFrom ? `[交接自 ${m.handoffFrom}]\n` : '');
864
871
  div.textContent = prefix + (m.text || '');
865
872
  streamEl.append(div);
866
873
  } else {
867
874
  const msgKey = m.id || `${s.id}_${idx}`;
868
875
  const isRunningMsg = isLast && s.status === 'running';
869
876
 
870
- // 1. Render ordered interleaved blocks (thinking -> text -> tools -> text -> ...)
877
+ // 1. Render ordered interleaved blocks (thinking -> text -> tools -> steer -> text -> ...)
871
878
  if (Array.isArray(m.blocks) && m.blocks.length) {
872
879
  for (let bIdx = 0; bIdx < m.blocks.length; bIdx++) {
873
880
  const block = m.blocks[bIdx];
@@ -876,6 +883,11 @@
876
883
  streamEl.append(buildThinkingTrace(`${msgKey}_th${bIdx}`, block.text));
877
884
  } else if (block?.type === 'tools' && Array.isArray(block.tools) && block.tools.length) {
878
885
  streamEl.append(buildToolTrace(`${msgKey}_b${bIdx}`, block.tools, isRunningMsg && isLastBlock));
886
+ } else if (block?.type === 'steer' && block.text && block.text.trim()) {
887
+ const sdiv = document.createElement('div');
888
+ sdiv.className = 'clado-msg-user is-steer';
889
+ sdiv.textContent = '[中途插话] ' + block.text;
890
+ streamEl.append(sdiv);
879
891
  } else if (block?.type === 'text' && block.text && block.text.trim()) {
880
892
  const div = document.createElement('div');
881
893
  div.className = 'clado-msg-assistant clado-md';
@@ -938,7 +950,57 @@
938
950
  }
939
951
  }
940
952
 
941
- // Copy code button & clickable card/tag chip delegation inside stream
953
+ let chatPreviewMask = null;
954
+ function openChatCodePreview(lang, rawCode) {
955
+ if (!chatPreviewMask) {
956
+ chatPreviewMask = document.createElement('div');
957
+ chatPreviewMask.id = 'clado-chat-preview-modal';
958
+ chatPreviewMask.className = 'clado-vnext-mask';
959
+ chatPreviewMask.hidden = true;
960
+ stageRoot().append(chatPreviewMask);
961
+ chatPreviewMask.addEventListener('click', ev => {
962
+ if (ev.target === chatPreviewMask) chatPreviewMask.hidden = true;
963
+ });
964
+ }
965
+ const isSvg = lang === 'svg';
966
+ const isDark = document.documentElement.dataset.theme === 'dark';
967
+ const bg = isDark ? '#0f172a' : '#f8fafc';
968
+ const fg = isDark ? '#f1f5f9' : '#0f172a';
969
+ let bodySrc = String(rawCode || '');
970
+ if (isSvg) {
971
+ let svgSrc = bodySrc.trim();
972
+ if (!/\bxmlns\s*=/i.test(svgSrc)) svgSrc = svgSrc.replace(/<svg\b/i, '<svg xmlns="http://www.w3.org/2000/svg"');
973
+ svgSrc = svgSrc.replace(/<script\b[\s\S]*?<\/script>/gi, '').replace(/\son[a-z]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, '');
974
+ bodySrc = `<!DOCTYPE html><html lang="zh-CN"><head><meta charset="utf-8"><style>html,body{margin:0;width:100%;height:100%;display:grid;place-items:center;background:${bg};overflow:auto;padding:20px;box-sizing:border-box}svg{max-width:100%;max-height:100%;width:auto;height:auto;transition:transform 140ms ease}</style></head><body>${svgSrc}</body></html>`;
975
+ } else if (!/^\s*<!doctype|^\s*<html\b/i.test(bodySrc)) {
976
+ bodySrc = `<!DOCTYPE html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style>*,*::before,*::after{box-sizing:border-box}html,body{margin:0;padding:14px;background:${bg};color:${fg};font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC",sans-serif;font-size:13px;line-height:1.5}</style></head><body>${bodySrc}</body></html>`;
977
+ }
978
+ chatPreviewMask.innerHTML = `
979
+ <div class="clado-well-box" style="width:min(1040px,calc(100% - 36px));height:min(760px,calc(100% - 36px));display:flex;flex-direction:column;gap:10px;padding:14px 16px;border-radius:18px;background:var(--clado-ui-popover);backdrop-filter:blur(26px) saturate(190%);-webkit-backdrop-filter:blur(26px) saturate(190%);border:1px solid var(--clado-ui-glass-outline);box-shadow:var(--clado-ui-glass-shadow);">
980
+ <div style="display:flex;align-items:center;justify-content:space-between;gap:8px;">
981
+ <strong style="font-size:13.5px;">${isSvg ? 'SVG 矢量放大预览' : 'HTML / UI 隔离沙盒预览'}</strong>
982
+ <div style="display:inline-flex;align-items:center;gap:6px;">
983
+ ${!isSvg ? '<button type="button" class="clado-dock-mini-btn" data-cp-vp="desktop">桌面</button><button type="button" class="clado-dock-mini-btn" data-cp-vp="mobile">手机 (375px)</button>' : ''}
984
+ <button type="button" class="clado-dock-mini-btn" data-cp-close>关闭</button>
985
+ </div>
986
+ </div>
987
+ <div style="flex:1;min-height:0;display:flex;justify-content:center;align-items:stretch;overflow:hidden;border-radius:12px;border:1px solid var(--clado-ui-edge);background:${bg};">
988
+ <iframe data-cp-frame sandbox="allow-scripts" title="预览" style="border:0;width:100%;height:100%;background:${bg};transition:width 180ms ease;"></iframe>
989
+ </div>
990
+ </div>
991
+ `;
992
+ const fr = chatPreviewMask.querySelector('[data-cp-frame]');
993
+ if (fr) fr.srcdoc = bodySrc;
994
+ chatPreviewMask.querySelector('[data-cp-close]').onclick = () => { chatPreviewMask.hidden = true; };
995
+ chatPreviewMask.querySelectorAll('[data-cp-vp]').forEach(b => {
996
+ b.onclick = () => {
997
+ if (fr) fr.style.width = b.dataset.cpVp === 'mobile' ? '375px' : '100%';
998
+ };
999
+ });
1000
+ chatPreviewMask.hidden = false;
1001
+ }
1002
+
1003
+ // Copy code, preview SVG/HTML & clickable card/tag chip delegation inside stream
942
1004
  streamEl.addEventListener('click', e => {
943
1005
  const refTag = e.target.closest?.('[data-ref-tag]');
944
1006
  if (refTag) {
@@ -950,6 +1012,12 @@
950
1012
  actions.focusCanvas?.(null, refCard.dataset.refCard);
951
1013
  return;
952
1014
  }
1015
+ const prevCodeBtn = e.target.closest?.('[data-preview-code]');
1016
+ if (prevCodeBtn) {
1017
+ const code = prevCodeBtn.closest('.clado-md-pre')?.querySelector('pre code')?.textContent || '';
1018
+ openChatCodePreview(prevCodeBtn.dataset.previewCode, code);
1019
+ return;
1020
+ }
953
1021
  const btn = e.target.closest?.('[data-copy-code]');
954
1022
  if (!btn) return;
955
1023
  const code = btn.closest('.clado-md-pre')?.querySelector('pre code')?.textContent || '';
@@ -981,6 +1049,7 @@
981
1049
  });
982
1050
  const data = await res.json();
983
1051
  if (data?.session) {
1052
+ data.session.updatedAt = data.session.updatedAt || new Date().toISOString();
984
1053
  sessions.push(data.session);
985
1054
  closeSessionPop();
986
1055
  selectSession(data.session.id, true);
@@ -1347,6 +1416,7 @@
1347
1416
  stoppingTurn = false;
1348
1417
  pendingCancelPromise = null;
1349
1418
  s.status = 'running';
1419
+ s.updatedAt = new Date().toISOString();
1350
1420
  s.messages = Array.isArray(s.messages) ? s.messages : [];
1351
1421
  const userPromptMsg = {
1352
1422
  id: 'local_u_' + Date.now(),
@@ -1453,6 +1523,14 @@
1453
1523
  renderStream();
1454
1524
  } else if (ev.type === 'focus') {
1455
1525
  actions.focusCanvas?.(ev.file, ev.heading);
1526
+ } else if (ev.type === 'steer' && ev.text) {
1527
+ if (!Array.isArray(liveAssistant.blocks)) liveAssistant.blocks = [];
1528
+ const lastBlk = liveAssistant.blocks[liveAssistant.blocks.length - 1];
1529
+ if (!lastBlk || lastBlk.type !== 'steer' || lastBlk.text !== ev.text) {
1530
+ liveAssistant.blocks.push({ type: 'steer', text: ev.text });
1531
+ }
1532
+ liveAssistant.activity = '已收到中途插话,正在调整方向…';
1533
+ renderStream();
1456
1534
  } else if (ev.type === 'status') {
1457
1535
  liveAssistant.activity = ev.text || liveAssistant.activity;
1458
1536
  showToast(ev.text);
@@ -1578,20 +1656,37 @@
1578
1656
  headers: { 'content-type': 'application/json' },
1579
1657
  body: JSON.stringify({ action: 'steer', session: targetId, text }),
1580
1658
  });
1581
- if (!res.ok) throw new Error('插话失败');
1659
+ const data = await res.json().catch(() => ({}));
1660
+ if (!res.ok || data.ok === false) throw new Error('插话失败');
1582
1661
  if (runningSession && Array.isArray(runningSession.messages)) {
1583
- const insertAt = Math.max(0, runningSession.messages.length - 1);
1584
- runningSession.messages.splice(insertAt, 0, {
1585
- id: 'local_steer_' + Date.now(),
1586
- role: 'user',
1587
- text,
1588
- isSteer: true,
1589
- });
1590
- renderStream();
1662
+ runningSession.updatedAt = new Date().toISOString();
1663
+ const liveMsg = runningSession.messages[runningSession.messages.length - 1];
1664
+ if (liveMsg && liveMsg.role === 'assistant') {
1665
+ if (!Array.isArray(liveMsg.blocks)) liveMsg.blocks = [];
1666
+ const lastBlk = liveMsg.blocks[liveMsg.blocks.length - 1];
1667
+ if (!lastBlk || lastBlk.type !== 'steer' || lastBlk.text !== text) {
1668
+ liveMsg.blocks.push({ type: 'steer', text });
1669
+ }
1670
+ liveMsg.activity = '已收到中途插话,正在调整方向…';
1671
+ } else {
1672
+ runningSession.messages.push({
1673
+ id: 'local_steer_' + Date.now(),
1674
+ role: 'user',
1675
+ text,
1676
+ isSteer: true,
1677
+ });
1678
+ }
1679
+ if (activeSessionId !== targetId) selectSession(targetId, true);
1680
+ else {
1681
+ renderStream();
1682
+ streamEl.scrollTop = streamEl.scrollHeight;
1683
+ }
1591
1684
  }
1592
- showToast('已发送中途纠偏指令');
1685
+ showToast('已发送中途插话');
1593
1686
  } catch {
1594
- showToast('当前回合暂不支持插话,可稍候或点击停止');
1687
+ inputEl.value = text;
1688
+ autoGrowInput();
1689
+ showToast('当前回合尚未就绪,稍候再试或点击停止');
1595
1690
  }
1596
1691
  return;
1597
1692
  }
@@ -1619,33 +1714,6 @@
1619
1714
  }, s);
1620
1715
  }
1621
1716
 
1622
- async function triggerHandoff(targetRoleId, customNote = '') {
1623
- const from = currentSession();
1624
- const targetRole = (meta?.roles || []).find(r => r.id === targetRoleId) || { id: targetRoleId, name: targetRoleId };
1625
- let targetSession = sessions.find(s => !s.archived && s.roleId === targetRole.id);
1626
- if (!targetSession) {
1627
- const res = await fetch(withWs('/library/agent/sessions'), {
1628
- method: 'POST',
1629
- headers: { 'content-type': 'application/json' },
1630
- body: JSON.stringify({ roleId: targetRole.id, title: targetRole.name }),
1631
- });
1632
- const data = await res.json();
1633
- targetSession = data.session;
1634
- if (targetSession) sessions.push(targetSession);
1635
- }
1636
- const canvas = actions.readContext ? actions.readContext() : {};
1637
- showToast(`已交接给「${targetRole.name}」执行`);
1638
- await streamAgentRequest({
1639
- action: 'handoff',
1640
- fromSession: from?.id,
1641
- fromRoleName: from?.title || '画布定稿',
1642
- targetRoleId: targetRole.id,
1643
- targetSession: targetSession?.id,
1644
- text: customNote,
1645
- canvas,
1646
- }, targetSession);
1647
- }
1648
-
1649
1717
  // Bind dock events
1650
1718
  dock.querySelector('[data-toggle-drawer]').onclick = () => setDrawerOpen(!drawerOpen);
1651
1719
  dock.querySelector('[data-collapse]').onclick = () => setDrawerOpen(false);
@@ -1675,9 +1743,6 @@
1675
1743
  if (!res.ok) showToast(data.error || '暂无可回退快照');
1676
1744
  else showToast('已回退画布 ' + data.file);
1677
1745
  };
1678
- dock.querySelectorAll('[data-quick-handoff]').forEach(btn => {
1679
- btn.onclick = () => triggerHandoff(btn.dataset.quickHandoff);
1680
- });
1681
1746
  modelChip.onclick = e => {
1682
1747
  e.stopPropagation();
1683
1748
  closeSessionPop();
@@ -1746,6 +1811,14 @@
1746
1811
  inputEl.focus();
1747
1812
  inputEl.setSelectionRange?.(inputEl.value.length, inputEl.value.length);
1748
1813
  });
1814
+ window.addEventListener('clado:focus-session', ev => {
1815
+ const d = ev.detail || {};
1816
+ const byId = d.sessionId ? sessions.find(s => s.id === d.sessionId) : null;
1817
+ const byRole = !byId && d.roleId ? sessions.find(s => !s.archived && s.roleId === d.roleId) : null;
1818
+ const target = byId || byRole;
1819
+ if (target) selectSession(target.id, true);
1820
+ else setDrawerOpen(true);
1821
+ });
1749
1822
  document.addEventListener('click', e => {
1750
1823
  if (!dock.contains(e.target)) {
1751
1824
  closePopover();
@@ -2043,17 +2116,17 @@
2043
2116
  <div class="clado-setting-row">
2044
2117
  <div>
2045
2118
  <div style="font-size:18px;font-weight:630;">角色与模板</div>
2046
- <div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;">定义各阶段的专业角色(系统提示词、阶段标签、可选专属模型)。</div>
2119
+ <div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;">人设只需专注专业流程与质量标准(如单测规范、代码审查);Clado 会自动注入画布与工具上下文,无需在人设中重复编写工具说明。</div>
2047
2120
  </div>
2048
2121
  <button type="button" class="clado-ui-button clado-ui-button-primary" data-add-role>+ 新建角色</button>
2049
2122
  </div>
2050
2123
  <div data-role-form class="clado-well-box" hidden style="display:none;flex-direction:column;gap:8px;">
2051
2124
  <div style="display:grid;grid-template-columns:1fr 1fr;gap:8px;">
2052
- <input class="clado-field" data-r-name placeholder="角色名称(如:安全审计专家)" />
2053
- <input class="clado-field" data-r-phase placeholder="阶段标签(如:审计阶段)" />
2125
+ <input class="clado-field" data-r-name placeholder="角色名称(如:单元测试专家)" />
2126
+ <input class="clado-field" data-r-phase placeholder="阶段标签(如:单测阶段)" />
2054
2127
  </div>
2055
- <input class="clado-field" data-r-desc placeholder="一句话职责描述" />
2056
- <textarea class="clado-field clado-scroll" data-r-prompt rows="3" placeholder="系统提示词(决定该角色如何协作修改画布或执行代码)"></textarea>
2128
+ <input class="clado-field" data-r-desc placeholder="一句话专业职责描述" />
2129
+ <textarea class="clado-field clado-scroll" data-r-prompt rows="3" placeholder="只需写该角色的专业工作流与细节要求(Clado 平台工具与画布用法会自动注入)"></textarea>
2057
2130
  <div style="display:flex;justify-content:flex-end;gap:8px;">
2058
2131
  <button type="button" class="clado-ui-button" data-r-cancel>取消</button>
2059
2132
  <button type="button" class="clado-ui-button clado-ui-button-primary" data-r-save>保存角色</button>
@@ -2262,32 +2335,123 @@
2262
2335
  }
2263
2336
  }
2264
2337
 
2338
+ let memorySubTab = 'agents';
2265
2339
  function renderMemoryTab() {
2266
2340
  const content = meta.memory?.content || '';
2341
+ const pdocs = meta.platformDocs || {};
2342
+ const ctxPath = pdocs.contextPath || ((meta.agentDir || '~/.pi/agent') + '/clado-context.md');
2343
+ const refPath = pdocs.referencePath || ((meta.agentDir || '~/.pi/agent') + '/clado-reference.md');
2344
+ const ctxContent = pdocs.contextContent || '';
2345
+ const refContent = pdocs.referenceContent || '';
2346
+
2347
+ const isAgents = memorySubTab === 'agents';
2348
+ const isPlatform = memorySubTab === 'platform';
2349
+ const isReference = memorySubTab === 'reference';
2350
+
2267
2351
  sBody.innerHTML = `
2268
2352
  <div class="clado-setting-row">
2269
2353
  <div>
2270
- <div style="font-size:18px;font-weight:630;">工作区与记忆</div>
2271
- <div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;">直接编辑项目根目录的 <code style="font-family:ui-monospace,monospace;">AGENTS.md</code>,Pi 会话启动时自动加载规范。</div>
2354
+ <div style="font-size:18px;font-weight:630;">工作区与平台上下文</div>
2355
+ <div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;">项目记忆 <code style="font-family:ui-monospace,monospace;">AGENTS.md</code> 与自动注入所有角色的 Clado 平台文档。</div>
2356
+ </div>
2357
+ <div style="display:flex;gap:6px;">
2358
+ ${isAgents ? '<button type="button" class="clado-ui-button clado-ui-button-primary" data-save-mem>保存 AGENTS.md</button>' : ''}
2359
+ ${isPlatform ? '<button type="button" class="clado-ui-button" data-reset-pctx style="border-color:var(--clado-ui-well-border);background:var(--clado-ui-well);">恢复默认</button><button type="button" class="clado-ui-button clado-ui-button-primary" data-save-pctx>保存注入文档</button>' : ''}
2272
2360
  </div>
2273
- <button type="button" class="clado-ui-button clado-ui-button-primary" data-save-mem>保存 AGENTS.md</button>
2274
2361
  </div>
2275
- <textarea class="clado-field clado-scroll" data-mem-text style="flex:1;min-height:360px;font-family:ui-monospace,monospace;line-height:1.65;resize:none;" placeholder="# AGENTS.md&#10;&#10;- 写下本项目的代码约定、测试命令与架构约束…">${esc(content)}</textarea>
2362
+ <div class="clado-ctx-pills" style="margin-bottom:2px;">
2363
+ <button type="button" class="clado-ctx-pill-btn ${isAgents ? 'active' : ''}" data-mtab="agents">项目记忆 (AGENTS.md)</button>
2364
+ <button type="button" class="clado-ctx-pill-btn ${isPlatform ? 'active' : ''}" data-mtab="platform">自动注入上下文 (clado-context.md)${pdocs.customized ? ' · 已自定义' : ''}</button>
2365
+ <button type="button" class="clado-ctx-pill-btn ${isReference ? 'active' : ''}" data-mtab="reference">完整参考手册 (clado-reference.md)</button>
2366
+ </div>
2367
+ ${isAgents ? `
2368
+ <div class="clado-well-box clado-setting-row" style="padding:9px 12px;font-size:11.5px;color:var(--clado-ui-muted);">
2369
+ <span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">文件路径:<code style="font-family:ui-monospace,monospace;color:var(--clado-ui-text);">${esc(meta.memory?.path || 'AGENTS.md')}</code></span>
2370
+ </div>
2371
+ <textarea class="clado-field clado-scroll" data-mem-text style="flex:1;min-height:320px;font-family:ui-monospace,monospace;line-height:1.65;resize:none;" placeholder="# AGENTS.md&#10;&#10;- 写下本项目的代码约定、测试命令与架构约束…">${esc(content)}</textarea>
2372
+ ` : isPlatform ? `
2373
+ <div class="clado-well-box clado-setting-row" style="padding:9px 12px;font-size:11.5px;color:var(--clado-ui-muted);gap:8px;">
2374
+ <span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">自动注入所有内置/自定义角色:<code style="font-family:ui-monospace,monospace;color:var(--clado-ui-text);">${esc(ctxPath)}</code></span>
2375
+ <button type="button" class="clado-dock-mini-btn" data-copy-path="${esc(ctxPath)}">复制路径</button>
2376
+ </div>
2377
+ <textarea class="clado-field clado-scroll" data-pctx-text style="flex:1;min-height:320px;font-family:ui-monospace,monospace;line-height:1.65;resize:none;">${esc(ctxContent)}</textarea>
2378
+ ` : `
2379
+ <div class="clado-well-box clado-setting-row" style="padding:9px 12px;font-size:11.5px;color:var(--clado-ui-muted);gap:8px;">
2380
+ <span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">AI 按需 read 查阅的完整手册:<code style="font-family:ui-monospace,monospace;color:var(--clado-ui-text);">${esc(refPath)}</code></span>
2381
+ <button type="button" class="clado-dock-mini-btn" data-copy-path="${esc(refPath)}">复制路径</button>
2382
+ </div>
2383
+ <textarea class="clado-field clado-scroll" readonly style="flex:1;min-height:320px;font-family:ui-monospace,monospace;line-height:1.65;resize:none;opacity:.92;">${esc(refContent)}</textarea>
2384
+ `}
2276
2385
  `;
2277
- sBody.querySelector('[data-save-mem]').onclick = async () => {
2278
- try {
2279
- await apiConfig({ action: 'save_memory', content: sBody.querySelector('[data-mem-text]').value });
2280
- showToast('已保存项目 AGENTS.md');
2281
- } catch (e) { showToast(e.message); }
2282
- };
2386
+
2387
+ sBody.querySelectorAll('[data-mtab]').forEach(btn => {
2388
+ btn.onclick = () => {
2389
+ memorySubTab = btn.dataset.mtab;
2390
+ renderMemoryTab();
2391
+ };
2392
+ });
2393
+ sBody.querySelectorAll('[data-copy-path]').forEach(btn => {
2394
+ btn.onclick = () => {
2395
+ navigator.clipboard?.writeText(btn.dataset.copyPath || '').catch(() => {});
2396
+ showToast('已复制文件路径');
2397
+ };
2398
+ });
2399
+ const saveMemBtn = sBody.querySelector('[data-save-mem]');
2400
+ if (saveMemBtn) {
2401
+ saveMemBtn.onclick = async () => {
2402
+ try {
2403
+ await apiConfig({ action: 'save_memory', content: sBody.querySelector('[data-mem-text]').value });
2404
+ showToast('已保存项目 AGENTS.md');
2405
+ } catch (e) { showToast(e.message); }
2406
+ };
2407
+ }
2408
+ const savePctxBtn = sBody.querySelector('[data-save-pctx]');
2409
+ if (savePctxBtn) {
2410
+ savePctxBtn.onclick = async () => {
2411
+ try {
2412
+ await apiConfig({ action: 'save_platform_context', content: sBody.querySelector('[data-pctx-text]').value });
2413
+ renderMemoryTab();
2414
+ showToast('已保存 Clado 平台注入上下文');
2415
+ } catch (e) { showToast(e.message); }
2416
+ };
2417
+ }
2418
+ const resetPctxBtn = sBody.querySelector('[data-reset-pctx]');
2419
+ if (resetPctxBtn) {
2420
+ resetPctxBtn.onclick = async () => {
2421
+ try {
2422
+ await apiConfig({ action: 'reset_platform_context' });
2423
+ renderMemoryTab();
2424
+ showToast('已恢复默认平台注入文档与参考手册');
2425
+ } catch (e) { showToast(e.message); }
2426
+ };
2427
+ }
2428
+ }
2429
+
2430
+ function readPresenceTtlSeconds() {
2431
+ try {
2432
+ const raw = localStorage.getItem('clado-presence-ttl');
2433
+ if (raw !== null && raw !== '') {
2434
+ const n = Number(raw);
2435
+ if (Number.isFinite(n) && n >= 0) return Math.round(n);
2436
+ }
2437
+ } catch {}
2438
+ return 15;
2283
2439
  }
2284
2440
 
2285
2441
  function renderAppearanceTab() {
2286
2442
  const isDark = document.documentElement.dataset.theme === 'dark';
2443
+ const curTtl = readPresenceTtlSeconds();
2444
+ const ttlOptions = [
2445
+ [0, '立即关闭 (0s)'],
2446
+ [10, '10 秒'],
2447
+ [15, '15 秒 (默认)'],
2448
+ [30, '30 秒'],
2449
+ [60, '60 秒'],
2450
+ ];
2287
2451
  sBody.innerHTML = `
2288
2452
  <div>
2289
2453
  <div style="font-size:18px;font-weight:630;">外观与连接</div>
2290
- <div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;">液态冰晶玻璃主题、画布导出与外部 /mcp 互联端点。</div>
2454
+ <div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;">液态冰晶玻璃主题、卡片协同呼吸余韵、画布导出与外部 /mcp 互联端点。</div>
2291
2455
  </div>
2292
2456
  <div class="clado-well-box clado-setting-row">
2293
2457
  <div>
@@ -2296,6 +2460,15 @@
2296
2460
  </div>
2297
2461
  <button type="button" class="clado-ui-button clado-ui-button-primary" data-toggle-theme>${isDark ? '切换浅色' : '切换暗色'}</button>
2298
2462
  </div>
2463
+ <div class="clado-well-box" style="display:flex;flex-direction:column;gap:10px;">
2464
+ <div>
2465
+ <div style="font-size:13.5px;font-weight:610;">卡片协同呼吸余韵</div>
2466
+ <div style="font-size:12px;color:var(--clado-ui-muted);margin-top:2px;">AI 执行期间卡片底部呼吸自动常亮,回合结束/停止后自动释放并保留短暂余韵(无需手动解锁)。</div>
2467
+ </div>
2468
+ <div class="clado-ctx-pills" data-presence-ttl-group>
2469
+ ${ttlOptions.map(([sec, label]) => `<button type="button" class="clado-ctx-pill-btn ${curTtl === sec ? 'active' : ''}" data-presence-ttl="${sec}">${label}</button>`).join('')}
2470
+ </div>
2471
+ </div>
2299
2472
  ${actions.capture ? `
2300
2473
  <div class="clado-well-box clado-setting-row">
2301
2474
  <div>
@@ -2317,6 +2490,16 @@
2317
2490
  actions.setTheme?.(next);
2318
2491
  renderAppearanceTab();
2319
2492
  };
2493
+ sBody.querySelectorAll('[data-presence-ttl]').forEach(btn => {
2494
+ btn.onclick = () => {
2495
+ const sec = Number(btn.dataset.presenceTtl);
2496
+ if (!Number.isFinite(sec) || sec < 0) return;
2497
+ try { localStorage.setItem('clado-presence-ttl', String(sec)); } catch {}
2498
+ window.dispatchEvent(new CustomEvent('clado:presence-config', { detail: { afterglowMs: sec * 1000 } }));
2499
+ renderAppearanceTab();
2500
+ showToast(sec === 0 ? '卡片呼吸余韵已设为结束后立即关闭' : `卡片呼吸余韵已设为 ${sec} 秒`);
2501
+ };
2502
+ });
2320
2503
  const cap = sBody.querySelector('[data-cap-shot]');
2321
2504
  if (cap) cap.onclick = () => { settingsMask.hidden = true; actions.capture?.(); };
2322
2505
  sBody.querySelector('[data-copy-mcp]').onclick = () => {
@@ -2326,57 +2509,7 @@
2326
2509
  }
2327
2510
 
2328
2511
  // =========================================================================
2329
- // 4. Design-to-Delivery Handoff Modal
2330
- // =========================================================================
2331
- const handoffMask = document.createElement('div');
2332
- handoffMask.className = 'clado-vnext-mask';
2333
- handoffMask.id = 'clado-handoff-modal';
2334
- handoffMask.hidden = true;
2335
- stageRoot().append(handoffMask);
2336
- handoffMask.addEventListener('click', e => { if (e.target === handoffMask) handoffMask.hidden = true; });
2337
-
2338
- function openHandoff() {
2339
- const ctx = actions.readContext ? actions.readContext() : {};
2340
- const selCount = ctx.selection?.length || 0;
2341
- const scopeText = selCount
2342
- ? `当前已选中 ${selCount} 项画布卡片(${ctx.file || '当前画布'}),将作为结构化设计契约交接给目标角色。`
2343
- : `将当前画布(${ctx.file || '当前工作区'})的完整设计交接给目标角色落地执行。`;
2344
- const roles = (meta?.roles || []).filter(r => r.id !== 'architect');
2345
- handoffMask.innerHTML = `
2346
- <div class="clado-handoff-card">
2347
- <div style="display:flex;align-items:center;justify-content:space-between;">
2348
- <div style="font-size:16.5px;font-weight:630;">将画布设计交付为实际产物</div>
2349
- <button type="button" class="clado-ui-button" data-close-ho style="width:28px;height:28px;padding:0;min-height:28px;">${ICONS.close}</button>
2350
- </div>
2351
- <p style="font-size:12.5px;color:var(--clado-ui-muted);margin:6px 0 14px;line-height:1.58;">${esc(scopeText)}</p>
2352
- <input class="clado-field" data-ho-note placeholder="补充交付要求(可选,例如:补齐并发重放单测)" style="margin-bottom:12px;" />
2353
- <div data-ho-list style="display:flex;flex-direction:column;gap:9px;"></div>
2354
- </div>
2355
- `;
2356
- handoffMask.querySelector('[data-close-ho]').onclick = () => { handoffMask.hidden = true; };
2357
- const list = handoffMask.querySelector('[data-ho-list]');
2358
- for (const r of roles) {
2359
- const row = document.createElement('div');
2360
- row.className = 'clado-well-box clado-setting-row clado-handoff-opt';
2361
- row.innerHTML = `
2362
- <div>
2363
- <div style="font-size:13px;font-weight:610;">交给「${esc(r.name)}」执行</div>
2364
- <div style="font-size:11.5px;color:var(--clado-ui-muted);margin-top:2px;">${esc(r.description)}</div>
2365
- </div>
2366
- <span class="clado-chip ${TONE_CHIP[r.tone] || 'clado-chip-mint'}">${esc(r.phase)}</span>
2367
- `;
2368
- row.onclick = () => {
2369
- const note = handoffMask.querySelector('[data-ho-note]').value.trim();
2370
- handoffMask.hidden = true;
2371
- triggerHandoff(r.id, note);
2372
- };
2373
- list.append(row);
2374
- }
2375
- handoffMask.hidden = false;
2376
- }
2377
-
2378
- // =========================================================================
2379
- // 5. Bootstrap & Public API
2512
+ // 4. Bootstrap & Public API
2380
2513
  // =========================================================================
2381
2514
  function applyMeta(data) {
2382
2515
  meta = data;
@@ -2420,15 +2553,23 @@
2420
2553
  return Boolean(comps.find(c => c.id === id)?.enabled);
2421
2554
  }
2422
2555
 
2556
+ function focusComposer(prefill = '') {
2557
+ setDrawerOpen(true);
2558
+ if (prefill) {
2559
+ inputEl.value = prefill;
2560
+ autoGrowInput();
2561
+ }
2562
+ inputEl.focus();
2563
+ }
2564
+
2423
2565
  window.CladoVNext = {
2424
2566
  openSettings,
2425
- openHandoff,
2426
- triggerHandoff,
2427
2567
  startCodeAnalysis,
2428
2568
  refreshMeta,
2429
2569
  getMeta: () => meta,
2430
2570
  isComponentEnabled,
2431
2571
  setDrawerOpen,
2572
+ focusComposer,
2432
2573
  renderMarkdown,
2433
2574
  };
2434
2575
 
@@ -2436,18 +2577,9 @@
2436
2577
 
2437
2578
  return {
2438
2579
  openSettings,
2439
- openHandoff,
2440
- triggerHandoff,
2441
2580
  startCodeAnalysis,
2442
2581
  refreshMeta,
2443
- focusComposer(prefill = '') {
2444
- setDrawerOpen(true);
2445
- if (prefill) {
2446
- inputEl.value = prefill;
2447
- autoGrowInput();
2448
- }
2449
- inputEl.focus();
2450
- },
2582
+ focusComposer,
2451
2583
  };
2452
2584
  };
2453
2585
  })();