Skip to content

Commit 096ec60

Browse files
committed
🤖 fix: lint errors and streaming aggregator logic
Change-Id: I10704b13805f557664038ffd2c619158b1556318 Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent 897d35f commit 096ec60

File tree

6 files changed

+27
-32
lines changed

6 files changed

+27
-32
lines changed

src/browser/components/ChatInput/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import {
5757

5858
import type { ThinkingLevel } from "@/common/types/thinking";
5959
import type { MuxFrontendMetadata } from "@/common/types/message";
60-
import { useWorkspaceStoreRaw } from "@/browser/stores/WorkspaceStore";
6160
import { useTelemetry } from "@/browser/hooks/useTelemetry";
6261
import { setTelemetryEnabled } from "@/common/telemetry";
6362
import { getTokenCountPromise } from "@/browser/utils/tokenizer/rendererClient";
@@ -143,7 +142,6 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
143142
const [mode, setMode] = useMode();
144143
const { recentModels, addModel, evictModel } = useModelLRU();
145144
const commandListId = useId();
146-
const workspaceStore = useWorkspaceStoreRaw();
147145
const telemetry = useTelemetry();
148146
const [vimEnabled, setVimEnabled] = usePersistedState<boolean>(VIM_ENABLED_KEY, false, {
149147
listener: true,

src/browser/utils/messages/StreamingMessageAggregator.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ describe("StreamingMessageAggregator", () => {
407407
scriptName: "demo",
408408
args: ["--flag"],
409409
result: BASE_SCRIPT_RESULT,
410-
}
410+
},
411411
});
412-
412+
413413
aggregator.addMessage(scriptMessage);
414414

415415
const displayed = aggregator.getDisplayedMessages();
@@ -424,7 +424,7 @@ describe("StreamingMessageAggregator", () => {
424424

425425
test("removes script logs when history is truncated", () => {
426426
const aggregator = new StreamingMessageAggregator(TEST_CREATED_AT);
427-
427+
428428
const timestamp = Date.now();
429429
const scriptMessage = createMuxMessage("script-1", "user", "Run script", {
430430
historySequence: 1,
@@ -438,7 +438,7 @@ describe("StreamingMessageAggregator", () => {
438438
scriptName: "cleanup",
439439
args: [],
440440
result: BASE_SCRIPT_RESULT,
441-
}
441+
},
442442
});
443443

444444
aggregator.addMessage(scriptMessage);

src/browser/utils/messages/StreamingMessageAggregator.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
MuxMetadata,
44
MuxImagePart,
55
DisplayedMessage,
6-
MuxFrontendMetadata,
76
} from "@/common/types/message";
87
import { createMuxMessage } from "@/common/types/message";
98
import type {
@@ -17,7 +16,7 @@ import type {
1716
ReasoningDeltaEvent,
1817
ReasoningEndEvent,
1918
} from "@/common/types/stream";
20-
import type { TodoItem, StatusSetToolResult, BashToolResult } from "@/common/types/tools";
19+
import type { TodoItem, StatusSetToolResult } from "@/common/types/tools";
2120

2221
import type { WorkspaceChatMessage, StreamErrorMessage, DeleteMessage } from "@/common/types/ipc";
2322
import { isInitStart, isInitOutput, isInitEnd, isMuxMessage } from "@/common/types/ipc";
@@ -208,7 +207,7 @@ export class StreamingMessageAggregator {
208207
return;
209208
}
210209
}
211-
210+
212211
// Special handling for script execution messages to ensure correct type identification
213212
// If we receive a user message that has script metadata, we treat it as a script execution
214213
// This is redundant with getDisplayedMessages logic but good for consistency
@@ -735,14 +734,31 @@ export class StreamingMessageAggregator {
735734
*/
736735
getDisplayedMessages(): DisplayedMessage[] {
737736
if (!this.cachedDisplayedMessages) {
738-
let displayedMessages: DisplayedMessage[] = [];
737+
const displayedMessages: DisplayedMessage[] = [];
739738

740739
for (const message of this.getAllMessages()) {
741740
const baseTimestamp = message.metadata?.timestamp;
742741
// Get historySequence from backend (required field)
743742
const historySequence = message.metadata?.historySequence ?? 0;
744743

745-
if (message.role === "user") {
744+
if (
745+
message.metadata?.muxMetadata?.type === "script-execution" &&
746+
(message.role as string) === "user"
747+
) {
748+
// Script Execution Message
749+
// Type assertion: we know the metadata shape from the check above
750+
const scriptMeta = message.metadata.muxMetadata;
751+
displayedMessages.push({
752+
type: "script-execution",
753+
id: message.id,
754+
historySequence,
755+
timestamp: baseTimestamp ?? message.metadata.timestamp ?? Date.now(),
756+
command: scriptMeta.command,
757+
scriptName: scriptMeta.scriptName,
758+
args: scriptMeta.args,
759+
result: scriptMeta.result,
760+
});
761+
} else if (message.role === "user") {
746762
// User messages: combine all text parts into single block, extract images
747763
const content = message.parts
748764
.filter((p) => p.type === "text")
@@ -780,23 +796,6 @@ export class StreamingMessageAggregator {
780796
timestamp: baseTimestamp,
781797
compactionRequest,
782798
});
783-
} else if (
784-
message.metadata?.muxMetadata?.type === "script-execution" &&
785-
(message.role as string) === "user"
786-
) {
787-
// Script Execution Message
788-
// Type assertion: we know the metadata shape from the check above
789-
const scriptMeta = message.metadata.muxMetadata as Extract<MuxFrontendMetadata, { type: "script-execution" }>;
790-
displayedMessages.push({
791-
type: "script-execution",
792-
id: message.id,
793-
historySequence,
794-
timestamp: baseTimestamp ?? message.metadata.timestamp ?? Date.now(),
795-
command: scriptMeta.command,
796-
scriptName: scriptMeta.scriptName,
797-
args: scriptMeta.args,
798-
result: scriptMeta.result,
799-
});
800799
} else if (message.role === "assistant") {
801800
// Assistant messages: each part becomes a separate DisplayedMessage
802801
// Use streamSequence to order parts within this message
@@ -947,7 +946,6 @@ export class StreamingMessageAggregator {
947946
displayedMessages.unshift(initMessage);
948947
}
949948

950-
951949
// Limit to last N messages for DOM performance
952950
// Full history is still maintained internally for token counting
953951
if (displayedMessages.length > MAX_DISPLAYED_MESSAGES) {

src/browser/utils/messages/modelMessageTransform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export function transformScriptMessagesForLLM(messages: MuxMessage[]): MuxMessag
216216

217217
const scriptMeta = msg.metadata.muxMetadata;
218218
const exitCode = scriptMeta.result.exitCode;
219-
const output = scriptMeta.result.output || "(no output)";
219+
const output = scriptMeta.result.output ?? "(no output)";
220220

221221
// Construct a concise representation for the LLM
222222
const llmContent = `Script '${scriptMeta.scriptName}' executed (exit code ${exitCode}).\nStdout/Stderr:\n${output}`;

src/node/services/historyService.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { describe, it, expect, beforeEach, afterEach } from "bun:test";
22
import { HistoryService } from "./historyService";
33
import { Config } from "@/node/config";
44
import { createMuxMessage } from "@/common/types/message";
5-
import type { MuxFrontendMetadata } from "@/common/types/message";
65
import * as fs from "fs/promises";
76
import * as path from "path";
87
import * as os from "os";

src/node/services/partialService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { describe, test, expect, beforeEach, afterEach, mock } from "bun:test";
33
import { PartialService } from "./partialService";
44
import type { HistoryService } from "./historyService";
55
import { Config } from "@/node/config";
6-
import { createMuxMessage, type MuxMessage, type MuxFrontendMetadata } from "@/common/types/message";
6+
import { createMuxMessage, type MuxMessage } from "@/common/types/message";
77
import { Ok } from "@/common/types/result";
88
import * as fs from "fs/promises";
99
import * as path from "path";

0 commit comments

Comments
 (0)