fix: 展示真实文件编辑事件

This commit is contained in:
root
2026-07-12 18:06:39 +02:00
parent b687d133b5
commit 89ef9cdbfb
5 changed files with 159 additions and 4 deletions
+49 -2
View File
@@ -68,6 +68,10 @@ export function traceDisplayRows(trace: Record<string, unknown> = {}, events: Tr
rows.push(traceToolCallRow(event, displayOptions));
continue;
}
if (isDiffTraceEvent(event)) {
rows.push(traceDiffRow(event, displayOptions));
continue;
}
if (isRequestTraceEvent(event)) {
continue;
}
@@ -245,7 +249,7 @@ function traceToolCallRow(event: TraceEvent, options: ResolvedTraceDisplayRowsOp
const command = cleanShellCommand(event.command);
const toolState = traceToolState(event);
const toolName = traceToolName(event, command);
const body = traceToolCallBody(event, command);
const body = isFileChangeTraceEvent(event) ? traceFileChangeBody(event) : traceToolCallBody(event, command);
const eventKey = traceEventIdentityToken(event, options.sequenceAuthority);
return {
rowId: `tool:${event.itemId ?? eventKey ?? `${event.label ?? event.type ?? "tool"}:${event.createdAt ?? "unknown"}`}`,
@@ -256,7 +260,50 @@ function traceToolCallRow(event: TraceEvent, options: ResolvedTraceDisplayRowsOp
statusLabel: traceToolStatusLabel(toolState),
header: traceEventClock(event, options),
body,
preview: traceToolPreview(command, toolName),
preview: isFileChangeTraceEvent(event) ? traceFileChangePreview(event) : traceToolPreview(command, toolName),
bodyFormat: "text"
};
}
function isFileChangeTraceEvent(event: TraceEvent): boolean {
return nonEmptyString(event.toolName ?? event.toolType) === "fileChange";
}
function traceFileChangePreview(event: TraceEvent): string {
const paths = (Array.isArray(event.changes) ? event.changes : [])
.filter(isRecord)
.map((change) => nonEmptyString(change.path))
.filter((path): path is string => Boolean(path));
return compactTraceOneLine(paths.length > 0 ? `fileChange ${paths.join(", ")}` : "fileChange", 140);
}
function traceFileChangeBody(event: TraceEvent): string | null {
const changes = (Array.isArray(event.changes) ? event.changes : []).filter(isRecord);
if (changes.length === 0) return null;
return changes.map((change) => {
const path = nonEmptyString(change.path) ?? "(path missing)";
const kind = nonEmptyString(change.kind) ?? "update";
const diff = nonEmptyString(change.diff) ?? "";
return [`path: ${path}`, `kind: ${kind}`, "diff:", diff].filter(Boolean).join("\n");
}).join("\n\n");
}
function isDiffTraceEvent(event: TraceEvent): boolean {
return event.type === "diff" || event.eventType === "diff" || nonEmptyString(event.label) === "agentrun:diff";
}
function traceDiffRow(event: TraceEvent, options: ResolvedTraceDisplayRowsOptions): TraceEventRow {
const eventKey = traceEventIdentityToken(event, options.sequenceAuthority);
return {
rowId: `tool:diff:${eventKey ?? event.createdAt ?? "updated"}`,
seq: traceEventDisplaySeq(event, options.sequenceAuthority),
sequenceAuthority: options.sequenceAuthority,
tone: traceEventTone(event),
toolState: "success",
statusLabel: "文件 diff 已更新",
header: traceEventClock(event, options),
body: nonEmptyString(event.diff ?? event.message),
preview: "turn/diff/updated",
bodyFormat: "text"
};
}