Skip to content

Commit 8dc4265

Browse files
fix: keep long sessions responsive in session view (anomalyco#605)
1 parent c4b21fd commit 8dc4265

4 files changed

Lines changed: 62 additions & 33 deletions

File tree

‎packages/app/src/app/app.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,10 @@ export default function App() {
686686
setPendingPermissions,
687687
} = sessionStore;
688688

689-
const artifacts = createMemo(() => deriveArtifacts(messages()));
689+
const ARTIFACT_SCAN_MESSAGE_WINDOW = 220;
690+
const artifacts = createMemo(() =>
691+
deriveArtifacts(messages(), { maxMessages: ARTIFACT_SCAN_MESSAGE_WINDOW }),
692+
);
690693
const workingFiles = createMemo(() => deriveWorkingFiles(artifacts()));
691694
const activeSessionId = createMemo(() => selectedSessionId());
692695
const activeSessions = createMemo(() => sessions());

‎packages/app/src/app/components/session/message-list.tsx‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Part } from "@opencode-ai/sdk/v2/client";
44
import { Check, ChevronDown, ChevronRight, Copy, Eye, File, FileEdit, FolderSearch, Pencil, Search, Sparkles, Terminal } from "lucide-solid";
55

66
import type { MessageGroup, MessageWithParts } from "../../types";
7-
import { classifyTool, groupMessageParts, summarizeStep } from "../../utils";
7+
import { groupMessageParts, summarizeStep } from "../../utils";
88
import PartView from "../part-view";
99

1010
export type MessageListProps = {
@@ -242,21 +242,9 @@ export default function MessageList(props: MessageListProps) {
242242

243243
/** Compact single-line step row */
244244
const StepRow = (rowProps: { part: Part; isUser: boolean }) => {
245-
const summary = () => summarizeStep(rowProps.part);
246-
const category = () => {
247-
if (rowProps.part.type === "tool") {
248-
const toolName = (rowProps.part as any).tool ? String((rowProps.part as any).tool) : "";
249-
return classifyTool(toolName);
250-
}
251-
return "tool";
252-
};
253-
const status = () => {
254-
if (rowProps.part.type === "tool") {
255-
const state = (rowProps.part as any).state ?? {};
256-
return state.status ? String(state.status) : undefined;
257-
}
258-
return undefined;
259-
};
245+
const summary = createMemo(() => summarizeStep(rowProps.part));
246+
const category = createMemo(() => summary().toolCategory ?? "tool");
247+
const status = createMemo(() => summary().status);
260248

261249
return (
262250
<div class="flex items-center gap-2.5 py-1.5 min-h-[28px] group/step">

‎packages/app/src/app/pages/session.tsx‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ const SOUL_SETUP_TEMPLATE = (() => {
223223
})();
224224

225225
const INITIAL_MESSAGE_WINDOW = 140;
226+
const MESSAGE_WINDOW_LOAD_CHUNK = 120;
226227

227228
export default function SessionView(props: SessionViewProps) {
228229
let messagesEndEl: HTMLDivElement | undefined;
@@ -382,6 +383,22 @@ export default function SessionView(props: SessionViewProps) {
382383
return hidden > 0 ? hidden : 0;
383384
});
384385

386+
const nextRevealCount = createMemo(() => {
387+
const hidden = hiddenMessageCount();
388+
if (hidden <= 0) return 0;
389+
return Math.min(hidden, MESSAGE_WINDOW_LOAD_CHUNK);
390+
});
391+
392+
const revealEarlierMessages = () => {
393+
const hidden = hiddenMessageCount();
394+
if (hidden <= 0) return;
395+
const nextStart = Math.max(0, messageWindowStart() - MESSAGE_WINDOW_LOAD_CHUNK);
396+
setMessageWindowStart(nextStart);
397+
if (nextStart === 0) {
398+
setMessageWindowExpanded(true);
399+
}
400+
};
401+
385402
const canUndoLastMessage = createMemo(() => {
386403
if (!props.selectedSessionId) return false;
387404
const revert = props.sessionRevertMessageId;
@@ -2424,13 +2441,10 @@ export default function SessionView(props: SessionViewProps) {
24242441
<button
24252442
type="button"
24262443
class="rounded-full border border-dls-border bg-dls-hover/70 px-3 py-1 text-xs text-dls-secondary transition-colors hover:bg-dls-active hover:text-dls-text"
2427-
onClick={() => {
2428-
setMessageWindowExpanded(true);
2429-
setMessageWindowStart(0);
2430-
}}
2444+
onClick={revealEarlierMessages}
24312445
>
2432-
Show {hiddenMessageCount().toLocaleString()} earlier message
2433-
{hiddenMessageCount() === 1 ? "" : "s"}
2446+
Show {nextRevealCount().toLocaleString()} earlier message
2447+
{nextRevealCount() === 1 ? "" : "s"}
24342448
</button>
24352449
</div>
24362450
</Show>

‎packages/app/src/app/utils/index.ts‎

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,12 @@ function buildToolDetail(state: any, toolName: string): string | undefined {
743743
}
744744

745745
// For completed tools with output, show a very short summary
746-
const output = typeof state?.output === "string" && state.output.trim() ? state.output.trim() : null;
747-
if (output) {
746+
const outputRaw = typeof state?.output === "string" ? state.output.trim() : "";
747+
if (outputRaw) {
748748
if (lower === "read") return undefined;
749749

750+
const output = outputRaw.length > 3000 ? outputRaw.slice(0, 3000) : outputRaw;
751+
750752
// Extract just the first meaningful line (skip line numbers and raw file markers)
751753
const lines = output.split("\n").filter((l: string) => {
752754
const trimmed = l.trim();
@@ -776,6 +778,15 @@ function buildToolDetail(state: any, toolName: string): string | undefined {
776778
return undefined;
777779
}
778780

781+
const ARTIFACT_PATH_PATTERN =
782+
/(?:^|[\s"'`([{])((?:[a-zA-Z]:[/\\]|\.{1,2}[/\\]|~[/\\]|[/\\])[\w./\\\-]*\.[a-z][a-z0-9]{0,9}|[\w.\-]+[/\\][\w./\\\-]*\.[a-z][a-z0-9]{0,9})/gi;
783+
const ARTIFACT_OUTPUT_SCAN_LIMIT = 4000;
784+
const ARTIFACT_OUTPUT_SKIP_TOOLS = new Set(["webfetch"]);
785+
786+
type DeriveArtifactsOptions = {
787+
maxMessages?: number;
788+
};
789+
779790
export function summarizeStep(part: Part): { title: string; detail?: string; isSkill?: boolean; skillName?: string; toolCategory?: string; status?: string } {
780791
if (part.type === "tool") {
781792
const record = part as any;
@@ -817,10 +828,15 @@ export function summarizeStep(part: Part): { title: string; detail?: string; isS
817828
return { title: "Step", toolCategory: "tool" };
818829
}
819830

820-
export function deriveArtifacts(list: MessageWithParts[]): ArtifactItem[] {
831+
export function deriveArtifacts(list: MessageWithParts[], options: DeriveArtifactsOptions = {}): ArtifactItem[] {
821832
const results = new Map<string, ArtifactItem>();
833+
const maxMessages =
834+
typeof options.maxMessages === "number" && Number.isFinite(options.maxMessages) && options.maxMessages > 0
835+
? Math.floor(options.maxMessages)
836+
: null;
837+
const source = maxMessages && list.length > maxMessages ? list.slice(list.length - maxMessages) : list;
822838

823-
list.forEach((message) => {
839+
source.forEach((message) => {
824840
const messageId = String((message.info as any)?.id ?? "");
825841

826842
message.parts.forEach((part) => {
@@ -849,15 +865,23 @@ export function deriveArtifacts(list: MessageWithParts[]): ArtifactItem[] {
849865
}
850866
});
851867

852-
const text = [state.title, state.output]
853-
.filter((v): v is string => typeof v === "string")
868+
const toolName =
869+
typeof record.tool === "string" && record.tool.trim()
870+
? record.tool.trim().toLowerCase()
871+
: "";
872+
const titleText = typeof state.title === "string" ? state.title : "";
873+
const outputText =
874+
typeof state.output === "string" && !ARTIFACT_OUTPUT_SKIP_TOOLS.has(toolName)
875+
? state.output.slice(0, ARTIFACT_OUTPUT_SCAN_LIMIT)
876+
: "";
877+
878+
const text = [titleText, outputText]
879+
.filter((v): v is string => Boolean(v))
854880
.join(" ");
855881

856882
if (text) {
857-
const pathPattern =
858-
/(?:^|[\s"'`([{])((?:[a-zA-Z]:[/\\]|\.{1,2}[/\\]|~[/\\]|[/\\])[\w./\\\-]*\.[a-z][a-z0-9]{0,9}|[\w.\-]+[/\\][\w./\\\-]*\.[a-z][a-z0-9]{0,9})/gi;
859-
860-
Array.from(text.matchAll(pathPattern))
883+
ARTIFACT_PATH_PATTERN.lastIndex = 0;
884+
Array.from(text.matchAll(ARTIFACT_PATH_PATTERN))
861885
.map((m) => m[1])
862886
.filter((f) => f && f.length <= 500)
863887
.forEach((f) => matches.add(f));

0 commit comments

Comments
 (0)