@vincentbanana/banana-gui 0.6.0 → 0.7.0

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/ui/app.js CHANGED
@@ -40,6 +40,7 @@ const ICONS = {
40
40
  minimize: '<path d="M5 12h14"/>',
41
41
  maximize: '<rect x="6" y="6" width="12" height="12" rx="1"/>',
42
42
  restore: '<rect x="5" y="8" width="9" height="9" rx="1"/><path d="M9 5h9v9"/>',
43
+ diff: '<path d="M6 4v16M18 4v16M3 8h6M15 16h6M3 16h6M15 8h6"/>',
43
44
  };
44
45
 
45
46
  const TOOL_ICON = {
@@ -174,6 +175,9 @@ const state = {
174
175
  overlay: null,
175
176
  ccIndex: 0,
176
177
  ccItems: [],
178
+ workbench: { open: false, tab: 'terminal', width: 420 },
179
+ changes: null,
180
+ changesFile: null,
177
181
  };
178
182
 
179
183
  const THREAD = $('thread');
@@ -227,10 +231,12 @@ async function switchSession(ref) {
227
231
  const result = await post('session', { action: 'switch', ref });
228
232
  if (result?.info) state.info = result.info;
229
233
  if (result?.sessions) state.sessions = result.sessions;
234
+ state.changes = null;
230
235
  renderHeader();
231
236
  renderSidebar();
232
237
  renderThread();
233
238
  $('filesTitle').textContent = `项目文件 · ${state.info?.workspace ?? ''}`;
239
+ if (state.workbench.open && state.workbench.tab === 'changes') void loadChanges(true);
234
240
  closeSidebarIfOverlay();
235
241
  } catch (error) {
236
242
  toast('切换会话失败:' + (error?.message ?? error));
@@ -360,8 +366,17 @@ function downloadSession(format, id) {
360
366
  }
361
367
 
362
368
  function toolGroup(calls, results) {
363
- const wrap = document.createElement('div');
364
- wrap.className = 'tool-group';
369
+ const wrap = document.createElement('details');
370
+ wrap.className = 'work-group';
371
+ const hasError = calls.some((call) => results.get(call.id)?.isError);
372
+ wrap.open = hasError;
373
+ wrap.classList.toggle('has-error', hasError);
374
+ const summary = document.createElement('summary');
375
+ summary.innerHTML =
376
+ `<span class="wg-dot"></span><span class="wg-title">运行了 ${calls.length} 个工具</span>` +
377
+ `<span class="wg-state">${hasError ? '有失败' : ''}</span>`;
378
+ const body = document.createElement('div');
379
+ body.className = 'tool-group-body';
365
380
  for (const call of calls) {
366
381
  const result = results.get(call.id);
367
382
  const row = document.createElement('div');
@@ -372,8 +387,14 @@ function toolGroup(calls, results) {
372
387
  `<span class="t-name">${escapeHtml(call.name)}</span>` +
373
388
  `<span class="t-detail">${escapeHtml(detail)}</span>` +
374
389
  `<span class="t-state">${result ? (result.isError ? '失败' : escapeHtml(result.content?.slice(0, 40) ?? '完成')) : '已调用'}</span>`;
375
- wrap.appendChild(row);
390
+ if (result?.content) {
391
+ row.classList.add('is-clickable');
392
+ row.title = '点击展开输出';
393
+ row.addEventListener('click', () => toggleToolOutput(row, result.content, Boolean(result.isError)));
394
+ }
395
+ body.appendChild(row);
376
396
  }
397
+ wrap.append(summary, body);
377
398
  return wrap;
378
399
  }
379
400
 
@@ -551,8 +572,7 @@ function syncOverlayState() {
551
572
  !$('commandCenter').hidden ||
552
573
  !$('codeViewer').hidden ||
553
574
  !$('settingsSheet').hidden ||
554
- !$('filesPanel').hidden ||
555
- !$('terminalPanel').hidden ||
575
+ !$('workbench').hidden ||
556
576
  !$('approvalModal').hidden;
557
577
  document.body.classList.toggle('has-overlay', open);
558
578
  }
@@ -562,9 +582,8 @@ function closeTopOverlay() {
562
582
  if (!$('commandCenter').hidden) return closeCommandCenter();
563
583
  if (!$('codeViewer').hidden) return closeViewer();
564
584
  if (!$('settingsSheet').hidden) return closeSettings();
565
- if (!$('filesPanel').hidden) return closeFiles();
566
- if (!$('terminalPanel').hidden) return termClose();
567
585
  if (!$('approvalModal').hidden) return closeApproval(false);
586
+ if (!$('workbench').hidden) return closeWorkbench();
568
587
  return false;
569
588
  }
570
589
 
@@ -727,18 +746,57 @@ async function send() {
727
746
  const botMsg = document.createElement('article');
728
747
  botMsg.className = 'msg assistant enter';
729
748
  botMsg.innerHTML = '<div class="msg-role">Banana</div>';
730
- const toolWrap = document.createElement('div');
731
- toolWrap.className = 'tool-group';
732
- const reasoning = document.createElement('div');
733
- reasoning.className = 'reasoning';
749
+
750
+ // 工具调用:默认折叠成一行工作摘要,失败时自动展开
751
+ const work = document.createElement('details');
752
+ work.className = 'work-group';
753
+ work.hidden = true;
754
+ const workSummary = document.createElement('summary');
755
+ workSummary.innerHTML =
756
+ '<span class="wg-dot"></span><span class="wg-title">正在运行</span><span class="wg-state"></span>';
757
+ const workBody = document.createElement('div');
758
+ workBody.className = 'tool-group-body';
759
+ work.append(workSummary, workBody);
760
+
761
+ // 思考过程:流式展开,回答开始后自动折叠
762
+ const reasoning = document.createElement('details');
763
+ reasoning.className = 'think';
734
764
  reasoning.hidden = true;
765
+ reasoning.open = true;
766
+ const reasonSummary = document.createElement('summary');
767
+ reasonSummary.innerHTML = '<span class="think-title">思考中…</span>';
768
+ const reasonBody = document.createElement('div');
769
+ reasonBody.className = 'think-body';
770
+ reasoning.append(reasonSummary, reasonBody);
771
+
735
772
  const body = document.createElement('div');
736
773
  body.className = 'msg-body caret';
737
774
  const meta = document.createElement('div');
738
775
  meta.className = 'turn-meta';
739
- botMsg.append(toolWrap, reasoning, body, meta);
776
+ botMsg.append(work, reasoning, body, meta);
740
777
  THREAD.appendChild(botMsg);
741
778
 
779
+ let reasoningStarted = 0;
780
+ let toolStarted = 0;
781
+ let toolCount = 0;
782
+ let toolErrors = false;
783
+ const finishReasoning = () => {
784
+ if (reasoning.hidden || reasoning.dataset.done === '1') return;
785
+ reasoning.dataset.done = '1';
786
+ reasoning.open = false;
787
+ const seconds = reasoningStarted ? ((Date.now() - reasoningStarted) / 1000).toFixed(1) : '0';
788
+ reasonSummary.querySelector('.think-title').textContent = `思考 · ${seconds}s`;
789
+ };
790
+ const finishWork = () => {
791
+ if (work.hidden || work.dataset.done === '1') return;
792
+ work.dataset.done = '1';
793
+ const seconds = toolStarted ? ((Date.now() - toolStarted) / 1000).toFixed(1) : '0';
794
+ workSummary.querySelector('.wg-title').textContent = `运行了 ${toolCount} 个工具`;
795
+ workSummary.querySelector('.wg-state').textContent = `${seconds}s${toolErrors ? ' · 有失败' : ''}`;
796
+ work.classList.toggle('has-error', toolErrors);
797
+ if (!toolErrors) work.open = false;
798
+ };
799
+
742
800
  const images = state.attachments.map((item) => item.path);
743
801
  state.attachments = [];
744
802
  renderAttachments();
@@ -787,9 +845,25 @@ async function send() {
787
845
  for (const line of chunk.split('\n')) {
788
846
  if (!line.startsWith('data: ')) continue;
789
847
  const event = JSON.parse(line.slice(6));
790
- if (event.type === 'text') { buffer += event.chunk; schedule(); }
791
- else if (event.type === 'reasoning') { reasoning.hidden = false; reasoning.textContent += event.chunk; }
792
- else if (event.type === 'tool_start') {
848
+ if (event.type === 'text') {
849
+ finishReasoning();
850
+ buffer += event.chunk;
851
+ schedule();
852
+ } else if (event.type === 'reasoning') {
853
+ if (!reasoningStarted) {
854
+ reasoningStarted = Date.now();
855
+ reasoning.hidden = false;
856
+ reasoning.open = true;
857
+ }
858
+ reasoning.hidden = false;
859
+ reasonBody.appendChild(document.createTextNode(event.chunk));
860
+ } else if (event.type === 'tool_start') {
861
+ if (!toolStarted) toolStarted = Date.now();
862
+ toolCount += 1;
863
+ work.hidden = false;
864
+ work.open = true;
865
+ workSummary.querySelector('.wg-title').textContent = `正在运行 ${toolCount} 个工具`;
866
+ workSummary.querySelector('.wg-state').textContent = '';
793
867
  const row = document.createElement('div');
794
868
  row.className = 'tool-row';
795
869
  row.innerHTML =
@@ -797,14 +871,15 @@ async function send() {
797
871
  `<span class="t-name">${escapeHtml(event.name)}</span>` +
798
872
  `<span class="t-detail">${escapeHtml(event.detail)}</span>` +
799
873
  '<span class="t-state"><span class="spin"></span></span>';
800
- toolWrap.appendChild(row);
874
+ workBody.appendChild(row);
801
875
  scrollToEnd(false);
802
876
  } else if (event.type === 'tool_end') {
803
- const rows = toolWrap.querySelectorAll('.tool-row');
877
+ const rows = workBody.querySelectorAll('.tool-row');
804
878
  const row = rows[rows.length - 1];
805
879
  if (row) {
806
880
  row.querySelector('.t-state').innerHTML = event.ok ? svg('check') : svg('x');
807
881
  row.classList.toggle('is-error', !event.ok);
882
+ if (!event.ok) toolErrors = true;
808
883
  if (event.detail) {
809
884
  row.classList.add('is-clickable');
810
885
  row.title = '点击展开输出';
@@ -816,12 +891,16 @@ async function send() {
816
891
  await post('approve', { id: event.id, allowed });
817
892
  } else if (event.type === 'error') {
818
893
  // 服务端提前收尾(没配 key、请求出错等):给出能照做的下一步
894
+ finishReasoning();
895
+ finishWork();
819
896
  body.classList.remove('caret');
820
897
  body.innerHTML = markdown(`**${escapeHtml(event.message ?? '出错了')}**`);
821
898
  if (event.hint) metaLine('提示', event.hint);
822
899
  if (event.code === 'no_api_key') openSettings();
823
900
  streamEnded = true;
824
901
  } else if (event.type === 'done') {
902
+ finishReasoning();
903
+ finishWork();
825
904
  body.classList.remove('caret');
826
905
  streamEnded = true;
827
906
  if (event.error) body.innerHTML = markdown(`**请求失败** ${escapeHtml(event.error)}`);
@@ -840,14 +919,17 @@ async function send() {
840
919
  state.sessions = sessions;
841
920
  renderSidebar();
842
921
  renderHeader();
922
+ if (state.workbench.open && state.workbench.tab === 'changes') void loadChanges(true);
843
923
  }
844
924
  }
845
925
  }
846
926
  }
847
927
  // 流结束了却没收到 done/error:多半是被中断,别让界面一直转圈
848
928
  if (!streamEnded) {
929
+ finishReasoning();
930
+ finishWork();
849
931
  body.classList.remove('caret');
850
- if (body.textContent === '' && toolWrap.childElementCount === 0) {
932
+ if (body.textContent === '' && workBody.childElementCount === 0) {
851
933
  body.innerHTML = markdown('这一轮没有返回内容。可以重试,或点「停止」后换个说法。');
852
934
  }
853
935
  await refresh();
@@ -857,8 +939,11 @@ async function send() {
857
939
  body.innerHTML = markdown(`**中断** ${escapeHtml(error.message)}`);
858
940
  await refresh();
859
941
  } finally {
942
+ finishReasoning();
943
+ finishWork();
860
944
  setBusy(false);
861
945
  scrollToEnd();
946
+ if (state.workbench.open && state.workbench.tab === 'changes') void loadChanges(true);
862
947
  }
863
948
  }
864
949
 
@@ -1424,42 +1509,23 @@ function renderTerminalSettings(body) {
1424
1509
  });
1425
1510
  card.appendChild(settingsRow('默认 Shell', '新建终端标签时使用。', shellSelect));
1426
1511
 
1427
- card.appendChild(
1428
- settingsRow(
1429
- '停靠位置',
1430
- '底部会盖住输入框;也可以靠左、靠右或浮动。',
1431
- settingsSeg(
1432
- [
1433
- { value: 'bottom', label: '底部' },
1434
- { value: 'left', label: '左侧' },
1435
- { value: 'right', label: '右侧' },
1436
- { value: 'float', label: '浮动' },
1437
- ],
1438
- term.dock,
1439
- (value) => {
1440
- termApplyDock(value);
1441
- if (!term.open) termOpen();
1442
- setTimeout(() => termActiveTab()?.terminal.focus(), 220);
1443
- renderSettings();
1444
- },
1445
- ),
1446
- ),
1447
- );
1448
-
1449
- const openBtn = settingsButton(term.open ? '隐藏终端' : '打开终端', () => {
1512
+ const isTermOpen = state.workbench.open && state.workbench.tab === 'terminal';
1513
+ const openBtn = settingsButton(isTermOpen ? '收起终端' : '打开终端', () => {
1450
1514
  closeSettings();
1451
- if (term.open) termClose();
1515
+ if (isTermOpen) closeWorkbench();
1452
1516
  else termOpen();
1453
1517
  }, true);
1454
- card.appendChild(settingsRow('终端面板', '快捷键 Ctrl+`,Esc 也可以收起。', openBtn));
1518
+ card.appendChild(settingsRow('终端面板', '在右侧工作台打开,不会挡住输入框。快捷键 Ctrl+`。', openBtn));
1455
1519
  section.appendChild(card);
1456
1520
 
1457
1521
  const help = settingsSection('常用快捷键', '');
1458
1522
  const helpCard = settingsCard();
1459
1523
  for (const [keys, text] of [
1460
- ['Ctrl+`', '打开 / 收起终端'],
1524
+ ['Ctrl+`', '打开 / 收起终端工作台'],
1461
1525
  ['Ctrl+K', '全局命令中心'],
1462
- ['Esc', '关闭最上层面板'],
1526
+ ['Ctrl+Shift+F', '打开文件工作台'],
1527
+ ['Ctrl+Shift+G', '查看本会话改动'],
1528
+ ['Esc', '关闭最上层;在终端里留给 shell'],
1463
1529
  ['Enter / Shift+Enter', '发送 / 换行'],
1464
1530
  ['@', '引用项目文件'],
1465
1531
  ['/', '打开命令面板'],
@@ -1703,11 +1769,224 @@ function renderAboutSettings(body) {
1703
1769
  body.appendChild(section);
1704
1770
  }
1705
1771
 
1772
+ // ---------------- 右侧工作台 ----------------
1773
+ const WB_STORAGE = { width: 'banana.wb.width', tab: 'banana.wb.tab' };
1774
+ const WB_MIN = 340;
1775
+ const WB_DEFAULT = 420;
1776
+
1777
+ function wbApplyWidth(width) {
1778
+ const max = Math.max(WB_MIN, Math.min(820, window.innerWidth * 0.72));
1779
+ state.workbench.width = Math.max(WB_MIN, Math.min(Number(width) || WB_DEFAULT, max));
1780
+ $('workbench').style.setProperty('--wb-width', `${Math.round(state.workbench.width)}px`);
1781
+ }
1782
+
1783
+ function wbIsNarrow() {
1784
+ return window.matchMedia('(max-width: 980px)').matches;
1785
+ }
1786
+
1787
+ function openWorkbench(tab) {
1788
+ const wb = $('workbench');
1789
+ if (tab) state.workbench.tab = tab;
1790
+ wb.classList.remove('is-closing');
1791
+ wb.hidden = false;
1792
+ state.workbench.open = true;
1793
+ wbApplyWidth(state.workbench.width);
1794
+ // 强制读一次布局,保证从 0 宽开始过渡(不依赖可能被后台节流的 rAF)
1795
+ void wb.offsetWidth;
1796
+ wb.classList.add('open');
1797
+ setWorkbenchTab(state.workbench.tab);
1798
+ $('wbScrim').hidden = !wbIsNarrow();
1799
+ syncOverlayState();
1800
+ }
1801
+
1802
+ function closeWorkbench() {
1803
+ const wb = $('workbench');
1804
+ if (!state.workbench.open) return;
1805
+ state.workbench.open = false;
1806
+ wb.classList.remove('open');
1807
+ wb.classList.add('is-closing');
1808
+ $('wbScrim').hidden = true;
1809
+ setTimeout(() => {
1810
+ if (state.workbench.open) return;
1811
+ wb.hidden = true;
1812
+ wb.classList.remove('is-closing');
1813
+ syncOverlayState();
1814
+ $('input')?.focus();
1815
+ }, 280);
1816
+ }
1817
+
1818
+ function setWorkbenchTab(tab) {
1819
+ if (!['terminal', 'files', 'changes'].includes(tab)) tab = 'terminal';
1820
+ state.workbench.tab = tab;
1821
+ try {
1822
+ localStorage.setItem(WB_STORAGE.tab, tab);
1823
+ } catch {}
1824
+ $('wbTabs').querySelectorAll('.wb-tab').forEach((node) => {
1825
+ const on = node.dataset.tab === tab;
1826
+ node.classList.toggle('is-on', on);
1827
+ node.setAttribute('aria-selected', String(on));
1828
+ });
1829
+ $('workbench').querySelectorAll('.wb-pane').forEach((node) => {
1830
+ node.classList.toggle('active', node.dataset.pane === tab);
1831
+ });
1832
+ if (tab === 'terminal') {
1833
+ termEnsure();
1834
+ requestAnimationFrame(() => termFitActive());
1835
+ } else if (tab === 'files') {
1836
+ if (!$('filesTree').childElementCount) void loadTree('.');
1837
+ } else if (tab === 'changes') {
1838
+ void loadChanges(true);
1839
+ }
1840
+ }
1841
+
1842
+ function initWorkbench() {
1843
+ try {
1844
+ const savedWidth = Number(localStorage.getItem(WB_STORAGE.width));
1845
+ if (savedWidth) state.workbench.width = savedWidth;
1846
+ const savedTab = localStorage.getItem(WB_STORAGE.tab);
1847
+ if (savedTab) state.workbench.tab = savedTab;
1848
+ } catch {}
1849
+ wbApplyWidth(state.workbench.width);
1850
+ $('wbTabs').querySelectorAll('.wb-tab').forEach((node) => {
1851
+ node.addEventListener('click', () => setWorkbenchTab(node.dataset.tab));
1852
+ });
1853
+ $('wbClose').addEventListener('click', closeWorkbench);
1854
+ $('wbScrim').addEventListener('click', closeWorkbench);
1855
+ $('changesRefresh').addEventListener('click', () => loadChanges(true));
1856
+ $('wbResizer').addEventListener('pointerdown', (event) => {
1857
+ event.preventDefault();
1858
+ $('workbench').classList.add('is-resizing');
1859
+ const move = (moveEvent) => {
1860
+ wbApplyWidth(window.innerWidth - moveEvent.clientX);
1861
+ if (state.workbench.tab === 'terminal') termFitActive();
1862
+ };
1863
+ const up = () => {
1864
+ window.removeEventListener('pointermove', move);
1865
+ window.removeEventListener('pointerup', up);
1866
+ $('workbench').classList.remove('is-resizing');
1867
+ try {
1868
+ localStorage.setItem(WB_STORAGE.width, String(Math.round(state.workbench.width)));
1869
+ } catch {}
1870
+ if (state.workbench.tab === 'terminal') termFitActive();
1871
+ };
1872
+ window.addEventListener('pointermove', move);
1873
+ window.addEventListener('pointerup', up);
1874
+ });
1875
+ window.addEventListener('resize', () => {
1876
+ wbApplyWidth(state.workbench.width);
1877
+ $('wbScrim').hidden = !state.workbench.open || !wbIsNarrow();
1878
+ if (state.workbench.tab === 'terminal') termFitActive();
1879
+ });
1880
+ }
1881
+
1882
+ // ---------------- 变更(Diff) ----------------
1883
+ async function loadChanges(force = false) {
1884
+ if (!force && state.changes) {
1885
+ renderChanges();
1886
+ return;
1887
+ }
1888
+ const list = $('changesList');
1889
+ list.innerHTML = '<div class="hint" style="padding:12px">读取改动…</div>';
1890
+ try {
1891
+ const data = await get('changes');
1892
+ state.changes = data;
1893
+ renderChanges();
1894
+ } catch (error) {
1895
+ list.innerHTML = `<div class="hint" style="padding:12px">${escapeHtml(error.message)}</div>`;
1896
+ }
1897
+ }
1898
+
1899
+ function renderChanges() {
1900
+ const list = $('changesList');
1901
+ const detail = $('changesDetail');
1902
+ list.innerHTML = '';
1903
+ const turns = state.changes?.turns ?? [];
1904
+ if (!turns.length) {
1905
+ list.innerHTML = '<div class="hint" style="padding:12px">还没有文件改动。让 Banana 改一次文件后,这里会出现增删行。</div>';
1906
+ detail.innerHTML = '<div class="hint">没有可显示的改动。</div>';
1907
+ return;
1908
+ }
1909
+ let total = 0;
1910
+ for (const turn of turns) {
1911
+ const group = document.createElement('div');
1912
+ group.className = 'changes-group';
1913
+ const head = document.createElement('div');
1914
+ head.className = 'changes-turn';
1915
+ head.textContent = new Date(turn.at).toLocaleString();
1916
+ group.appendChild(head);
1917
+ for (const file of turn.files) {
1918
+ total += 1;
1919
+ const button = document.createElement('button');
1920
+ button.className = 'change-file';
1921
+ button.innerHTML =
1922
+ `<span class="cf-name">${escapeHtml(file.path)}</span>` +
1923
+ `<span class="cf-count"><i class="plus">+${file.additions}</i><i class="minus">-${file.deletions}</i></span>`;
1924
+ button.addEventListener('click', () => {
1925
+ list.querySelectorAll('.change-file.is-on').forEach((node) => node.classList.remove('is-on'));
1926
+ button.classList.add('is-on');
1927
+ renderDiff(file);
1928
+ });
1929
+ group.appendChild(button);
1930
+ }
1931
+ list.appendChild(group);
1932
+ }
1933
+ $('changesTitle').textContent = `本会话改动 · ${total} 个文件`;
1934
+ // 默认打开第一个有内容的文件
1935
+ const firstFile = turns.find((turn) => turn.files.length)?.files[0];
1936
+ if (firstFile) {
1937
+ const firstButton = list.querySelector('.change-file');
1938
+ firstButton?.classList.add('is-on');
1939
+ renderDiff(firstFile);
1940
+ } else {
1941
+ detail.innerHTML = '<div class="hint">没有可显示的改动。</div>';
1942
+ }
1943
+ }
1944
+
1945
+ function renderDiff(file) {
1946
+ const detail = $('changesDetail');
1947
+ detail.innerHTML = '';
1948
+ const head = document.createElement('div');
1949
+ head.className = 'diff-head';
1950
+ head.innerHTML =
1951
+ `<span class="diff-path">${escapeHtml(file.path)}</span>` +
1952
+ `<span class="diff-stat"><i class="plus">+${file.additions}</i><i class="minus">-${file.deletions}</i></span>` +
1953
+ (file.missing ? '<span class="plugin-badge">文件已不存在</span>' : '');
1954
+ detail.appendChild(head);
1955
+ const body = document.createElement('div');
1956
+ body.className = 'diff-body';
1957
+ const lines = file.lines ?? [];
1958
+ if (!lines.length) {
1959
+ body.innerHTML = '<div class="hint" style="padding:10px">没有行级差异(可能只是换行符变化)。</div>';
1960
+ } else {
1961
+ for (const line of lines) {
1962
+ const row = document.createElement('div');
1963
+ row.className = `diff-line ${line.type}`;
1964
+ const oldNo = line.oldLine ?? '';
1965
+ const newNo = line.newLine ?? '';
1966
+ row.innerHTML =
1967
+ `<span class="diff-no">${oldNo}</span><span class="diff-no">${newNo}</span>` +
1968
+ `<span class="diff-sign">${line.type === 'add' ? '+' : line.type === 'del' ? '-' : ' '}</span>` +
1969
+ `<span class="diff-text"></span>`;
1970
+ row.querySelector('.diff-text').textContent = line.text;
1971
+ body.appendChild(row);
1972
+ }
1973
+ }
1974
+ if (file.truncated) {
1975
+ const note = document.createElement('div');
1976
+ note.className = 'hint';
1977
+ note.style.padding = '8px 10px';
1978
+ note.textContent = '改动较大,只显示前面一部分。';
1979
+ body.appendChild(note);
1980
+ }
1981
+ detail.appendChild(body);
1982
+ detail.scrollTop = 0;
1983
+ }
1984
+
1706
1985
  // ---------------- 文件面板 ----------------
1707
1986
 
1708
1987
 
1709
1988
  const FILE_ICON = { dir: 'folder', file: 'file' };
1710
- const FILE_STORAGE = { width: 'banana.files.width', tree: 'banana.files.tree', wrap: 'banana.files.wrap' };
1989
+ const FILE_STORAGE = { tree: 'banana.files.tree', wrap: 'banana.files.wrap' };
1711
1990
 
1712
1991
  async function loadTree(path = '.', container = $('filesTree')) {
1713
1992
  container.innerHTML = '<div class="hint" style="padding:8px 10px">读取中…</div>';
@@ -1753,8 +2032,6 @@ async function loadTree(path = '.', container = $('filesTree')) {
1753
2032
 
1754
2033
  function applyFilesLayout() {
1755
2034
  const panel = $('filesPanel');
1756
- const width = Number(localStorage.getItem(FILE_STORAGE.width));
1757
- if (width) panel.style.setProperty('--files-width', `${Math.max(340, Math.min(width, window.innerWidth * 0.92))}px`);
1758
2035
  const tree = Number(localStorage.getItem(FILE_STORAGE.tree));
1759
2036
  if (tree) panel.style.setProperty('--tree-height', `${tree}px`);
1760
2037
  const wrap = localStorage.getItem(FILE_STORAGE.wrap) === '1';
@@ -1765,27 +2042,23 @@ function applyFilesLayout() {
1765
2042
  }
1766
2043
 
1767
2044
  function openFiles() {
1768
- const panel = $('filesPanel');
1769
- panel.classList.remove('is-closing');
1770
- panel.hidden = false;
1771
2045
  applyFilesLayout();
1772
- document.body.classList.add('has-overlay');
1773
2046
  $('filesTitle').textContent = `项目文件 · ${state.info?.workspace ?? ''}`;
1774
- if (!$('filesTree').childElementCount) void loadTree('.');
2047
+ openWorkbench('files');
2048
+ }
2049
+
2050
+ function openChanges() {
2051
+ openWorkbench('changes');
2052
+ void loadChanges(true);
1775
2053
  }
1776
2054
 
1777
2055
  function closeFiles() {
1778
- const panel = $('filesPanel');
1779
- if (panel.hidden) return;
1780
- void hideAnimated(panel, 'is-closing', 170).then(() => {
1781
- syncOverlayState();
1782
- $('input')?.focus();
1783
- });
2056
+ closeWorkbench();
1784
2057
  }
1785
2058
 
1786
2059
  function toggleFiles() {
1787
- if ($('filesPanel').hidden) openFiles();
1788
- else closeFiles();
2060
+ if (!$('workbench').hidden && state.workbench.tab === 'files') closeWorkbench();
2061
+ else openFiles();
1789
2062
  }
1790
2063
 
1791
2064
  function closePreview() {
@@ -1852,21 +2125,6 @@ function toggleWrap() {
1852
2125
 
1853
2126
  function initFileResize() {
1854
2127
  const panel = $('filesPanel');
1855
- $('filesGrip').addEventListener('pointerdown', (event) => {
1856
- event.preventDefault();
1857
- const move = (moveEvent) => {
1858
- const width = Math.max(320, Math.min(window.innerWidth - 80, window.innerWidth - moveEvent.clientX));
1859
- panel.style.setProperty('--files-width', `${width}px`);
1860
- };
1861
- const up = () => {
1862
- window.removeEventListener('pointermove', move);
1863
- window.removeEventListener('pointerup', up);
1864
- localStorage.setItem(FILE_STORAGE.width, String(Math.round(panel.getBoundingClientRect().width)));
1865
- };
1866
- window.addEventListener('pointermove', move);
1867
- window.addEventListener('pointerup', up);
1868
- });
1869
-
1870
2128
  $('filesDivider').addEventListener('pointerdown', (event) => {
1871
2129
  event.preventDefault();
1872
2130
  const split = $('filesSplit');
@@ -1905,17 +2163,12 @@ function toggleToolOutput(row, detail, isError) {
1905
2163
  // ---------------- 内嵌终端(xterm + PTY) ----------------
1906
2164
  const TERM_FONT = '"Cascadia Mono", "JetBrains Mono", "SF Mono", Consolas, "Microsoft YaHei", monospace';
1907
2165
  const TERM_STORAGE = {
1908
- dock: 'banana.term.dock',
1909
- size: 'banana.term.size',
1910
- pos: 'banana.term.pos',
1911
2166
  fontSize: 'banana.term.fontSize',
1912
2167
  shell: 'banana.term.shell',
1913
2168
  };
1914
2169
 
1915
2170
  const term = {
1916
2171
  open: false,
1917
- dock: localStorage.getItem(TERM_STORAGE.dock) || 'bottom',
1918
- size: Number(localStorage.getItem(TERM_STORAGE.size)) || 280,
1919
2172
  fontSize: Number(localStorage.getItem(TERM_STORAGE.fontSize)) || 13,
1920
2173
  shells: [],
1921
2174
  defaultShell: '',
@@ -1964,82 +2217,49 @@ function termActiveTab() {
1964
2217
  return term.tabs.find((tab) => tab.id === term.activeId) ?? null;
1965
2218
  }
1966
2219
 
1967
- function termUpdateCwd(cwd) {
1968
- const label = $('termCwd');
1969
- if (label && cwd) label.textContent = cwd;
1970
- }
1971
-
1972
- function termPersistSize() {
1973
- localStorage.setItem(TERM_STORAGE.size, String(Math.round(term.size)));
1974
- localStorage.setItem(TERM_STORAGE.dock, term.dock);
1975
- }
1976
-
1977
- function termApplyDock(dock, persist = true) {
1978
- term.dock = dock;
1979
- const panel = $('terminalPanel');
1980
- const main = $('main');
1981
- panel.dataset.dock = dock;
1982
- panel.style.removeProperty('left');
1983
- panel.style.removeProperty('top');
1984
- panel.style.removeProperty('right');
1985
- panel.style.removeProperty('bottom');
1986
- panel.style.width = '';
1987
- panel.style.height = '';
1988
- if (dock === 'bottom' || dock === 'top') {
1989
- const max = Math.max(180, main.clientHeight - 150);
1990
- term.size = Math.min(Math.max(180, term.size), max);
1991
- panel.style.height = `${term.size}px`;
1992
- } else if (dock === 'left' || dock === 'right') {
1993
- const max = Math.max(300, main.clientWidth - 320);
1994
- term.size = Math.min(Math.max(260, term.size), max);
1995
- panel.style.width = `${term.size}px`;
1996
- } else {
1997
- const width = Math.min(720, Math.max(380, Math.round(main.clientWidth * 0.64)));
1998
- const height = Math.min(460, Math.max(240, Math.round(main.clientHeight * 0.56)));
1999
- panel.style.width = `${width}px`;
2000
- panel.style.height = `${height}px`;
2001
- const saved = termReadPos() ?? { x: Math.max(24, main.clientWidth - width - 40), y: Math.max(20, main.clientHeight - height - 40) };
2002
- const left = Math.max(8, Math.min(saved.x, main.clientWidth - width - 8));
2003
- const top = Math.max(8, Math.min(saved.y, main.clientHeight - height - 8));
2004
- panel.style.left = `${left}px`;
2005
- panel.style.top = `${top}px`;
2006
- }
2007
- if (persist) termPersistSize();
2008
- requestAnimationFrame(() => {
2009
- termActiveTab()?.fit.fit();
2010
- });
2011
- }
2012
-
2013
- function termReadPos() {
2220
+ function termFitActive() {
2221
+ if ($('workbench').hidden || state.workbench.tab !== 'terminal') return;
2222
+ const tab = termActiveTab();
2223
+ if (!tab) return;
2014
2224
  try {
2015
- const raw = JSON.parse(localStorage.getItem(TERM_STORAGE.pos) || 'null');
2016
- return raw && Number.isFinite(raw.x) && Number.isFinite(raw.y) ? raw : null;
2225
+ tab.fit.fit();
2226
+ tab.sendResize();
2017
2227
  } catch {
2018
- return null;
2228
+ /* 面板还没布局完成 */
2019
2229
  }
2020
2230
  }
2021
2231
 
2232
+ function termUpdateCwd(cwd) {
2233
+ const label = $('termCwd');
2234
+ if (label && cwd) label.textContent = cwd;
2235
+ }
2236
+
2237
+ let termShellsPromise = null;
2022
2238
  async function termLoadShells() {
2023
- if (term.loadedShells) return;
2239
+ if (termShellsPromise) return termShellsPromise;
2024
2240
  term.loadedShells = true;
2025
- try {
2026
- const data = await get('shells');
2027
- term.shells = Array.isArray(data.shells) ? data.shells : [];
2028
- term.defaultShell = data.default || term.shells[0]?.id || 'cmd';
2029
- const select = $('termShell');
2030
- const preferred = localStorage.getItem(TERM_STORAGE.shell);
2031
- select.innerHTML = term.shells
2032
- .map((shell) => `<option value="${escapeHtml(shell.id)}">${escapeHtml(shell.name)}</option>`)
2033
- .join('');
2034
- select.value = term.shells.some((shell) => shell.id === preferred) ? preferred : term.defaultShell;
2035
- select.addEventListener('change', () => {
2036
- localStorage.setItem(TERM_STORAGE.shell, select.value);
2037
- termCreateTab(select.value);
2038
- });
2039
- } catch (error) {
2040
- term.shells = [{ id: 'cmd', name: '终端' }];
2041
- term.defaultShell = 'cmd';
2042
- }
2241
+ termShellsPromise = (async () => {
2242
+ try {
2243
+ const data = await get('shells');
2244
+ term.shells = Array.isArray(data.shells) ? data.shells : [];
2245
+ term.defaultShell = data.default || term.shells[0]?.id || 'cmd';
2246
+ const select = $('termShell');
2247
+ const preferred = localStorage.getItem(TERM_STORAGE.shell);
2248
+ select.innerHTML = term.shells
2249
+ .map((shell) => `<option value="${escapeHtml(shell.id)}">${escapeHtml(shell.name)}</option>`)
2250
+ .join('');
2251
+ select.value = term.shells.some((shell) => shell.id === preferred) ? preferred : term.defaultShell;
2252
+ select.addEventListener('change', () => {
2253
+ localStorage.setItem(TERM_STORAGE.shell, select.value);
2254
+ closeTermMenu();
2255
+ termCreateTab(select.value);
2256
+ });
2257
+ } catch {
2258
+ term.shells = [{ id: 'cmd', name: '终端' }];
2259
+ term.defaultShell = 'cmd';
2260
+ }
2261
+ })();
2262
+ return termShellsPromise;
2043
2263
  }
2044
2264
 
2045
2265
  function termRenderTabs() {
@@ -2127,10 +2347,10 @@ function termConnect(tab) {
2127
2347
  }
2128
2348
  });
2129
2349
  ws.addEventListener('close', () => {
2130
- if (!tab.alive || !term.open) return;
2350
+ if (!tab.alive) return;
2131
2351
  // 服务重启或网络抖动时自动重连;服务端会按 tab.termId 把会话接回来
2132
2352
  setTimeout(() => {
2133
- if (tab.alive && term.open && (!tab.ws || tab.ws.readyState > 1)) termConnect(tab);
2353
+ if (tab.alive && (!tab.ws || tab.ws.readyState > 1)) termConnect(tab);
2134
2354
  }, 900);
2135
2355
  });
2136
2356
 
@@ -2140,11 +2360,12 @@ function termConnect(tab) {
2140
2360
  }
2141
2361
 
2142
2362
  function termCreateTab(shellId) {
2143
- if (!term.open) {
2144
- termOpen();
2145
- return null;
2363
+ if (!term.shells.length) {
2364
+ void termLoadShells().then(() => {
2365
+ if (term.shells.length) termCreateTab(shellId);
2366
+ });
2367
+ return;
2146
2368
  }
2147
- termLoadShells();
2148
2369
  const shell = term.shells.find((item) => item.id === shellId) ?? term.shells[0];
2149
2370
  const name = shell?.name ?? '终端';
2150
2371
  const pane = document.createElement('div');
@@ -2156,7 +2377,7 @@ function termCreateTab(shellId) {
2156
2377
  cursorStyle: 'bar',
2157
2378
  fontFamily: TERM_FONT,
2158
2379
  fontSize: term.fontSize,
2159
- lineHeight: 1.25,
2380
+ lineHeight: 1.45,
2160
2381
  letterSpacing: 0,
2161
2382
  scrollback: 8000,
2162
2383
  allowTransparency: true,
@@ -2190,14 +2411,8 @@ function termCreateTab(shellId) {
2190
2411
  termActivate(tab.id);
2191
2412
  // 先连 WebSocket(不依赖页面可见性),再等布局完成 fit
2192
2413
  termConnect(tab);
2193
- requestAnimationFrame(() => {
2194
- try {
2195
- fit.fit();
2196
- tab.sendResize();
2197
- } catch {
2198
- /* 忽略 */
2199
- }
2200
- });
2414
+ requestAnimationFrame(() => termFitActive());
2415
+ setTimeout(() => termFitActive(), 320);
2201
2416
  return tab;
2202
2417
  }
2203
2418
 
@@ -2231,44 +2446,38 @@ function termCloseTab(id) {
2231
2446
  }
2232
2447
  }
2233
2448
 
2234
- function termOpen() {
2235
- const panel = $('terminalPanel');
2236
- termApplyDock(term.dock, false);
2237
- if (!term.open) {
2238
- term.open = true;
2239
- panel.hidden = false;
2240
- document.body.classList.add('has-overlay');
2241
- requestAnimationFrame(() => panel.classList.add('show'));
2449
+ function termEnsure() {
2450
+ if (term.tabs.length) {
2451
+ termActivate(term.activeId);
2452
+ return;
2242
2453
  }
2243
- const ensure = () => {
2244
- if (term.tabs.length === 0) termCreateTab($('termShell')?.value || term.defaultShell);
2245
- else termActivate(term.activeId);
2246
- setTimeout(() => termActiveTab()?.terminal.focus(), 180);
2454
+ const create = () => {
2455
+ if (term.tabs.length) {
2456
+ termActivate(term.activeId);
2457
+ return;
2458
+ }
2459
+ termCreateTab($('termShell')?.value || term.defaultShell);
2247
2460
  };
2248
- if (term.loadedShells) ensure();
2249
- else termLoadShells().then(ensure);
2461
+ if (term.shells.length) create();
2462
+ else void termLoadShells().then(create);
2463
+ }
2464
+
2465
+ function termOpen() {
2466
+ openWorkbench('terminal');
2250
2467
  termUpdateCwd(state.info?.workspace ?? '');
2251
- syncOverlayState();
2468
+ setTimeout(() => {
2469
+ termFitActive();
2470
+ termActiveTab()?.terminal.focus();
2471
+ }, 320);
2252
2472
  }
2253
2473
 
2254
2474
  function termClose() {
2255
- if (!term.open) return;
2256
- term.open = false;
2257
- const panel = $('terminalPanel');
2258
- panel.classList.remove('show');
2259
- panel.classList.add('closing');
2260
- setTimeout(() => {
2261
- if (term.open) return;
2262
- panel.hidden = true;
2263
- panel.classList.remove('closing');
2264
- syncOverlayState();
2265
- $('input')?.focus();
2266
- }, 180);
2475
+ closeWorkbench();
2267
2476
  }
2268
2477
 
2269
2478
  function termToggle() {
2270
- if (term.open) termClose();
2271
- else termOpen();
2479
+ if (!state.workbench.open || state.workbench.tab !== 'terminal') termOpen();
2480
+ else closeWorkbench();
2272
2481
  }
2273
2482
 
2274
2483
  function termRestyle() {
@@ -2276,87 +2485,39 @@ function termRestyle() {
2276
2485
  for (const tab of term.tabs) {
2277
2486
  tab.terminal.options.theme = theme;
2278
2487
  tab.terminal.options.fontSize = term.fontSize;
2279
- requestAnimationFrame(() => {
2280
- try {
2281
- tab.fit.fit();
2282
- } catch {
2283
- /* 忽略 */
2284
- }
2285
- });
2286
2488
  }
2489
+ termFitActive();
2287
2490
  }
2288
2491
 
2289
2492
  function bindTerminal() {
2290
2493
  $('termBtn').innerHTML = svg('terminal');
2291
2494
  $('termAdd').innerHTML = svg('plus');
2292
- $('termClear').innerHTML = svg('trash');
2293
- $('termClose').innerHTML = svg('x');
2294
- $('termDock').innerHTML = svg('panel');
2295
- $('termAnalyze').innerHTML = svg('search');
2495
+ $('termMore').innerHTML = svg('dots');
2296
2496
  $('termBtn').addEventListener('click', termToggle);
2297
- $('termClose').addEventListener('click', termClose);
2298
- $('termAnalyze').addEventListener('click', analyzeTerminal);
2299
2497
  $('termAdd').addEventListener('click', () => {
2498
+ closeTermMenu();
2300
2499
  termCreateTab($('termShell')?.value || term.defaultShell);
2301
2500
  });
2302
- $('termClear').addEventListener('click', () => termActiveTab()?.terminal.clear());
2303
- $('termDock').addEventListener('click', () => {
2304
- const order = ['bottom', 'right', 'left', 'float'];
2305
- const next = order[(order.indexOf(term.dock) + 1) % order.length];
2306
- termApplyDock(next);
2307
- toast(`终端停靠在${next === 'bottom' ? '底部' : next === 'top' ? '顶部' : next === 'right' ? '右侧' : next === 'left' ? '左侧' : '浮动'}`);
2501
+ $('termMore').addEventListener('click', (event) => {
2502
+ event.stopPropagation();
2503
+ $('termMenu').hidden = !$('termMenu').hidden;
2308
2504
  });
2309
-
2310
- // 拖动边缘调整大小(浮动态拖标题栏移动位置)
2311
- const grip = $('termGrip');
2312
- grip.addEventListener('pointerdown', (event) => {
2313
- event.preventDefault();
2314
- const main = $('main');
2315
- const rect = main.getBoundingClientRect();
2316
- const move = (moveEvent) => {
2317
- let size;
2318
- if (term.dock === 'bottom') size = rect.bottom - moveEvent.clientY;
2319
- else if (term.dock === 'top') size = moveEvent.clientY - rect.top;
2320
- else if (term.dock === 'right') size = rect.right - moveEvent.clientX;
2321
- else size = moveEvent.clientX - rect.left;
2322
- term.size = Math.min(Math.max(160, size), (term.dock === 'left' || term.dock === 'right' ? rect.width : rect.height) - 160);
2323
- if (term.dock === 'bottom' || term.dock === 'top') $('terminalPanel').style.height = `${term.size}px`;
2324
- else $('terminalPanel').style.width = `${term.size}px`;
2325
- termActiveTab()?.fit.fit();
2326
- };
2327
- const up = () => {
2328
- window.removeEventListener('pointermove', move);
2329
- window.removeEventListener('pointerup', up);
2330
- termPersistSize();
2331
- };
2332
- window.addEventListener('pointermove', move);
2333
- window.addEventListener('pointerup', up);
2505
+ $('termAnalyze').addEventListener('click', () => {
2506
+ closeTermMenu();
2507
+ analyzeTerminal();
2334
2508
  });
2335
-
2336
- const panel = $('terminalPanel');
2337
- panel.addEventListener('pointerdown', (event) => {
2338
- if (term.dock !== 'float') return;
2339
- if (event.target.closest('button, select, .term-tab, .term-grip')) return;
2340
- const main = $('main');
2341
- const rect = main.getBoundingClientRect();
2342
- const panelRect = panel.getBoundingClientRect();
2343
- const offsetX = event.clientX - panelRect.left;
2344
- const offsetY = event.clientY - panelRect.top;
2345
- const move = (moveEvent) => {
2346
- const x = Math.min(Math.max(0, moveEvent.clientX - rect.left - offsetX), rect.width - 240);
2347
- const y = Math.min(Math.max(0, moveEvent.clientY - rect.top - offsetY), rect.height - 80);
2348
- panel.style.left = `${x}px`;
2349
- panel.style.top = `${y}px`;
2350
- };
2351
- const up = () => {
2352
- window.removeEventListener('pointermove', move);
2353
- window.removeEventListener('pointerup', up);
2354
- const x = parseFloat(panel.style.left) || 0;
2355
- const y = parseFloat(panel.style.top) || 0;
2356
- localStorage.setItem(TERM_STORAGE.pos, JSON.stringify({ x, y }));
2357
- };
2358
- window.addEventListener('pointermove', move);
2359
- window.addEventListener('pointerup', up);
2509
+ $('termClear').addEventListener('click', () => {
2510
+ closeTermMenu();
2511
+ termActiveTab()?.terminal.clear();
2512
+ });
2513
+ $('termCopy').addEventListener('click', () => {
2514
+ closeTermMenu();
2515
+ const text = termActiveTab()?.terminal.getSelection?.() ?? '';
2516
+ if (text) copyText(text);
2517
+ else toast('先在终端里选中文字');
2518
+ });
2519
+ document.addEventListener('click', (event) => {
2520
+ if (!$('termMenu').hidden && !event.target.closest('#termMenu, #termMore')) closeTermMenu();
2360
2521
  });
2361
2522
 
2362
2523
  window.addEventListener('keydown', (event) => {
@@ -2366,10 +2527,8 @@ function bindTerminal() {
2366
2527
  }
2367
2528
  });
2368
2529
 
2369
- const observer = new ResizeObserver(() => {
2370
- if (term.open) termActiveTab()?.fit.fit();
2371
- });
2372
- observer.observe($('main'));
2530
+ const observer = new ResizeObserver(() => termFitActive());
2531
+ observer.observe($('workbench'));
2373
2532
 
2374
2533
  document.addEventListener('banana:theme', () => {
2375
2534
  if (term.tabs.length) termRestyle();
@@ -2377,6 +2536,11 @@ function bindTerminal() {
2377
2536
  termUpdateCwd(state.info?.workspace ?? '');
2378
2537
  }
2379
2538
 
2539
+ function closeTermMenu() {
2540
+ const menu = $('termMenu');
2541
+ if (menu) menu.hidden = true;
2542
+ }
2543
+
2380
2544
  // ---------------- 命令中心(Ctrl+K) ----------------
2381
2545
  const CC_GROUPS = ['会话', '动作', '设置', '命令', '文件'];
2382
2546
 
@@ -2384,7 +2548,8 @@ function ccActions() {
2384
2548
  return [
2385
2549
  { title: '新建对话', sub: '开始一个干净的会话', icon: 'plus', run: () => $('newChat').click() },
2386
2550
  { title: '打开项目文件', sub: '浏览、全屏查看、引用文件', icon: 'panel', run: openFiles },
2387
- { title: '打开终端', sub: 'Ctrl+` 随时开关,底部覆盖不挤压对话', icon: 'terminal', run: termOpen },
2551
+ { title: '查看本会话改动', sub: '按文件查看增删行,审阅 agent 的修改', icon: 'diff', run: openChanges },
2552
+ { title: '打开终端', sub: '右侧工作台,不遮挡输入框', icon: 'terminal', run: termOpen },
2388
2553
  { title: '打开控制中心', sub: '模型、外观、终端、工作区、插件', icon: 'sliders', run: () => openSettings() },
2389
2554
  { title: '插件工坊', sub: '启用、停用、生成模板、试运行插件', icon: 'plug', run: () => openSettings('plugins') },
2390
2555
  { title: '切换主题', sub: '浅色 / 深色 / 跟随系统', icon: 'sun', run: cycleTheme },
@@ -2701,8 +2866,11 @@ function bind() {
2701
2866
  $('toggleSidebar').innerHTML = svg('list');
2702
2867
  $('closeSettings').innerHTML = svg('x');
2703
2868
  $('filesBtn').innerHTML = svg('panel');
2704
- $('closeFiles').innerHTML = svg('x');
2869
+ $('changesBtn').innerHTML = svg('diff');
2870
+ $('wbClose').innerHTML = svg('x');
2705
2871
  $('pluginsBtn').innerHTML = svg('plug');
2872
+ initWorkbench();
2873
+ initFileResize();
2706
2874
  bindTerminal();
2707
2875
  initTooltips();
2708
2876
  initSelectionTools();
@@ -2716,6 +2884,7 @@ function bind() {
2716
2884
  const result = await post('session', { action: 'new' });
2717
2885
  if (result?.info) state.info = result.info;
2718
2886
  if (result?.sessions) state.sessions = result.sessions;
2887
+ state.changes = null;
2719
2888
  renderHeader();
2720
2889
  renderSidebar();
2721
2890
  renderThread();
@@ -2736,8 +2905,8 @@ function bind() {
2736
2905
  });
2737
2906
  $('toggleSidebar').addEventListener('click', () => $('sidebar').classList.toggle('open'));
2738
2907
  $('filesBtn').addEventListener('click', toggleFiles);
2908
+ $('changesBtn').addEventListener('click', openChanges);
2739
2909
  $('themeBtn').addEventListener('click', cycleTheme);
2740
- $('closeFiles').addEventListener('click', closeFiles);
2741
2910
  $('pluginsBtn').addEventListener('click', () => openSettings('plugins'));
2742
2911
  $('previewWrap').addEventListener('click', toggleWrap);
2743
2912
  $('viewerWrap').addEventListener('click', toggleWrap);
@@ -2766,6 +2935,8 @@ function bind() {
2766
2935
  $('undoBtn').addEventListener('click', async () => {
2767
2936
  const result = await post('undo');
2768
2937
  toast(result.had ? `已回滚:恢复 ${result.restored} 个文件` : '没有可回滚的改动');
2938
+ state.changes = null;
2939
+ if (state.workbench.open && state.workbench.tab === 'changes') void loadChanges(true);
2769
2940
  });
2770
2941
 
2771
2942
  $('composer').addEventListener('submit', (event) => { event.preventDefault(); send(); });
@@ -2824,8 +2995,16 @@ function bind() {
2824
2995
  else closeCommandCenter();
2825
2996
  return;
2826
2997
  }
2998
+ if ((event.ctrlKey || event.metaKey) && event.shiftKey) {
2999
+ const key = String(event.key).toLowerCase();
3000
+ if (key === 'f') { event.preventDefault(); openFiles(); return; }
3001
+ if (key === 'g') { event.preventDefault(); openChanges(); return; }
3002
+ }
2827
3003
  if (event.key === 'Escape') {
2828
3004
  if (!$('commandPalette').hidden) { closePalette(); return; }
3005
+ // 终端里的 Esc 属于 shell,不要把工作台一起关掉
3006
+ const inTerminal = event.target instanceof Element && event.target.closest('#terminalPanel');
3007
+ if (inTerminal && $('settingsSheet').hidden && $('codeViewer').hidden && $('commandCenter').hidden && $('approvalModal').hidden) return;
2829
3008
  if (closeTopOverlay()) return;
2830
3009
  if ($('sidebar').classList.contains('open')) $('sidebar').classList.remove('open');
2831
3010
  }