Merge branch 'master' into fix/session-waiting-approval
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
// DiffBlock: the inline-diff surface for a file mutation (write/edit) — a copy
|
||||
// control over one or more per-file hunks, each a bold path header followed by
|
||||
// the removed block (`-`, error color) and the added block (`+`, success
|
||||
// color), with a dim `└ +A -R · N file(s)` footer. The +/- block form mirrors
|
||||
// the TUI transcript's diff card (packages/ui/tui: diffLines) so a diff reads
|
||||
// the same across front ends: the removed side is the old text in full, the
|
||||
// added side the new text in full, both split on the same terminator rule, and
|
||||
// the footer counts distinct paths on both ends. Output never soft-wraps — an
|
||||
// aligned source line keeps its indentation and scrolls horizontally instead of
|
||||
// folding. Colors resolve through --dsw-* tokens; geometry mirrors CodeBlock.
|
||||
// color), with a dim `└ +A -R · N file(s)` footer. Unlike the TUI's exact
|
||||
// changed-row comparison, this block renders the old and new sides in full.
|
||||
// Both front ends share the line-terminator rule and distinct-path file count.
|
||||
// Output never soft-wraps — an aligned source line keeps its indentation and
|
||||
// scrolls horizontally instead of folding. Colors resolve through --dsw-*
|
||||
// tokens; geometry mirrors CodeBlock.
|
||||
|
||||
import { useCallback, useMemo, useState } from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write packages/ui/tui/README.md
|
||||
README.md: a577fb2f858f61eb765d4a1a9564f452d01d92c1
|
||||
README.zh.md: 61e1b9d526a00e3c8cbc2c9ed0cc483e2ab8dba2
|
||||
README.md: 60e42a64305931a6bf93a470f851f662be33e2bb
|
||||
README.zh.md: fc12b75a1e320103a1d4cc70cc00adfeb639a3d9
|
||||
|
||||
@@ -50,6 +50,7 @@ A launcher can seed a fresh session's first turn by providing `INITIAL_SKILL_KEY
|
||||
| `sessionId` | `main` | Exact shared agent/session identity driven by the terminal |
|
||||
| `showReasoning` | `true` | Render reasoning blocks |
|
||||
| `maxToolOutputLines` | `6` | Output lines retained across a collapsed tool card's head/tail preview |
|
||||
| `maxDiffEditLength` | `1000` | Maximum added and removed lines explored for an exact diff before whole-side fallback |
|
||||
| `maxQuestionOptions` | `8` | Visible options in a question panel |
|
||||
| `maxModelOptions` | `8` | Visible models in the model selector |
|
||||
| `maxResumeOptions` | `8` | Visible sessions in the resume selector |
|
||||
@@ -73,6 +74,7 @@ A launcher can seed a fresh session's first turn by providing `INITIAL_SKILL_KEY
|
||||
sessionId: main-session-123
|
||||
showReasoning: true
|
||||
maxToolOutputLines: 6
|
||||
maxDiffEditLength: 1000
|
||||
fileSearchExcludedDirectories: ['.git', 'node_modules', 'dist']
|
||||
```
|
||||
|
||||
@@ -84,7 +86,7 @@ Every general-purpose SGR code the TUI emits lives in one table, `paletteSpec` i
|
||||
|
||||
There is one role per visual meaning: `dim` is the single recessed tone, `accent` the single interaction emphasis, and `brand` the DeepSeek mark's standard-ANSI fallback, while `success` and `error` double as a diff's added and removed lines. Colors and attributes are separately typed, so `bold(accent(x))` compiles and `accent(error(x))` does not — SGR has no color stack, so nesting one color inside another silently drops the outer color at the inner one's close. Attributes occupy independent SGR groups and compose with any color in either order. Run `/palette` to see every role as your terminal renders it, with its SGR pair.
|
||||
|
||||
Grouped regions (user prompts, assistant replies, tool cards) are separated by a bold, underlined role header in the role color and blank-line spacing rather than a filled block or a per-line prefix, so a mouse drag-select copies the message text without any leading bar or indent; a tool card's status (pending, error, success) shows in its colored, underlined title glyph and title. Inside a tool card, the whole body — presenter title, a terminal `$` command and cwd, and the tool's own output — renders in one dim tone, so only the status-colored header carries color and the body reads as one recessed block instead of a run of competing shades; an injected-context card's prose is the same tone as its header. A diff card's `+`/`-` lines and a `[signal …]` marker stay colored, because there the color is the meaning rather than emphasis. The question panel emphasizes its active row with bold accent text, while selectors use reverse video. These treatments are foreground-only, so they never collide with the terminal background. Set `color: false` to strip all styling.
|
||||
Grouped regions (user prompts, assistant replies, tool cards) are separated by a bold, underlined role header in the role color and blank-line spacing rather than a filled block or a per-line prefix, so a mouse drag-select copies the message text without any leading bar or indent; a tool card's status (pending, error, success) shows in its colored, underlined title glyph and title. Inside a tool card, the whole body — presenter title, a terminal `$` command and cwd, and the tool's own output — renders in one dim tone, so only the status-colored header carries color and the body reads as one recessed block instead of a run of competing shades; an injected-context card's prose is the same tone as its header. A diff card with both sides available colors and counts exact added `+` and removed `-` lines, while unchanged context stays dim and uncounted. If exact comparison exceeds `maxDiffEditLength`, the card renders each old-side row as removed and each new-side row as added, marks the footer approximate, and caches that fallback for later redraws. When `oldText` is unavailable, including pending writes and replay fallbacks as well as creates, every non-empty new-side row is shown and counted as added; that count does not prove the rows were absent from an existing file. Empty new content produces no synthetic `+ ` row. A `[signal …]` marker remains colored because there the color is the meaning rather than emphasis. The question panel emphasizes its active row with bold accent text, while selectors use reverse video. These treatments are foreground-only, so they never collide with the terminal background. Set `color: false` to strip all styling.
|
||||
|
||||
## Model Experience
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ Footer 将会话报告的用量汇总为 `↑<uncached input> ↓<output>`;任
|
||||
| `sessionId` | `main` | 由终端驱动的精确共享 agent/会话身份 |
|
||||
| `showReasoning` | `true` | 渲染 reasoning 块 |
|
||||
| `maxToolOutputLines` | `6` | 折叠工具卡片的头尾预览所保留的输出行数 |
|
||||
| `maxDiffEditLength` | `1000` | 回退到整侧展示前,精确 diff 最多探索的新增与删除行总数 |
|
||||
| `maxQuestionOptions` | `8` | 问题面板中可见的选项数 |
|
||||
| `maxModelOptions` | `8` | 模型选择器中可见的模型数 |
|
||||
| `maxResumeOptions` | `8` | 恢复选择器中可见的会话数 |
|
||||
@@ -73,6 +74,7 @@ Footer 将会话报告的用量汇总为 `↑<uncached input> ↓<output>`;任
|
||||
sessionId: main-session-123
|
||||
showReasoning: true
|
||||
maxToolOutputLines: 6
|
||||
maxDiffEditLength: 1000
|
||||
fileSearchExcludedDirectories: ['.git', 'node_modules', 'dist']
|
||||
```
|
||||
|
||||
@@ -84,7 +86,7 @@ TUI 发出的所有通用 SGR 代码都集中在一个表中,即 `components/t
|
||||
|
||||
每种视觉语义只对应一个角色:`dim` 是唯一的弱化色调,`accent` 是唯一的交互强调色,`brand` 是 DeepSeek 标志的标准 ANSI 回退色,`success` 和 `error` 还分别充当 diff 的新增行与删除行。颜色和属性分属不同类型,因此 `bold(accent(x))` 可以通过编译,`accent(error(x))` 则不行——SGR 没有颜色栈;在一种颜色内嵌套另一种颜色时,内层颜色闭合时会静默丢弃外层颜色。各属性占用彼此独立的 SGR 组,可以按任一顺序与任何颜色组合。运行 `/palette` 可查看每个角色在你的终端上的实际渲染效果及其 SGR 码对。
|
||||
|
||||
成组区域(用户提示词、assistant 回复、工具卡片)通过以角色色渲染的粗体带下划线角色标题和空行分隔,而非填充背景块或逐行前缀,因此用鼠标框选复制时不会带上任何左侧竖条或缩进;工具卡片的状态(进行中、错误、成功)由其彩色带下划线的标题字形与标题体现。在工具卡片内部,整个正文——presenter 标题、终端 `$` 命令与 cwd,以及工具自身的输出——统一以同一种暗色渲染,因此只有带状态色的表头携带颜色,正文读作一个整体弱化的区块,而不是一串互相竞争的色调;注入上下文卡片的正文与其表头也是同一种色调。diff 卡片的 `+`/`-` 行与 `[signal …]` 标记保留颜色,因为那里的颜色本身就是语义,而非强调。问题面板使用粗体强调色文本突出活跃行,选择器则使用反色。所有效果都只作用于前景色,因此不会与终端背景冲突。设置 `color: false` 可移除所有样式。
|
||||
成组区域(用户提示词、assistant 回复、工具卡片)通过以角色色渲染的粗体带下划线角色标题和空行分隔,而非填充背景块或逐行前缀,因此用鼠标框选复制时不会带上任何左侧竖条或缩进;工具卡片的状态(进行中、错误、成功)由其彩色带下划线的标题字形与标题体现。在工具卡片内部,整个正文——presenter 标题、终端 `$` 命令与 cwd,以及工具自身的输出——统一以同一种暗色渲染,因此只有带状态色的表头携带颜色,正文读作一个整体弱化的区块,而不是一串互相竞争的色调;注入上下文卡片的正文与其表头也是同一种色调。当前后两侧文本均可用时,diff 卡片会为精确识别出的新增 `+` 行和删除 `-` 行着色并计数;未变更的上下文保持暗色且不纳入计数。如果精确比较超出 `maxDiffEditLength`,卡片会把旧侧每一行渲染为删除行、把新侧每一行渲染为新增行,将页脚标记为近似结果,并缓存该回退结果供后续重绘使用。当 `oldText` 不可用时(包括待处理写入、回放回退以及文件创建),新侧的每个非空行都会显示并计作新增行;该计数不能证明这些行原先不存在于已有文件中。新内容为空时,不会补出虚构的 `+ ` 行。`[signal …]` 标记仍保留颜色,因为那里的颜色本身就是语义,而非强调。问题面板使用粗体强调色文本突出活跃行,选择器则使用反色。所有效果都只作用于前景色,因此不会与终端背景冲突。设置 `color: false` 可移除所有样式。
|
||||
|
||||
## 模型体验
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@earendil-works/pi-tui": "0.80.7",
|
||||
"diff": "^9.0.0",
|
||||
"saxes": "6.0.0",
|
||||
"schemastery": "^3.18.0"
|
||||
},
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
type Component,
|
||||
type MarkdownTheme,
|
||||
} from '@earendil-works/pi-tui'
|
||||
import { diffLines as compareLines } from 'diff'
|
||||
import type { Agent } from '@deepseek-ai/dsh-agent'
|
||||
import type { ContentBlock, StreamChunk } from '@deepseek-ai/dsh-llm'
|
||||
import type { JsonValue, SessionEvent, TodoItem } from '@deepseek-ai/dsh-session'
|
||||
@@ -52,12 +53,17 @@ function pretty(value: unknown): string {
|
||||
return displayText(serialized ?? String(value))
|
||||
}
|
||||
|
||||
interface RenderedDiff {
|
||||
lines: string[]
|
||||
added: number
|
||||
removed: number
|
||||
approximate: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* A side's content lines under the terminator rule the Web DiffBlock also
|
||||
* applies: empty text is zero lines (a full deletion's `newText`, a create's
|
||||
* absent `oldText`), and a single trailing newline terminates the last line
|
||||
* rather than adding an empty one. An interior blank line survives. Keeping the
|
||||
* two front ends on the same rule holds their `+A -R` footers in step.
|
||||
* applies: empty text is zero lines, a trailing newline terminates the last
|
||||
* line, and an interior blank line survives.
|
||||
*/
|
||||
function diffContentLines(text: string): string[] {
|
||||
if (text === '') return []
|
||||
@@ -65,16 +71,47 @@ function diffContentLines(text: string): string[] {
|
||||
return body.split('\n')
|
||||
}
|
||||
|
||||
/** A file diff as colored `+`/`-` lines, optionally prefixed with its path. */
|
||||
function diffLines(diff: FileDiff, palette: Palette): string[] {
|
||||
/**
|
||||
* A file diff whose unchanged context stays neutral and does not affect exact
|
||||
* change totals. Comparisons beyond the edit-distance budget fall back to
|
||||
* whole-side rendering so a model-authored pending edit cannot stall the TUI.
|
||||
*/
|
||||
function renderDiff(diff: FileDiff, maxDiffEditLength: number, palette: Palette): RenderedDiff {
|
||||
// The card header is a fixed `Tool / <name>` frame that never names a file, so
|
||||
// each hunk always carries its own path header (no redundancy to suppress).
|
||||
const lines = [palette.bold(displayText(diff.path))]
|
||||
if (diff.oldText !== null) {
|
||||
for (const line of diffContentLines(displayText(diff.oldText))) lines.push(palette.error(`- ${line}`))
|
||||
let added = 0
|
||||
let removed = 0
|
||||
if (diff.oldText === null) {
|
||||
const newLines = diffContentLines(displayText(diff.newText))
|
||||
added = newLines.length
|
||||
for (const line of newLines) lines.push(palette.success(`+ ${line}`))
|
||||
return { lines, added, removed, approximate: false }
|
||||
}
|
||||
for (const line of diffContentLines(displayText(diff.newText))) lines.push(palette.success(`+ ${line}`))
|
||||
return lines
|
||||
const changes = compareLines(diff.oldText, diff.newText, { maxEditLength: maxDiffEditLength })
|
||||
if (changes === undefined) {
|
||||
const oldLines = diffContentLines(displayText(diff.oldText))
|
||||
const newLines = diffContentLines(displayText(diff.newText))
|
||||
lines.push(palette.dim(`[exact line diff omitted: >${maxDiffEditLength} changed lines]`))
|
||||
removed = oldLines.length
|
||||
added = newLines.length
|
||||
for (const line of oldLines) lines.push(palette.error(`- ${line}`))
|
||||
for (const line of newLines) lines.push(palette.success(`+ ${line}`))
|
||||
return { lines, added, removed, approximate: true }
|
||||
}
|
||||
for (const change of changes) {
|
||||
const changedLines = diffContentLines(displayText(change.value))
|
||||
if (change.added) {
|
||||
added += changedLines.length
|
||||
for (const line of changedLines) lines.push(palette.success(`+ ${line}`))
|
||||
} else if (change.removed) {
|
||||
removed += changedLines.length
|
||||
for (const line of changedLines) lines.push(palette.error(`- ${line}`))
|
||||
} else {
|
||||
for (const line of changedLines) lines.push(palette.dim(` ${line}`))
|
||||
}
|
||||
}
|
||||
return { lines, added, removed, approximate: false }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -378,12 +415,14 @@ export class ToolCardComponent implements Component {
|
||||
private visibility: ToolCardVisibility = 'collapsed'
|
||||
private callView: ToolCallView
|
||||
private resultView: ToolResultView | undefined
|
||||
private diffBodyCache: { view: ToolCallView | ToolResultView; body: CardBody } | undefined
|
||||
|
||||
constructor(
|
||||
private readonly name: string,
|
||||
private readonly parsed: ParsedArguments,
|
||||
private readonly definition: ToolDefinition | undefined,
|
||||
private readonly maxOutputLines: number,
|
||||
private readonly maxDiffEditLength: number,
|
||||
private readonly palette: Palette,
|
||||
private readonly mdTheme: MarkdownTheme,
|
||||
) {
|
||||
@@ -407,6 +446,7 @@ export class ToolCardComponent implements Component {
|
||||
* @param event - The `tool/result` event payload.
|
||||
*/
|
||||
updateResult(event: Extract<SessionEvent, { type: 'tool/result' }>['data']): void {
|
||||
this.diffBodyCache = undefined
|
||||
const result = event.message.content[0]
|
||||
this.result = {
|
||||
content: [...result.content],
|
||||
@@ -560,24 +600,28 @@ export class ToolCardComponent implements Component {
|
||||
return { prelude: prelude.filter(Boolean), lines: lines.filter(Boolean) }
|
||||
}
|
||||
if (view.card === 'diff') {
|
||||
if (this.diffBodyCache?.view === view) return this.diffBodyCache.body
|
||||
// The header no longer names the file, so each diff keeps its own path
|
||||
// header. A trailing footer summarizes the change (`+A -R · N file(s)`),
|
||||
// on the same terminator rule and distinct-path count the Web DiffBlock
|
||||
// uses, so the two front ends' footers agree.
|
||||
let added = 0
|
||||
let removed = 0
|
||||
const paths = new Set<string>()
|
||||
const hunks = view.diffs.flatMap((diff, index) => {
|
||||
paths.add(diff.path)
|
||||
if (diff.oldText !== null) removed += diffContentLines(displayText(diff.oldText)).length
|
||||
added += diffContentLines(displayText(diff.newText)).length
|
||||
return [...index > 0 ? [''] : [], ...diffLines(diff, this.palette)]
|
||||
// header. A trailing footer summarizes the exact changed rows when the
|
||||
// bounded comparison succeeds (`+A -R · N file(s)`).
|
||||
const renderedDiffs = view.diffs.map(diff =>
|
||||
renderDiff(diff, this.maxDiffEditLength, this.palette),
|
||||
)
|
||||
const added = renderedDiffs.reduce((total, rendered) => total + rendered.added, 0)
|
||||
const removed = renderedDiffs.reduce((total, rendered) => total + rendered.removed, 0)
|
||||
const approximate = renderedDiffs.some(rendered => rendered.approximate)
|
||||
const hunks = renderedDiffs.flatMap((rendered, index) => {
|
||||
return [...index > 0 ? [''] : [], ...rendered.lines]
|
||||
})
|
||||
const files = paths.size
|
||||
const footer = this.palette.dim(`└ +${added} -${removed} · ${files} file${files === 1 ? '' : 's'}`)
|
||||
const files = new Set(view.diffs.map(diff => diff.path)).size
|
||||
const footer = this.palette.dim(
|
||||
`└ +${added} -${removed} · ${files} file${files === 1 ? '' : 's'}${approximate ? ' · approximate' : ''}`,
|
||||
)
|
||||
// A diff's own `+`/`-` colors carry its meaning, so it renders verbatim
|
||||
// rather than under the dim result-output color.
|
||||
return { prelude: [...hunks, footer], lines: [] }
|
||||
const body = { prelude: [...hunks, footer], lines: [] }
|
||||
this.diffBodyCache = { view, body }
|
||||
return body
|
||||
}
|
||||
// A generic or read card carries its own envelope-stripped `content`; a
|
||||
// search or web card carries no `content` copy and falls back to the raw
|
||||
|
||||
@@ -34,6 +34,8 @@ export interface TuiConfig {
|
||||
showReasoning?: boolean
|
||||
/** Maximum tool-card body lines retained in its collapsed head/tail preview. */
|
||||
maxToolOutputLines?: number
|
||||
/** Maximum added and removed lines explored while deriving an exact line diff. */
|
||||
maxDiffEditLength?: number
|
||||
/** Maximum options visible at once in a user-question panel. */
|
||||
maxQuestionOptions?: number
|
||||
/** Maximum models visible at once in the model selector. */
|
||||
@@ -66,6 +68,7 @@ export interface TuiConfig {
|
||||
|
||||
const showReasoningSchema = z.boolean().default(true)
|
||||
const maxToolOutputLinesSchema = z.number().step(1).min(1).default(6)
|
||||
const maxDiffEditLengthSchema = z.number().step(1).min(1).default(1000)
|
||||
const maxQuestionOptionsSchema = z.number().step(1).min(1).default(8)
|
||||
const maxModelOptionsSchema = z.number().step(1).min(1).default(8)
|
||||
const maxResumeOptionsSchema = z.number().step(1).min(1).default(8)
|
||||
@@ -98,6 +101,7 @@ const titleSchema = z.string().default('DeepSeek Harness')
|
||||
const tuiConfigSchemaFields = {
|
||||
showReasoning: showReasoningSchema,
|
||||
maxToolOutputLines: maxToolOutputLinesSchema,
|
||||
maxDiffEditLength: maxDiffEditLengthSchema,
|
||||
maxQuestionOptions: maxQuestionOptionsSchema,
|
||||
maxModelOptions: maxModelOptionsSchema,
|
||||
maxResumeOptions: maxResumeOptionsSchema,
|
||||
@@ -139,6 +143,7 @@ export const Config: z<Config> = z.object({
|
||||
initialSkill: z.string(),
|
||||
showReasoning: tuiConfigSchemaFields.showReasoning,
|
||||
maxToolOutputLines: tuiConfigSchemaFields.maxToolOutputLines,
|
||||
maxDiffEditLength: tuiConfigSchemaFields.maxDiffEditLength,
|
||||
maxQuestionOptions: tuiConfigSchemaFields.maxQuestionOptions,
|
||||
maxModelOptions: tuiConfigSchemaFields.maxModelOptions,
|
||||
maxResumeOptions: tuiConfigSchemaFields.maxResumeOptions,
|
||||
@@ -169,6 +174,7 @@ export interface ResolvedTuiThemeConfig {
|
||||
export interface ResolvedTuiConfig {
|
||||
showReasoning: boolean
|
||||
maxToolOutputLines: number
|
||||
maxDiffEditLength: number
|
||||
maxQuestionOptions: number
|
||||
maxModelOptions: number
|
||||
maxResumeOptions: number
|
||||
@@ -195,6 +201,7 @@ export function resolveTuiConfig(config: TuiConfig | undefined): ResolvedTuiConf
|
||||
return {
|
||||
showReasoning: config?.showReasoning ?? true,
|
||||
maxToolOutputLines: config?.maxToolOutputLines ?? 6,
|
||||
maxDiffEditLength: config?.maxDiffEditLength ?? 1000,
|
||||
maxQuestionOptions: config?.maxQuestionOptions ?? 8,
|
||||
maxModelOptions: config?.maxModelOptions ?? 8,
|
||||
maxResumeOptions: config?.maxResumeOptions ?? 8,
|
||||
|
||||
@@ -643,6 +643,7 @@ export function createTuiChat(
|
||||
parsed,
|
||||
ctx.tools.get(event.data.name, agent),
|
||||
resolved.maxToolOutputLines,
|
||||
resolved.maxDiffEditLength,
|
||||
palette,
|
||||
mdTheme,
|
||||
)
|
||||
@@ -835,7 +836,15 @@ export function createTuiChat(
|
||||
const callId = event.data.message.source.callId
|
||||
let card = toolCards.get(callId)
|
||||
if (card === undefined) {
|
||||
card = new ToolCardComponent('tool', { value: {}, valid: true }, undefined, resolved.maxToolOutputLines, palette, mdTheme)
|
||||
card = new ToolCardComponent(
|
||||
'tool',
|
||||
{ value: {}, valid: true },
|
||||
undefined,
|
||||
resolved.maxToolOutputLines,
|
||||
resolved.maxDiffEditLength,
|
||||
palette,
|
||||
mdTheme,
|
||||
)
|
||||
card.setVisibility(toolsVisibility)
|
||||
chat.addChild(card)
|
||||
allToolCards.add(card)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
terminal 100x40 buffer=normal length=40 base=0 viewport=0
|
||||
terminal 100x40 buffer=normal length=41 base=1 viewport=1
|
||||
lifecycle started=1 stopped=0 progress=inactive
|
||||
title "DSH snapshot"
|
||||
cursor hidden column=7 viewportRow=34 bufferRow=34
|
||||
cursor hidden column=7 viewportRow=39 bufferRow=40
|
||||
buffer
|
||||
0| " DEEPSEEK HARNESS"
|
||||
style 1-8 fg=bright-magenta bold
|
||||
@@ -31,9 +31,9 @@ buffer
|
||||
style 0-10 bold
|
||||
14| "- old line "
|
||||
style 0-9 fg=red
|
||||
15| "… +3 lines (Ctrl+O to expand) "
|
||||
15| "… +2 lines (Ctrl+O to expand) "
|
||||
style 0-28 dim
|
||||
16| "└ +2 -2 · 1 file "
|
||||
16| "└ +1 -1 · 1 file "
|
||||
style 0-15 dim
|
||||
17| <blank>
|
||||
18| "● Tool / subagent"
|
||||
@@ -58,17 +58,27 @@ buffer
|
||||
style 0-99 dim
|
||||
30| "Loaded review instructions. "
|
||||
style 0-99 dim
|
||||
31| "Model wait 0.0s "
|
||||
31| <blank>
|
||||
32| "● Tool / large_edit"
|
||||
style 0-18 fg=green
|
||||
33| "src/large.ts "
|
||||
style 0-11 bold
|
||||
34| "[exact line diff omitted: >2 changed lines] "
|
||||
style 0-42 dim
|
||||
35| "… +6 lines (Ctrl+O to expand) "
|
||||
style 0-28 dim
|
||||
36| "└ +3 -3 · 1 file · approximate "
|
||||
style 0-29 dim
|
||||
37| "Model wait 0.0s "
|
||||
style 0-14 dim
|
||||
32| <blank>
|
||||
33| "/workspace/project (tui-staging) deepseek-v4-flash ↑0 ↓0 0% context"
|
||||
38| <blank>
|
||||
39| "/workspace/project (tui-staging) deepseek-v4-flash ↑0 ↓0 0% context"
|
||||
style 0-17 fg=bright-magenta bold
|
||||
style 18-31 dim
|
||||
style 34-50 dim
|
||||
style 53-57 dim
|
||||
style 60-69 dim
|
||||
34| " dsh > "
|
||||
40| " dsh > "
|
||||
style 1-3 fg=bright-magenta bold
|
||||
style 5-6 dim
|
||||
style 7-7 inverse
|
||||
35-39| <blank>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
terminal 100x40 buffer=normal length=43 base=3 viewport=3
|
||||
terminal 100x40 buffer=normal length=53 base=13 viewport=13
|
||||
lifecycle started=1 stopped=0 progress=inactive
|
||||
title "DSH snapshot"
|
||||
cursor hidden column=7 viewportRow=39 bufferRow=42
|
||||
cursor hidden column=7 viewportRow=39 bufferRow=52
|
||||
buffer
|
||||
0| " DEEPSEEK HARNESS"
|
||||
style 1-8 fg=bright-magenta bold
|
||||
@@ -37,54 +37,73 @@ buffer
|
||||
style 0-10 bold
|
||||
17| "- old line "
|
||||
style 0-9 fg=red
|
||||
18| "- keep "
|
||||
style 0-5 fg=red
|
||||
19| "+ new line "
|
||||
18| "+ new line "
|
||||
style 0-9 fg=green
|
||||
20| "+ keep "
|
||||
style 0-5 fg=green
|
||||
21| "└ +2 -2 · 1 file "
|
||||
19| " keep "
|
||||
style 0-5 dim
|
||||
20| "└ +1 -1 · 1 file "
|
||||
style 0-15 dim
|
||||
22| <blank>
|
||||
23| "● Tool / subagent"
|
||||
21| <blank>
|
||||
22| "● Tool / subagent"
|
||||
style 0-16 fg=green
|
||||
24| "Delegate renderer audit "
|
||||
23| "Delegate renderer audit "
|
||||
style 0-99 dim
|
||||
25| "The renderer has explicit lifecycle ownership. "
|
||||
24| "The renderer has explicit lifecycle ownership. "
|
||||
style 0-99 dim
|
||||
26| <blank>
|
||||
27| "● Tool / task_output"
|
||||
25| <blank>
|
||||
26| "● Tool / task_output"
|
||||
style 0-19 fg=green
|
||||
28| "Read output from background task subagent-7 "
|
||||
27| "Read output from background task subagent-7 "
|
||||
style 0-99 dim
|
||||
29| " "
|
||||
30| "console "
|
||||
28| " "
|
||||
29| "console "
|
||||
style 0-6 dim
|
||||
31| " started background task bash-5 "
|
||||
30| " started background task bash-5 "
|
||||
style 0-1 dim
|
||||
style 2-31 fg=cyan dim
|
||||
style 32-99 dim
|
||||
32| " "
|
||||
33| <blank>
|
||||
34| "● Tool / skill"
|
||||
31| " "
|
||||
32| <blank>
|
||||
33| "● Tool / skill"
|
||||
style 0-13 fg=green
|
||||
35| "Load skill dsh-code-review "
|
||||
34| "Load skill dsh-code-review "
|
||||
style 0-99 dim
|
||||
36| "Loaded review instructions. "
|
||||
35| "Loaded review instructions. "
|
||||
style 0-99 dim
|
||||
37| "Model wait 0.0s "
|
||||
36| <blank>
|
||||
37| "● Tool / large_edit"
|
||||
style 0-18 fg=green
|
||||
38| "src/large.ts "
|
||||
style 0-11 bold
|
||||
39| "[exact line diff omitted: >2 changed lines] "
|
||||
style 0-42 dim
|
||||
40| "- old one "
|
||||
style 0-8 fg=red
|
||||
41| "- old two "
|
||||
style 0-8 fg=red
|
||||
42| "- old three "
|
||||
style 0-10 fg=red
|
||||
43| "+ new one "
|
||||
style 0-8 fg=green
|
||||
44| "+ new two "
|
||||
style 0-8 fg=green
|
||||
45| "+ new three "
|
||||
style 0-10 fg=green
|
||||
46| "└ +3 -3 · 1 file · approximate "
|
||||
style 0-29 dim
|
||||
47| "Model wait 0.0s "
|
||||
style 0-14 dim
|
||||
38| <blank>
|
||||
39| "Tool and context cards expanded. "
|
||||
48| <blank>
|
||||
49| "Tool and context cards expanded. "
|
||||
style 0-31 dim
|
||||
40| <blank>
|
||||
41| "/workspace/project (tui-staging) deepseek-v4-flash ↑0 ↓0 0% context"
|
||||
50| <blank>
|
||||
51| "/workspace/project (tui-staging) deepseek-v4-flash ↑0 ↓0 0% context"
|
||||
style 0-17 fg=bright-magenta bold
|
||||
style 18-31 dim
|
||||
style 34-50 dim
|
||||
style 53-57 dim
|
||||
style 60-69 dim
|
||||
42| " dsh > "
|
||||
52| " dsh > "
|
||||
style 1-3 fg=bright-magenta bold
|
||||
style 5-6 dim
|
||||
style 7-7 inverse
|
||||
|
||||
@@ -272,13 +272,32 @@ const ADVANCED_CARD_TOOLS: Record<string, ToolDefinition> = {
|
||||
edit: visualTool(
|
||||
'edit',
|
||||
() => ({ card: 'diff', title: 'Edit src/view.ts', diffs: [{ path: 'src/view.ts', oldText: 'old line', newText: 'new line' }] }),
|
||||
// The real edit/write tools produce exactly one diff whose path the title
|
||||
// already names, so the card omits the redundant per-file header.
|
||||
// The fixed tool header never names a path, so the hunk retains its path.
|
||||
(): ToolResultView => ({
|
||||
card: 'diff',
|
||||
diffs: [{ path: 'src/view.ts', oldText: 'old line\nkeep', newText: 'new line\nkeep' }],
|
||||
}),
|
||||
),
|
||||
large_edit: visualTool(
|
||||
'large_edit',
|
||||
() => ({
|
||||
card: 'diff',
|
||||
title: 'Edit src/large.ts',
|
||||
diffs: [{
|
||||
path: 'src/large.ts',
|
||||
oldText: 'old one\nold two\nold three',
|
||||
newText: 'new one\nnew two\nnew three',
|
||||
}],
|
||||
}),
|
||||
(): ToolResultView => ({
|
||||
card: 'diff',
|
||||
diffs: [{
|
||||
path: 'src/large.ts',
|
||||
oldText: 'old one\nold two\nold three',
|
||||
newText: 'new one\nnew two\nnew three',
|
||||
}],
|
||||
}),
|
||||
),
|
||||
subagent: visualTool('subagent', args => ({
|
||||
card: 'generic',
|
||||
title: 'Delegate renderer audit',
|
||||
@@ -588,7 +607,7 @@ describe('TUI terminal-state snapshots', () => {
|
||||
it('pins terminal, diff, subagent, task, skill, collapsed, and expanded cards', async () => {
|
||||
const harness = await setupSnapshot({
|
||||
tools: ADVANCED_CARD_TOOLS,
|
||||
config: { maxToolOutputLines: 3 },
|
||||
config: { maxToolOutputLines: 3, maxDiffEditLength: 2 },
|
||||
}, { columns: 100, rows: 40 })
|
||||
const calls = [
|
||||
{ id: 'advanced-1', name: 'bash', arguments: { command: 'pnpm run test:coverage' } },
|
||||
@@ -596,6 +615,7 @@ describe('TUI terminal-state snapshots', () => {
|
||||
{ id: 'advanced-3', name: 'subagent', arguments: { prompt: 'Review renderer ownership and report only gaps.' } },
|
||||
{ id: 'advanced-4', name: 'task_output', arguments: { task_id: 'subagent-7', wait: true } },
|
||||
{ id: 'advanced-5', name: 'skill', arguments: { name: 'dsh-code-review' } },
|
||||
{ id: 'advanced-6', name: 'large_edit', arguments: { file_path: 'src/large.ts' } },
|
||||
]
|
||||
await renderAfter(harness, () => {
|
||||
appendToolCalls(harness.session, calls)
|
||||
@@ -604,6 +624,7 @@ describe('TUI terminal-state snapshots', () => {
|
||||
appendToolResult(harness.session, 'advanced-3', [{ type: 'text', text: 'The renderer has explicit lifecycle ownership.' }])
|
||||
appendToolResult(harness.session, 'advanced-4', [{ type: 'text', text: 'audit complete\n[status: completed]' }])
|
||||
appendToolResult(harness.session, 'advanced-5', [{ type: 'text', text: 'Loaded review instructions.' }])
|
||||
appendToolResult(harness.session, 'advanced-6', [{ type: 'text', text: 'large edit complete' }])
|
||||
})
|
||||
await checkpoint('advanced-cards-collapsed', harness.terminal, { includeScrollback: true })
|
||||
|
||||
|
||||
@@ -185,6 +185,7 @@ describe('TUI config', () => {
|
||||
expect(resolveTuiConfig(undefined)).toEqual({
|
||||
showReasoning: true,
|
||||
maxToolOutputLines: 6,
|
||||
maxDiffEditLength: 1000,
|
||||
maxQuestionOptions: 8,
|
||||
maxModelOptions: 8,
|
||||
maxResumeOptions: 8,
|
||||
@@ -210,6 +211,7 @@ describe('TUI config', () => {
|
||||
expect(resolveTuiConfig({
|
||||
showReasoning: false,
|
||||
maxToolOutputLines: 2,
|
||||
maxDiffEditLength: 12,
|
||||
maxQuestionOptions: 3,
|
||||
maxModelOptions: 4,
|
||||
maxResumeOptions: 5,
|
||||
@@ -227,6 +229,7 @@ describe('TUI config', () => {
|
||||
})).toEqual({
|
||||
showReasoning: false,
|
||||
maxToolOutputLines: 2,
|
||||
maxDiffEditLength: 12,
|
||||
maxQuestionOptions: 3,
|
||||
maxModelOptions: 4,
|
||||
maxResumeOptions: 5,
|
||||
@@ -4675,7 +4678,11 @@ describe('tool cards and surface replay', () => {
|
||||
presentCall: () => ({
|
||||
card: 'diff',
|
||||
title: 'Edit src/only.ts',
|
||||
diffs: [{ path: 'src/only.ts', oldText: 'old', newText: 'new' }],
|
||||
diffs: [{
|
||||
path: 'src/only.ts',
|
||||
oldText: 'my: my-MM\nne: ne-NP\nnl: nl-NL\nnb: no-NO\npa: pa-Guru-IN\npl: pl-PL\npt_pt: pt-PT',
|
||||
newText: 'my: my-MM\nne: ne-NP\nnl: nl-NL\nnb: nb-NO\npa: pa-Guru-IN\npl: pl-PL\npt_pt: pt-PT',
|
||||
}],
|
||||
}),
|
||||
},
|
||||
scatteredDiff: {
|
||||
@@ -5029,7 +5036,7 @@ describe('tool cards and surface replay', () => {
|
||||
})
|
||||
|
||||
it('names a single-file diff in the body once, under a fixed Tool header', async () => {
|
||||
const result = await setup({ tools })
|
||||
const result = await setup({ tools, config: { maxToolOutputLines: 20 } })
|
||||
appendUser(result.session, 'edit one file')
|
||||
appendAssistant(result.session, [
|
||||
{ type: 'text', text: 'Editing' },
|
||||
@@ -5045,9 +5052,123 @@ describe('tool cards and surface replay', () => {
|
||||
expect(output).toContain('Tool / singleDiff')
|
||||
expect(output).not.toContain('Edit src/only.ts')
|
||||
expect(output.split('src/only.ts').length - 1).toBe(1)
|
||||
expect(output).toContain('- old')
|
||||
expect(output).toContain('+ new')
|
||||
expect(output).toContain('· 1 file')
|
||||
expect(output).toContain(' my: my-MM')
|
||||
expect(output).not.toContain('- my: my-MM')
|
||||
expect(output).not.toContain('+ my: my-MM')
|
||||
expect(output).toContain('- nb: no-NO')
|
||||
expect(output).toContain('+ nb: nb-NO')
|
||||
expect(output).toContain('└ +1 -1 · 1 file')
|
||||
await dispose(result)
|
||||
})
|
||||
|
||||
it('renders an empty create without a synthetic added row', async () => {
|
||||
const emptyCreate: Record<string, ToolDefinition> = {
|
||||
emptyCreate: {
|
||||
name: 'emptyCreate',
|
||||
description: '',
|
||||
parameters: {},
|
||||
output: UNUSED_TOOL_OUTPUT,
|
||||
execute: async () => [],
|
||||
presentCall: () => ({
|
||||
card: 'diff',
|
||||
title: 'Write empty.txt',
|
||||
diffs: [{ path: 'empty.txt', oldText: null, newText: '' }],
|
||||
}),
|
||||
},
|
||||
}
|
||||
const result = await setup({
|
||||
tools: emptyCreate,
|
||||
config: { maxToolOutputLines: 20, theme: { color: false } },
|
||||
})
|
||||
appendAssistant(result.session, [
|
||||
{ type: 'tool-call', id: 'empty-create' as never, name: 'emptyCreate', arguments: '{}' },
|
||||
])
|
||||
result.session.append('tool/call', {
|
||||
turn: 1,
|
||||
step: 1,
|
||||
callId: 'empty-create' as never,
|
||||
name: 'emptyCreate',
|
||||
arguments: '{}',
|
||||
})
|
||||
await tick()
|
||||
const rows = result.terminal.output.split('\n').map(row => row.trim())
|
||||
expect(result.terminal.output).toContain('empty.txt')
|
||||
expect(result.terminal.output).toContain('└ +0 -0 · 1 file')
|
||||
expect(rows).not.toContain('+')
|
||||
await dispose(result)
|
||||
})
|
||||
|
||||
it('bounds and caches exact diff comparison before whole-side fallback', async () => {
|
||||
let oldTextReads = 0
|
||||
let newText = 'new one\nnew two'
|
||||
const boundedDiff = {
|
||||
path: 'bounded.txt',
|
||||
get oldText() {
|
||||
oldTextReads += 1
|
||||
return 'old one\nold two'
|
||||
},
|
||||
get newText() { return newText },
|
||||
}
|
||||
const boundedView = {
|
||||
card: 'diff' as const,
|
||||
title: 'Edit bounded.txt',
|
||||
diffs: [boundedDiff],
|
||||
}
|
||||
const bounded: Record<string, ToolDefinition> = {
|
||||
bounded: {
|
||||
name: 'bounded',
|
||||
description: '',
|
||||
parameters: {},
|
||||
output: UNUSED_TOOL_OUTPUT,
|
||||
execute: async () => [],
|
||||
presentCall: () => boundedView,
|
||||
presentResult: () => {
|
||||
newText = 'settled one\nsettled two'
|
||||
return boundedView
|
||||
},
|
||||
},
|
||||
}
|
||||
const result = await setup({
|
||||
tools: bounded,
|
||||
config: {
|
||||
maxToolOutputLines: 20,
|
||||
maxDiffEditLength: 1,
|
||||
theme: { color: false },
|
||||
},
|
||||
})
|
||||
appendAssistant(result.session, [
|
||||
{ type: 'tool-call', id: 'bounded-diff' as never, name: 'bounded', arguments: '{}' },
|
||||
])
|
||||
result.session.append('tool/call', {
|
||||
turn: 1,
|
||||
step: 1,
|
||||
callId: 'bounded-diff' as never,
|
||||
name: 'bounded',
|
||||
arguments: '{}',
|
||||
})
|
||||
await tick()
|
||||
expect(result.terminal.output).toContain('[exact line diff omitted: >1 changed lines]')
|
||||
expect(result.terminal.output).toContain('- old one')
|
||||
expect(result.terminal.output).toContain('+ new one')
|
||||
expect(result.terminal.output).toContain('└ +2 -2 · 1 file · approximate')
|
||||
const readsAfterFirstRender = oldTextReads
|
||||
expect(readsAfterFirstRender).toBeGreaterThan(0)
|
||||
result.session.append('tool/result', {
|
||||
turn: 1,
|
||||
step: 1,
|
||||
message: createToolResultMessage({
|
||||
callId: 'bounded-diff' as never,
|
||||
content: [{ type: 'text', text: 'done' }],
|
||||
isError: false,
|
||||
}),
|
||||
}, { surfaceOp: 'append' })
|
||||
await tick()
|
||||
expect(result.terminal.output).toContain('+ settled one')
|
||||
expect(oldTextReads).toBeGreaterThan(readsAfterFirstRender)
|
||||
const readsAfterResult = oldTextReads
|
||||
result.terminal.resize(87)
|
||||
await tick()
|
||||
expect(oldTextReads).toBe(readsAfterResult)
|
||||
await dispose(result)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user