Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ function runtimeEventToActivities(
kind: "tool.updated",
summary: event.payload.title ?? "Tool updated",
payload: {
...(event.itemId ? { itemId: event.itemId } : {}),
itemType: event.payload.itemType,
...(event.payload.status ? { status: event.payload.status } : {}),
...(event.payload.detail ? { detail: truncateDetail(event.payload.detail) } : {}),
Expand All @@ -463,8 +464,9 @@ function runtimeEventToActivities(
kind: "tool.completed",
summary: event.payload.title ?? "Tool",
payload: {
...(event.itemId ? { itemId: event.itemId } : {}),
itemType: event.payload.itemType,
...(event.payload.detail ? { detail: truncateDetail(event.payload.detail) } : {}),
...(event.payload.detail ? { detail: event.payload.detail } : {}),
},
turnId: toTurnId(event.turnId) ?? null,
...maybeSequence,
Expand All @@ -482,10 +484,11 @@ function runtimeEventToActivities(
createdAt: event.createdAt,
tone: "tool",
kind: "tool.started",
summary: `${event.payload.title ?? "Tool"} started`,
summary: event.payload.title ?? "Tool started",
payload: {
...(event.itemId ? { itemId: event.itemId } : {}),
itemType: event.payload.itemType,
...(event.payload.detail ? { detail: truncateDetail(event.payload.detail) } : {}),
...(event.payload.detail ? { detail: event.payload.detail } : {}),
},
turnId: toTurnId(event.turnId) ?? null,
...maybeSequence,
Expand Down
10 changes: 7 additions & 3 deletions apps/server/src/provider/Layers/CodexAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ function toCanonicalItemType(raw: unknown): CanonicalItemType {
return "unknown";
}

function itemTitle(itemType: CanonicalItemType): string | undefined {
function itemTitle(
itemType: CanonicalItemType,
started = false,
): string | undefined {
switch (itemType) {
case "assistant_message":
return "Assistant message";
Expand All @@ -224,7 +227,7 @@ function itemTitle(itemType: CanonicalItemType): string | undefined {
case "plan":
return "Plan";
case "command_execution":
return "Ran command";
return started ? "Running command" : "Ran command";
case "file_change":
return "File change";
case "mcp_tool_call":
Expand Down Expand Up @@ -562,14 +565,15 @@ function mapItemLifecycle(
: lifecycle === "item.completed"
? "completed"
: undefined;
const title = itemTitle(itemType, lifecycle === "item.started");

return {
...runtimeEventBase(event, canonicalThreadId),
type: lifecycle,
payload: {
itemType,
...(status ? { status } : {}),
...(itemTitle(itemType) ? { title: itemTitle(itemType) } : {}),
...(title ? { title } : {}),
...(detail ? { detail } : {}),
...(event.payload !== undefined ? { data: event.payload } : {}),
},
Expand Down
5 changes: 4 additions & 1 deletion apps/web/src/components/chat/MessagesTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ export const MessagesTimeline = memo(function MessagesTimeline({
)}
<div className="space-y-0.5">
{visibleEntries.map((workEntry) => (
<SimpleWorkEntryRow key={`work-row:${workEntry.id}`} workEntry={workEntry} />
<SimpleWorkEntryRow
key={`work-row:${workEntry.id}`}
workEntry={workEntry}
/>
))}
</div>
</div>
Expand Down
60 changes: 49 additions & 11 deletions apps/web/src/session-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export interface WorkLogEntry {
tone: "thinking" | "tool" | "info" | "error";
toolTitle?: string;
itemType?: ToolLifecycleItemType;
itemId?: string;
requestKind?: PendingApproval["requestKind"];
collapseKey?: string;
}

interface DerivedWorkLogEntry extends WorkLogEntry {
Expand Down Expand Up @@ -462,14 +464,13 @@ export function deriveWorkLogEntries(
const ordered = [...activities].toSorted(compareActivitiesByOrder);
const entries = ordered
.filter((activity) => (latestTurnId ? activity.turnId === latestTurnId : true))
.filter((activity) => activity.kind !== "tool.started")
.filter((activity) => activity.kind !== "task.started" && activity.kind !== "task.completed")
.filter((activity) => activity.kind !== "context-window.updated")
.filter((activity) => activity.summary !== "Checkpoint captured")
.filter((activity) => !isPlanBoundaryToolActivity(activity))
.map(toDerivedWorkLogEntry);
return collapseDerivedWorkLogEntries(entries).map(
({ activityKind: _activityKind, collapseKey: _collapseKey, ...entry }) => entry,
({ activityKind: _activityKind, ...entry }) => entry,
);
}

Expand Down Expand Up @@ -501,6 +502,7 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
activityKind: activity.kind,
};
const itemType = extractWorkLogItemType(payload);
const itemId = extractWorkLogItemId(payload);
const requestKind = extractWorkLogRequestKind(payload);
if (payload && typeof payload.detail === "string" && payload.detail.length > 0) {
const detail = stripTrailingExitCode(payload.detail).output;
Expand All @@ -523,6 +525,9 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
if (itemType) {
entry.itemType = itemType;
}
if (itemId) {
entry.itemId = itemId;
}
if (requestKind) {
entry.requestKind = requestKind;
}
Expand All @@ -537,13 +542,28 @@ function collapseDerivedWorkLogEntries(
entries: ReadonlyArray<DerivedWorkLogEntry>,
): DerivedWorkLogEntry[] {
const collapsed: DerivedWorkLogEntry[] = [];
const openLifecycleRowIndexByCollapseKey = new Map<string, number>();
for (const entry of entries) {
const previous = collapsed.at(-1);
if (previous && shouldCollapseToolLifecycleEntries(previous, entry)) {
collapsed[collapsed.length - 1] = mergeDerivedWorkLogEntries(previous, entry);
continue;
const collapseKey = entry.collapseKey;
if (collapseKey) {
const openIndex = openLifecycleRowIndexByCollapseKey.get(collapseKey);
if (openIndex !== undefined) {
const previous = collapsed[openIndex];
if (previous && shouldCollapseToolLifecycleEntries(previous, entry)) {
collapsed[openIndex] = mergeDerivedWorkLogEntries(previous, entry);
if (entry.activityKind === "tool.completed") {
openLifecycleRowIndexByCollapseKey.delete(collapseKey);
}
continue;
}
}
}

collapsed.push(entry);
if (collapseKey && (entry.activityKind === "tool.started" || entry.activityKind === "tool.updated")) {
openLifecycleRowIndexByCollapseKey.set(collapseKey, collapsed.length - 1);
continue;
}
}
return collapsed;
}
Expand All @@ -552,7 +572,11 @@ function shouldCollapseToolLifecycleEntries(
previous: DerivedWorkLogEntry,
next: DerivedWorkLogEntry,
): boolean {
if (previous.activityKind !== "tool.updated" && previous.activityKind !== "tool.completed") {
if (
previous.activityKind !== "tool.started" &&
previous.activityKind !== "tool.updated" &&
previous.activityKind !== "tool.completed"
) {
return false;
}
if (next.activityKind !== "tool.updated" && next.activityKind !== "tool.completed") {
Expand All @@ -579,6 +603,8 @@ function mergeDerivedWorkLogEntries(
return {
...previous,
...next,
id: previous.id,
createdAt: previous.createdAt,
...(detail ? { detail } : {}),
...(command ? { command } : {}),
...(rawCommand ? { rawCommand } : {}),
Expand All @@ -602,16 +628,24 @@ function mergeChangedFiles(
}

function deriveToolLifecycleCollapseKey(entry: DerivedWorkLogEntry): string | undefined {
if (entry.activityKind !== "tool.updated" && entry.activityKind !== "tool.completed") {
if (
entry.activityKind !== "tool.started" &&
entry.activityKind !== "tool.updated" &&
entry.activityKind !== "tool.completed"
) {
return undefined;
}
const itemId = entry.itemId?.trim() ?? "";
if (itemId.length > 0) {
return itemId;
}
const normalizedLabel = normalizeCompactToolLabel(entry.toolTitle ?? entry.label);
const detail = entry.detail?.trim() ?? "";
const commandOrDetail = (entry.command ?? entry.detail)?.trim() ?? "";
const itemType = entry.itemType ?? "";
if (normalizedLabel.length === 0 && detail.length === 0 && itemType.length === 0) {
if (normalizedLabel.length === 0 && commandOrDetail.length === 0 && itemType.length === 0) {
return undefined;
}
return [itemType, normalizedLabel, detail].join("\u001f");
return [itemType, normalizedLabel, commandOrDetail].join("\u001f");
}

function normalizeCompactToolLabel(value: string): string {
Expand Down Expand Up @@ -855,6 +889,10 @@ function extractWorkLogItemType(
return undefined;
}

function extractWorkLogItemId(payload: Record<string, unknown> | null): string | undefined {
return typeof payload?.itemId === "string" && payload.itemId.length > 0 ? payload.itemId : undefined;
}

function extractWorkLogRequestKind(
payload: Record<string, unknown> | null,
): WorkLogEntry["requestKind"] | undefined {
Expand Down
Loading