JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
Fix: btw overlay scrolling
chensheng12345e9babd6e4c7e
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.tsindex 92e313284e..25a3e9df37 100644--- a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts+++ b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts@@ -1179,6 +1179,8 @@ export class AppScreen implements Component, Focusable {private pendingSubmittedBaseline = 0;private pendingSubmittedSessionId: string | null = null;private transcriptScrollOffset = 0;+ private btwOverlayScrollOffset = 0;+ private lastBtwOverlayKey: string | null = null;private lastTranscriptLineCount = 0;private lastTranscriptLineWidth = 0;/** Image attachments keyed by composer `@path` tokens (e.g. cached base64 for terminal preview). */@@ -1915,6 +1917,15 @@ export class AppScreen implements Component, Focusable {this.configEditorState !== null ||this.diffViewerState !== null;+ if (+ !pendingQuestion &&+ !hasOverlay &&+ snapshot.btwOverlay &&+ this.handleBtwOverlayScrollInput(data)+ ) {+ return;+ }+if (!pendingQuestion && !hasOverlay && this.handleTranscriptScrollInput(data)) {return;}@@ -1927,6 +1938,7 @@ export class AppScreen implements Component, Focusable {// 关闭 BTW overlay(如果可见)if (snapshot.btwOverlay) {this.state.clearBtwOverlay();+ this.btwOverlayScrollOffset = 0;}// 取消正在进行的 BTW WS 请求(加载中状态),不影响主会话this.state.requestLocalInterrupt();@@ -1963,6 +1975,7 @@ export class AppScreen implements Component, Focusable {if (!pendingQuestion && !hasOverlay && !snapshot.cancellableWork && isCancelWorkKey) {if (snapshot.btwOverlay) {this.state.clearBtwOverlay();+ this.btwOverlayScrollOffset = 0;this.tui.requestRender();return;}@@ -2491,6 +2504,13 @@ export class AppScreen implements Component, Focusable {}this.lastTranscriptLineCount = transcriptLineCount;this.lastTranscriptLineWidth = width;+ const btwOverlayKey = snapshot.btwOverlay+ ? `${snapshot.btwOverlay.question}\0${snapshot.btwOverlay.answer}`+ : null;+ if (btwOverlayKey !== this.lastBtwOverlayKey) {+ this.btwOverlayScrollOffset = 0;+ this.lastBtwOverlayKey = btwOverlayKey;+ }const screenLines = buildAppScreenLines(snapshot, {width,height: this.tui.terminal.rows,@@ -2512,6 +2532,10 @@ export class AppScreen implements Component, Focusable {onTranscriptScrollOffsetChange: (offset) => {this.transcriptScrollOffset = offset;},+ btwOverlayScrollOffset: this.btwOverlayScrollOffset,+ onBtwOverlayScrollOffsetChange: (offset) => {+ this.btwOverlayScrollOffset = offset;+ },runningElapsedMs:!snapshot.isInterrupted &&(snapshot.isProcessing ||@@ -2976,6 +3000,49 @@ export class AppScreen implements Component, Focusable {}}+ private handleBtwOverlayScrollInput(data: string): boolean {+ const wheelOffset = getSgrMouseWheelOffset(data, this.btwOverlayScrollOffset);+ if (wheelOffset !== null) {+ this.btwOverlayScrollOffset = wheelOffset;+ this.tui.requestRender();+ return true;+ }++ const pageSize = Math.max(1, Math.floor(this.tui.terminal.rows * 0.8));+ if (matchesKey(data, "up")) {+ this.btwOverlayScrollOffset = Math.max(0, this.btwOverlayScrollOffset - 1);+ this.tui.requestRender();+ return true;+ }+ if (matchesKey(data, "down")) {+ this.btwOverlayScrollOffset += 1;+ this.tui.requestRender();+ return true;+ }++ const scrollAction = resolveAction("Scroll", data);+ switch (scrollAction) {+ case "scroll:pageUp":+ this.btwOverlayScrollOffset = Math.max(0, this.btwOverlayScrollOffset - pageSize);+ this.tui.requestRender();+ return true;+ case "scroll:pageDown":+ this.btwOverlayScrollOffset += pageSize;+ this.tui.requestRender();+ return true;+ case "scroll:top":+ this.btwOverlayScrollOffset = 0;+ this.tui.requestRender();+ return true;+ case "scroll:bottom":+ this.btwOverlayScrollOffset = Number.MAX_SAFE_INTEGER;+ this.tui.requestRender();+ return true;+ default:+ return false;+ }+ }+private clearPendingSubmittedInput(requestRender = true): void {this.pendingSubmittedInput = null;this.pendingSubmittedBaseline = 0;diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/screen-layout.ts b/jiuwenswarm/channels/tui/frontend/src/ui/screen-layout.tsindex e150f998f6..2b99d3c831 100644--- a/jiuwenswarm/channels/tui/frontend/src/ui/screen-layout.ts+++ b/jiuwenswarm/channels/tui/frontend/src/ui/screen-layout.ts@@ -5,7 +5,7 @@ import { isTeamWorking } from "./components/team-shared.js";import { renderTeamStatusPill } from "./components/team-status-pill.js";import { renderTodoList } from "./components/todo-list.js";import { APP_SCREEN_KEY_BINDINGS } from "./keymap.js";-import { padToWidth } from "./rendering/text.js";+import { padToWidth, renderWrappedText } from "./rendering/text.js";import { palette } from "./theme.js";import { buildTranscriptLines } from "./transcript-renderer.js";import { loadTuiConfig } from "../core/tui-config-store.js";@@ -30,6 +30,8 @@ export interface ScreenLayoutOptions {runningElapsedMs?: number;transcriptScrollOffset?: number;onTranscriptScrollOffsetChange?: (offset: number) => void;+ btwOverlayScrollOffset?: number;+ onBtwOverlayScrollOffsetChange?: (offset: number) => void;}function formatSubtaskStatus(status: string): string {@@ -211,9 +213,14 @@ function buildStatusLineBar(snapshot: AppSnapshot, width: number): string[] {function renderBtwOverlay(overlay: { question: string; answer: string },width: number,-): string[] {+ maxHeight: number,+ scrollOffset: number,+): { lines: string[]; offset: number } {const lines: string[] = [];const safeWidth = Math.max(1, width);+ const availableHeight = Math.max(0, Math.floor(maxHeight));+ if (availableHeight <= 0) return { lines: [], offset: 0 };+ const footerHeight = 2;// 确保与其他固定区块有视觉分隔lines.push(" ".repeat(safeWidth));@@ -225,16 +232,38 @@ function renderBtwOverlay(lines.push(padToWidth(palette.text.dim("─".repeat(Math.min(safeWidth, 80))), safeWidth));// 回答内容:完整展示,不折叠(btw 本身是单轮简短回答,不会过长)- const answerLines = overlay.answer.split("\n");- for (const line of answerLines) {- lines.push(padToWidth(palette.text.secondary(line), safeWidth));+ const bodyHeight = Math.max(0, availableHeight - lines.length - footerHeight);+ if (bodyHeight <= 0) {+ return {+ lines: [+ padToWidth(palette.text.accent(headerText), safeWidth),+ padToWidth(palette.text.dim("Esc to dismiss"), safeWidth),+ ].slice(-availableHeight),+ offset: 0,+ };+ }++ const answerLines = overlay.answer+ .split("\n")+ .flatMap((line) => renderWrappedText(safeWidth, line, palette.text.secondary));+ const maxOffset = Math.max(0, answerLines.length - bodyHeight);+ const offset = Math.min(maxOffset, Math.max(0, Math.floor(scrollOffset)));+ const visibleAnswerLines = answerLines.slice(offset, offset + bodyHeight);+ for (const line of visibleAnswerLines) {+ lines.push(line);}+ const rangeStart = answerLines.length === 0 ? 0 : offset + 1;+ const rangeEnd = Math.min(offset + visibleAnswerLines.length, answerLines.length);+ const scrollHint =+ answerLines.length > bodyHeight+ ? `Esc to dismiss | ↑/↓ scroll | PgUp/PgDn page | ${rangeStart}-${rangeEnd}/${answerLines.length}`+ : "Esc to dismiss";// 提示行: Esc to dismiss- lines.push(padToWidth(palette.text.dim("Esc to dismiss"), safeWidth));+ lines.push(padToWidth(palette.text.dim(scrollHint), safeWidth));lines.push(" ".repeat(safeWidth));- return lines;+ return { lines, offset };}function buildShortcutLines(width: number): string[] {@@ -315,10 +344,7 @@ export function buildAppScreenLines(snapshot: AppSnapshot, options: ScreenLayoutoptions.width,): [];- const btwOverlayLines =- snapshot.btwOverlay ? renderBtwOverlay(snapshot.btwOverlay, options.width) : [];-- const fixedLines = [+ const fixedLinesBeforeBtw = [...todoLines,...(todoLines.length > 0 &&(teamStatusLines.length > 0 || miniTeamTreeLines.length > 0 || teamPanelLines.length > 0)@@ -328,7 +354,8 @@ export function buildAppScreenLines(snapshot: AppSnapshot, options: ScreenLayout...miniTeamTreeLines,...teamPanelLines,...options.questionLines,- ...btwOverlayLines,+ ];+ const fixedLinesAfterBtw = [...options.editorLines,...options.composerPreviewLines,...statusLineBarLines,@@ -336,6 +363,24 @@ export function buildAppScreenLines(snapshot: AppSnapshot, options: ScreenLayout...shortcutLines,];const height = Math.floor(options.height ?? 0);+ const btwMaxHeight =+ height > 0+ ? Math.max(0, height - fixedLinesBeforeBtw.length - fixedLinesAfterBtw.length)+ : Number.MAX_SAFE_INTEGER;+ const requestedBtwOverlayScrollOffset = options.btwOverlayScrollOffset ?? 0;+ const renderedBtwOverlay = snapshot.btwOverlay+ ? renderBtwOverlay(+ snapshot.btwOverlay,+ options.width,+ btwMaxHeight,+ requestedBtwOverlayScrollOffset,+ )+ : { lines: [], offset: 0 };+ if (renderedBtwOverlay.offset !== requestedBtwOverlayScrollOffset) {+ options.onBtwOverlayScrollOffsetChange?.(renderedBtwOverlay.offset);+ }+ const btwOverlayLines = renderedBtwOverlay.lines;+ const fixedLines = [...fixedLinesBeforeBtw, ...btwOverlayLines, ...fixedLinesAfterBtw];if (height <= 0) {return [...transcriptLines, ...fixedLines];}