惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
博客园_首页
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
小众软件
小众软件
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
refactor(agents): share session tool output rendering · o...
vincentkoc · 2026-06-23 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -9,13 +9,12 @@ import path from "node:path";

99

import { createInterface } from "node:readline";

1010

import { Text } from "@earendil-works/pi-tui";

1111

import { Type } from "typebox";

12-

import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";

1312

import type { AgentTool } from "../../runtime/index.js";

1413

import { ensureTool } from "../../utils/tools-manager.js";

1514

import type { ToolDefinition, ToolRenderResultOptions } from "../extensions/types.js";

1615

import { appendBoundedTextTail, normalizePositiveLimit } from "./limits.js";

1716

import { resolveToCwd } from "./path-utils.js";

18-

import { getTextOutput, invalidArgText, shortenPath, str } from "./render-utils.js";

17+

import { formatSessionToolOutput, invalidArgText, shortenPath, str } from "./render-utils.js";

1918

import type { FindToolDetails } from "./tool-contracts.js";

2019

import { wrapToolDefinition } from "./tool-definition-wrapper.js";

2120

import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";

@@ -92,18 +91,7 @@ function formatFindResult(

9291

theme: typeof import("../../modes/interactive/theme/theme.js").theme,

9392

showImages: boolean,

9493

): string {

95-

const output = getTextOutput(result, showImages).trim();

96-

let text = "";

97-

if (output) {

98-

const lines = output.split("\n");

99-

const maxLines = options.expanded ? lines.length : 20;

100-

const displayLines = lines.slice(0, maxLines);

101-

const remaining = lines.length - maxLines;

102-

text += `\n${displayLines.map((line) => theme.fg("toolOutput", line)).join("\n")}`;

103-

if (remaining > 0) {

104-

text += `${theme.fg("muted", `\n... (${remaining} more lines,`)} ${keyHint("app.tools.expand", "to expand")})`;

105-

}

106-

}

94+

let text = formatSessionToolOutput(result, options, theme, showImages, 20);

10795
10896

const resultLimit = result.details?.resultLimitReached;

10997

const truncation = result.details?.truncation;

Original file line numberDiff line numberDiff line change

@@ -9,13 +9,12 @@ import path from "node:path";

99

import { createInterface } from "node:readline";

1010

import { Text } from "@earendil-works/pi-tui";

1111

import { Type } from "typebox";

12-

import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";

1312

import type { AgentTool } from "../../runtime/index.js";

1413

import { ensureTool } from "../../utils/tools-manager.js";

1514

import type { ToolDefinition, ToolRenderResultOptions } from "../extensions/types.js";

1615

import { appendBoundedTextTail, normalizePositiveLimit } from "./limits.js";

1716

import { resolveToCwd } from "./path-utils.js";

18-

import { getTextOutput, invalidArgText, shortenPath, str } from "./render-utils.js";

17+

import { formatSessionToolOutput, invalidArgText, shortenPath, str } from "./render-utils.js";

1918

import type { GrepToolDetails } from "./tool-contracts.js";

2019

import { wrapToolDefinition } from "./tool-definition-wrapper.js";

2120

import {

@@ -108,18 +107,7 @@ function formatGrepResult(

108107

theme: typeof import("../../modes/interactive/theme/theme.js").theme,

109108

showImages: boolean,

110109

): string {

111-

const output = getTextOutput(result, showImages).trim();

112-

let text = "";

113-

if (output) {

114-

const lines = output.split("\n");

115-

const maxLines = options.expanded ? lines.length : 15;

116-

const displayLines = lines.slice(0, maxLines);

117-

const remaining = lines.length - maxLines;

118-

text += `\n${displayLines.map((line) => theme.fg("toolOutput", line)).join("\n")}`;

119-

if (remaining > 0) {

120-

text += `${theme.fg("muted", `\n... (${remaining} more lines,`)} ${keyHint("app.tools.expand", "to expand")})`;

121-

}

122-

}

110+

let text = formatSessionToolOutput(result, options, theme, showImages, 15);

123111
124112

const matchLimit = result.details?.matchLimitReached;

125113

const truncation = result.details?.truncation;

Original file line numberDiff line numberDiff line change

@@ -7,12 +7,11 @@ import { existsSync, readdirSync, statSync } from "node:fs";

77

import nodePath from "node:path";

88

import { Text } from "@earendil-works/pi-tui";

99

import { Type } from "typebox";

10-

import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";

1110

import type { AgentTool } from "../../runtime/index.js";

1211

import type { ToolDefinition, ToolRenderResultOptions } from "../extensions/types.js";

1312

import { normalizePositiveLimit } from "./limits.js";

1413

import { resolveToCwd } from "./path-utils.js";

15-

import { getTextOutput, invalidArgText, shortenPath, str } from "./render-utils.js";

14+

import { formatSessionToolOutput, invalidArgText, shortenPath, str } from "./render-utils.js";

1615

import type { LsToolDetails } from "./tool-contracts.js";

1716

import { wrapToolDefinition } from "./tool-definition-wrapper.js";

1817

import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";

@@ -79,18 +78,7 @@ function formatLsResult(

7978

theme: typeof import("../../modes/interactive/theme/theme.js").theme,

8079

showImages: boolean,

8180

): string {

82-

const output = getTextOutput(result, showImages).trim();

83-

let text = "";

84-

if (output) {

85-

const lines = output.split("\n");

86-

const maxLines = options.expanded ? lines.length : 20;

87-

const displayLines = lines.slice(0, maxLines);

88-

const remaining = lines.length - maxLines;

89-

text += `\n${displayLines.map((line) => theme.fg("toolOutput", line)).join("\n")}`;

90-

if (remaining > 0) {

91-

text += `${theme.fg("muted", `\n... (${remaining} more lines,`)} ${keyHint("app.tools.expand", "to expand")})`;

92-

}

93-

}

81+

let text = formatSessionToolOutput(result, options, theme, showImages, 20);

9482
9583

const entryLimit = result.details?.entryLimitReached;

9684

const truncation = result.details?.truncation;

Original file line numberDiff line numberDiff line change

@@ -5,9 +5,11 @@

55

*/

66

import * as os from "node:os";

77

import { getCapabilities, getImageDimensions, imageFallback } from "@earendil-works/pi-tui";

8+

import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";

89

import type { Theme } from "../../modes/interactive/theme/theme.js";

910

import { sanitizeBinaryOutput } from "../../shell-utils.js";

1011

import { stripAnsi } from "../../utils/ansi.js";

12+

import type { ToolRenderResultOptions } from "../extensions/types.js";

1113
1214

/** Shortens paths under the current home directory for display. */

1315

export function shortenPath(path: unknown): string {

@@ -79,6 +81,30 @@ export function getTextOutput(

7981

return output;

8082

}

8183
84+

/** Renders bounded text output with the shared TUI expansion hint. */

85+

export function formatSessionToolOutput(

86+

result: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> },

87+

options: ToolRenderResultOptions,

88+

theme: Pick<Theme, "fg">,

89+

showImages: boolean,

90+

collapsedLineLimit: number,

91+

): string {

92+

const output = getTextOutput(result, showImages).trim();

93+

if (!output) {

94+

return "";

95+

}

96+
97+

const lines = output.split("\n");

98+

const maxLines = options.expanded ? lines.length : collapsedLineLimit;

99+

const displayLines = lines.slice(0, maxLines);

100+

const remaining = lines.length - maxLines;

101+

let text = `\n${displayLines.map((line) => theme.fg("toolOutput", line)).join("\n")}`;

102+

if (remaining > 0) {

103+

text += `${theme.fg("muted", `\n... (${remaining} more lines,`)} ${keyHint("app.tools.expand", "to expand")})`;

104+

}

105+

return text;

106+

}

107+
82108

/** Formats the invalid-argument marker with the active theme. */

83109

export function invalidArgText(theme: Pick<Theme, "fg">): string {

84110

return theme.fg("error", "[invalid arg]");