Skip to content
5 changes: 5 additions & 0 deletions .changeset/merge-read-media-into-read-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": minor
---

Read image and video files directly with `Read` instead of `ReadMediaFile`; the `region` and `full_resolution` image cropping parameters are removed.
5 changes: 5 additions & 0 deletions .changeset/merge-read-media-into-read-desktop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kimi-code-app": minor
---

Read image and video files directly with `Read` instead of `ReadMediaFile`; the `region` and `full_resolution` image cropping parameters are removed.
5 changes: 5 additions & 0 deletions .changeset/merge-read-media-into-read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/agent-core-v2": minor

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Mark the agent-core change as breaking

Consumers of @moonshot-ai/agent-core-v2 that still rely on ReadMediaFile or its region and full_resolution inputs lose that behavior after this release. The changeset explicitly removes them but classifies the package change as minor; mark it as breaking or preserve a compatibility path.

AGENTS.md reference: AGENTS.md:L90-L90

Useful? React with 👍 / 👎.

---

Merge `ReadMediaFile` into `Read` for image and video files, remove the `region` and `full_resolution` image cropping parameters and image-crop telemetry, emit capability reminders when model media support changes, and refresh legacy `Read` schemas, filter retired `ReadMediaFile` declarations, and inject a one-time migration reminder when resuming older sessions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { AssistantMessageComponent } from '../messages/assistant-message';
import { ThinkingComponent } from '../messages/thinking';
import { extractKeyArgument } from '../messages/tool-call';
import { pickChip } from '../messages/tool-renderers/chip';
import { parseReadMediaOutput } from '../messages/tool-renderers/media';
import { pickResultRenderer } from '../messages/tool-renderers/registry';
import { STATUS_LABEL, statusColor } from './task-output-viewer';

Expand Down Expand Up @@ -234,7 +235,11 @@ export class AgentActivityViewer extends Container implements Focusable {
? []
: [currentTheme.dim(`${MESSAGE_INDENT}│ ${call.liveOutputTail}`)];
}
if (call.name === 'ReadMediaFile' && call.result.is_error !== true) {
if (
call.result.is_error !== true &&
(call.name === 'ReadMediaFile' ||
(call.name === 'Read' && parseReadMediaOutput(call.result.output) !== null))
) {
return [currentTheme.dim(`${MESSAGE_INDENT}[media output omitted]`)];
}
const components = pickResultRenderer(call.name)(
Expand Down
48 changes: 44 additions & 4 deletions apps/kimi-code/src/tui/components/messages/read-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { STATUS_BULLET } from '#/tui/constant/symbols';
import { currentTheme } from '#/tui/theme';

import type { ToolCallComponent, ToolCallReadSnapshot } from './tool-call';
import { TruncatedOutputComponent } from './tool-renderers/truncated';
import { TruncatedHeaderLine, type HeaderContent } from './truncated-header-line';

const THROTTLE_MS = 200;
Expand Down Expand Up @@ -102,13 +103,23 @@ export class ReadGroupComponent extends Container {
const snapshots = this.entries.map((e) => e.tc.getReadSnapshot());
let pending = 0;
let failed = 0;
let textFiles = 0;
let totalLines = 0;
let images = 0;
let videos = 0;
for (const snap of snapshots) {
if (snap.phase === 'pending') pending += 1;
else if (snap.phase === 'failed') failed += 1;
else totalLines += snap.lines;
else if (snap.mediaKind === 'image') images += 1;
else if (snap.mediaKind === 'video') videos += 1;
else {
textFiles += 1;
totalLines += snap.lines;
}
}
this.headerText.setText(this.buildHeader(snapshots.length, pending, failed, totalLines));
this.headerText.setText(
this.buildHeader(snapshots.length, pending, failed, textFiles, totalLines, images, videos),
);

this.bodyContainer.clear();
if (this.expanded) {
Expand All @@ -118,6 +129,16 @@ export class ReadGroupComponent extends Container {
visibleSnapshots.forEach((snap, idx) => {
const isLast = idx === visibleSnapshots.length - 1;
this.bodyContainer.addChild(new Text(this.buildBodyLine(snap, isLast), 0, 0));
if (snap.mediaUrl !== undefined) {
this.bodyContainer.addChild(new Text(currentTheme.dim(snap.mediaUrl), 5, 0));
}
if (snap.errorOutput) {
this.bodyContainer.addChild(new TruncatedOutputComponent(snap.errorOutput, {
expanded: true,
isError: true,
indent: 5,
}));
}
});
}

Expand All @@ -135,7 +156,10 @@ export class ReadGroupComponent extends Container {
total: number,
pending: number,
failed: number,
textFiles: number,
totalLines: number,
images: number,
videos: number,
): HeaderContent {
if (pending > 0) {
const bullet = currentTheme.fg('text', STATUS_BULLET);
Expand All @@ -151,14 +175,28 @@ export class ReadGroupComponent extends Container {

const bullet = currentTheme.fg('success', STATUS_BULLET);
const label = currentTheme.boldFg('primary', `Read ${String(total)} files`);
const summaryParts: string[] = [];
if (textFiles > 0) {
summaryParts.push(`${String(totalLines)} ${totalLines === 1 ? 'line' : 'lines'}`);
}
if (images > 0) {
summaryParts.push(`${String(images)} ${images === 1 ? 'image' : 'images'}`);
}
if (videos > 0) {
summaryParts.push(`${String(videos)} ${videos === 1 ? 'video' : 'videos'}`);
}
const tail = failed > 0 ? currentTheme.fg('error', ` · ${String(failed)} failed`) : '';
if (summaryParts.length === 0) {
return `${bullet}${label}${tail}`;
}
return {
head: `${bullet}${label}`,
flex: {
text: ` · ${String(totalLines)} ${totalLines === 1 ? 'line' : 'lines'}`,
text: ` · ${summaryParts.join(', ')}`,
style: dimHeaderStyle,
keep: 'head',
},
tail: failed > 0 ? currentTheme.fg('error', ` · ${String(failed)} failed`) : '',
tail,
};
}

Expand All @@ -173,6 +211,8 @@ export class ReadGroupComponent extends Container {
tail = dim(' · reading…');
} else if (snap.phase === 'failed') {
tail = currentTheme.fg('error', ' · failed');
} else if (snap.mediaChip !== undefined) {
tail = dim(` · ${snap.mediaChip}`);
} else {
tail = dim(` · ${String(snap.lines)} ${snap.lines === 1 ? 'line' : 'lines'}`);
}
Expand Down
26 changes: 24 additions & 2 deletions apps/kimi-code/src/tui/components/messages/tool-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import { ShellExecutionComponent } from './shell-execution';
import { chipText, countNonEmptyLines } from './tool-renderers/chip';
import { buildGoalToolHeader, isGoalToolName, parseGoalToolOutput } from './tool-renderers/goal';
import { searchNoticeOnly } from './tool-renderers/grep-output';
import { parseReadMediaOutput } from './tool-renderers/media';
import { formatReadMediaChip, parseReadMediaOutput } from './tool-renderers/media';
import { nonEmptyLines, outcomeLine, outcomeRows } from './tool-renderers/outcome';
import { TruncatedOutputComponent, trimTrailingEmptyLines } from './tool-renderers/truncated';
import { CardOnly, isSpilledToolOutput } from './tool-renderers/types';
Expand Down Expand Up @@ -135,6 +135,10 @@ export interface ToolCallReadSnapshot {
readonly filePath: string | undefined;
readonly phase: 'pending' | 'done' | 'failed';
readonly lines: number;
readonly mediaKind?: 'image' | 'video';
readonly mediaChip?: string;
readonly mediaUrl?: string;
readonly errorOutput?: string;
}

function backgroundFailureMessage(
Expand Down Expand Up @@ -1252,7 +1256,25 @@ export class ToolCallComponent extends Container {
return { toolCallId: this.toolCall.id, filePath, phase: 'pending', lines: 0 };
}
if (this.result.is_error === true) {
return { toolCallId: this.toolCall.id, filePath, phase: 'failed', lines: 0 };
return {
toolCallId: this.toolCall.id,
filePath,
phase: 'failed',
lines: 0,
errorOutput: this.result.output,
};
}
const media = parseReadMediaOutput(this.result.output);
if (media !== null) {
return {
toolCallId: this.toolCall.id,
filePath,
phase: 'done',
lines: 0,
mediaKind: media.kind,
mediaChip: formatReadMediaChip(media),
mediaUrl: media.url,
};
}
return {
toolCallId: this.toolCall.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ToolCallBlockData, ToolResultBlockData } from '#/tui/types';

import { goalStatusChip } from './goal';
import { parseGlobOutput, parseGrepOutput, searchNoticeOnly } from './grep-output';
import { readMediaChip } from './media';
import { formatReadMediaChip, parseReadMediaOutput, readMediaChip } from './media';
import { nonEmptyLines } from './outcome';
import { isSpilledToolOutput, strArg, stripSpillPointer } from './types';
import { waitForChip } from './wait-for';
Expand Down Expand Up @@ -77,8 +77,13 @@ const editChip: ChipProvider = (toolCall) => {

const writeChip: ChipProvider = (toolCall) => formatWriteChip(computeWriteStats(toolCall.args));

const readChip: ChipProvider = (_toolCall, result) =>
pluralize(nonEmptyLines(result.output).length, 'line');
const readChip: ChipProvider = (_toolCall, result) => {
if (!result.is_error) {
const media = parseReadMediaOutput(result.output);
if (media !== null) return formatReadMediaChip(media);
}
return pluralize(nonEmptyLines(result.output).length, 'line');
};

const bashChip: ChipProvider = (_toolCall, result) => {
if (result.is_error === true) return '';
Expand Down
27 changes: 19 additions & 8 deletions apps/kimi-code/src/tui/components/messages/tool-renderers/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,25 @@ function metaSegments(summary: ReadMediaSummary): string[] {
return segs;
}

export const readMediaChip: ChipProvider = (_toolCall, result) => {
if (result.is_error) return '';
const summary = parseReadMediaOutput(result.output);
if (summary === null) return '';
export function formatReadMediaChip(summary: ReadMediaSummary): string {
const meta = metaSegments(summary);
if (meta.length === 0) {
return summary.url !== undefined ? `${summary.kind} · uploaded` : summary.kind;
}
return `${summary.kind} (${meta.join(', ')})`;
};
}

export const readMediaSummary: ResultRenderer = (toolCall, result, ctx) => {
if (result.is_error) return renderTruncated(toolCall, result, ctx);
export const readMediaChip: ChipProvider = (_toolCall, result) => {
if (result.is_error) return '';
const summary = parseReadMediaOutput(result.output);
if (summary === null) return renderTruncated(toolCall, result, ctx);
if (summary === null) return '';
return formatReadMediaChip(summary);
};

export function renderReadMediaSummary(
summary: ReadMediaSummary,
ctx: Parameters<ResultRenderer>[2],
): Component[] {
if (!ctx.expanded) return [];

const dim = (text: string): string => currentTheme.dim(text);
Expand All @@ -126,4 +130,11 @@ export const readMediaSummary: ResultRenderer = (toolCall, result, ctx) => {
if (summary.url !== undefined) tail.push(summary.url);
out.push(new Text(` ${dim(tail.join(' · '))}`, 0, 0));
return out;
}

export const readMediaSummary: ResultRenderer = (toolCall, result, ctx) => {
if (result.is_error) return renderTruncated(toolCall, result, ctx);
const summary = parseReadMediaOutput(result.output);
if (summary === null) return renderTruncated(toolCall, result, ctx);
return renderReadMediaSummary(summary, ctx);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { OUTCOME_GLANCE_SAMPLES, OUTCOME_ROW_INDENT } from '#/tui/constant/rende
import { currentTheme } from '#/tui/theme';

import { parseGlobOutput, parseGrepOutput, searchNoticeOnly } from './grep-output';
import { parseReadMediaOutput, renderReadMediaSummary } from './media';
import { outcomeRow, outcomeRows } from './outcome';
import { renderTruncated } from './truncated';
import { CardOnly, isSpilledToolOutput, type ResultRenderer } from './types';
Expand Down Expand Up @@ -63,7 +64,14 @@ const globGlance: GlanceFn = (toolCall, result) => {
return sampleList(parseGlobOutput(result.output).entries);
};

export const readSummary: ResultRenderer = withGlance(null);
const textReadSummary: ResultRenderer = withGlance(null);
export const readSummary: ResultRenderer = (toolCall, result, ctx) => {
if (!result.is_error) {
const media = parseReadMediaOutput(result.output);
if (media !== null) return renderReadMediaSummary(media, ctx);
}
return textReadSummary(toolCall, result, ctx);
};
export const fetchSummary: ResultRenderer = withGlance(null);
export const webSearchSummary: ResultRenderer = withGlance(null);
export const thinkSummary: ResultRenderer = withGlance(null);
Expand Down
2 changes: 1 addition & 1 deletion apps/kimi-code/src/tui/utils/image-placeholder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,5 +602,5 @@ function originalImageTempDir(): string {
}

function formatMediaReference(kind: 'image' | 'video', path: string): string {
return `Attached ${kind} file: ${path} (open it with ReadMediaFile)`;
return `Attached ${kind} file: ${path} (open it with Read)`;
}
4 changes: 4 additions & 0 deletions apps/kimi-code/src/tui/utils/transcript-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ function toolStat(component: ToolCallComponent, event: SummaryEvent): ItemStat |
: { kind: 'diff', added: event.added, removed: event.removed };
}
const toolCall = component.toolCallView;
if (toolCall.name === 'Read') {
const mediaChip = component.getReadSnapshot().mediaChip;
return mediaChip === undefined ? undefined : { kind: 'note', text: mediaChip };
}
if (LINE_COUNT_CHIP_TOOLS.has(toolCall.name)) return undefined;
const text = chipText(toolCall, result);
return text.length === 0 ? undefined : { kind: 'note', text };
Expand Down
49 changes: 49 additions & 0 deletions apps/kimi-code/test/tui/components/messages/read-group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@ function rows(group: ReadGroupComponent, width: number): string[] {
return group.render(width).map(strip).filter((line) => line.trim().length > 0);
}

function mediaReadCall(
id: string,
path: string,
kind: 'image' | 'video',
url = 'kimi-file://f_media_1',
): ToolCallComponent {
const part =
kind === 'image'
? { type: 'image_url', imageUrl: { url } }
: { type: 'video_url', videoUrl: { url } };
return new ToolCallComponent(
{ id, name: 'Read', args: { path } },
{
tool_call_id: id,
output: JSON.stringify([
{ type: 'text', text: `<${kind} path="${path}">` },
part,
{ type: 'text', text: `</${kind}>` },
]),
is_error: false,
},
);
}

describe('ReadGroupComponent', () => {
it('collapses to a single header row and hides the per-file body until expanded', () => {
const group = makeGroup();
Expand All @@ -49,6 +73,31 @@ describe('ReadGroupComponent', () => {
expect(rows(group, 100)).toHaveLength(1);
});

it('describes parallel media and mixed text/media Read calls instead of counting JSON as 1 line', () => {
const mediaGroup = new ReadGroupComponent(undefined);
mediaGroup.attach('m1', mediaReadCall('m1', 'shots/before.png', 'image'));
mediaGroup.attach('m2', mediaReadCall('m2', 'shots/after.png', 'image'));

expect(rows(mediaGroup, 100)[0]).toContain('Read 2 files · 2 images');
expect(rows(mediaGroup, 100)[0]).not.toContain('lines');
mediaGroup.setExpanded(true);
const mediaBody = rows(mediaGroup, 100).join('\n');
expect(mediaBody).toContain('shots/before.png · image · uploaded');
expect(mediaBody).toContain('shots/after.png · image · uploaded');

const mixedGroup = new ReadGroupComponent(undefined);
mixedGroup.attach('t1', readCall('t1', 'src/Card.tsx', 120));
mixedGroup.attach('m3', mediaReadCall('m3', 'shots/design.png', 'image'));
mixedGroup.attach('v1', mediaReadCall('v1', 'shots/demo.mp4', 'video'));
mixedGroup.setExpanded(true);

const mixedRows = rows(mixedGroup, 100);
expect(mixedRows[0]).toContain('Read 3 files · 120 lines, 1 image, 1 video');
expect(mixedRows.join('\n')).toContain('src/Card.tsx · 120 lines');
expect(mixedRows.join('\n')).toContain('shots/design.png · image · uploaded');
expect(mixedRows.join('\n')).toContain('shots/demo.mp4 · video · uploaded');
});

it('truncates the header to the terminal width instead of wrapping', () => {
const group = makeGroup();
for (const width of [16, 24]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { Component } from '@moonshot-ai/pi-tui';
import { describe, expect, it } from 'vitest';

import { chipText } from '#/tui/components/messages/tool-renderers/chip';
import {
parseReadMediaOutput,
readMediaChip,
readMediaSummary,
} from '#/tui/components/messages/tool-renderers/media';
import { pickResultRenderer } from '#/tui/components/messages/tool-renderers/registry';
import { darkColors } from '#/tui/theme/colors';
import type { ToolCallBlockData, ToolResultBlockData } from '#/tui/types';

Expand Down Expand Up @@ -152,4 +154,21 @@ describe('readMediaSummary renderer', () => {
);
expect(out).toContain('some plain string output');
});

it('routes Read media outputs through media chip and summary while keeping text Read line counts', () => {
const mediaChip = strip(chipText(call('Read', { path: '/tmp/a.png' }), result(imageOutput('/tmp/a.png'))));
expect(mediaChip).toContain('image');
expect(mediaChip).toContain('image/png');

const textChip = strip(chipText(call('Read', { path: '/tmp/a.txt' }), result('1\thello\n2\tworld')));
expect(textChip).toBe('2 lines');

const expandedMedia = strip(
joinRender(
pickResultRenderer('Read')(call('Read', { path: '/tmp/a.png' }), result(imageOutput('/tmp/a.png')), expandedCtx),
),
);
expect(expandedMedia).toContain('/tmp/a.png');
expect(expandedMedia).not.toContain(PNG_B64);
});
});
Loading
Loading