Skip to content

Commit 05d4802

Browse files
committed
🤖 fix: resolve circular deps and lint errors by extracting workspace events
1 parent ad10d31 commit 05d4802

File tree

4 files changed

+49
-29
lines changed

4 files changed

+49
-29
lines changed

‎src/browser/App.tsx‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { buildCoreSources, type BuildSourcesParams } from "./utils/commands/sour
2828

2929
import type { ThinkingLevel } from "@/common/types/thinking";
3030
import { CUSTOM_EVENTS } from "@/common/constants/events";
31-
import { isWorkspaceForkSwitchEvent } from "./utils/chatCommands";
31+
import { isWorkspaceForkSwitchEvent } from "./utils/workspaceEvents";
3232
import { getThinkingLevelKey } from "@/common/constants/storage";
3333
import type { BranchListResult } from "@/common/types/ipc";
3434
import { useTelemetry } from "./hooks/useTelemetry";
@@ -530,8 +530,6 @@ function AppInner() {
530530
return (
531531
<>
532532
<div className="bg-bg-dark mobile-layout flex h-screen overflow-hidden">
533-
534-
535533
<LeftSidebar
536534
lastReadTimestamps={lastReadTimestamps}
537535
onToggleUnread={onToggleUnread}

‎src/browser/components/ChatInput/index.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
489489
};
490490

491491
const result = await processSlashCommand(parsed, context);
492-
492+
493493
if (!result.clearInput) {
494494
setInput(messageText); // Restore input on failure
495495
}

‎src/browser/utils/chatCommands.ts‎

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type { Toast } from "@/browser/components/ChatInputToast";
1616
import type { ParsedCommand } from "@/browser/utils/slashCommands/types";
1717
import { applyCompactionOverrides } from "@/browser/utils/messages/compactionOptions";
1818
import { resolveCompactionModel } from "@/browser/utils/messages/compactionModelPreference";
19+
import { dispatchWorkspaceSwitch } from "./workspaceEvents";
1920
import { getRuntimeKey, copyWorkspaceStorage } from "@/common/constants/storage";
2021

2122
// ============================================================================
@@ -110,7 +111,15 @@ export async function processSlashCommand(
110111
context: SlashCommandContext
111112
): Promise<CommandHandlerResult> {
112113
if (!parsed) return { clearInput: false, toastShown: false };
113-
const { setInput, setIsSending, setToast, variant, setVimEnabled, setPreferredModel, onModelChange } = context;
114+
const {
115+
setInput,
116+
setIsSending,
117+
setToast,
118+
variant,
119+
setVimEnabled,
120+
setPreferredModel,
121+
onModelChange,
122+
} = context;
114123

115124
// 1. Global Commands
116125
if (parsed.type === "providers-set") {
@@ -178,7 +187,7 @@ export async function processSlashCommand(
178187
const workspaceCommands = ["clear", "truncate", "compact", "fork", "new"];
179188
const isWorkspaceCommand = workspaceCommands.includes(parsed.type);
180189

181-
if (isWorkspaceCommand) {
190+
if (isWorkspaceCommand) {
182191
if (variant !== "workspace") {
183192
setToast({
184193
id: Date.now().toString(),
@@ -197,12 +206,18 @@ export async function processSlashCommand(
197206
case "compact":
198207
// handleCompactCommand expects workspaceId in context
199208
if (!context.workspaceId) throw new Error("Workspace ID required");
200-
return handleCompactCommand(parsed, { ...context, workspaceId: context.workspaceId } as CommandHandlerContext);
209+
return handleCompactCommand(parsed, {
210+
...context,
211+
workspaceId: context.workspaceId,
212+
} as CommandHandlerContext);
201213
case "fork":
202214
return handleForkCommand(parsed, context);
203215
case "new":
204216
if (!context.workspaceId) throw new Error("Workspace ID required");
205-
return handleNewCommand(parsed, { ...context, workspaceId: context.workspaceId } as CommandHandlerContext);
217+
return handleNewCommand(parsed, {
218+
...context,
219+
workspaceId: context.workspaceId,
220+
} as CommandHandlerContext);
206221
}
207222
}
208223

@@ -225,10 +240,10 @@ async function handleClearCommand(
225240
context: SlashCommandContext
226241
): Promise<CommandHandlerResult> {
227242
const { setInput, onTruncateHistory, resetInputHeight, setToast } = context;
228-
243+
229244
setInput("");
230245
resetInputHeight();
231-
246+
232247
if (!onTruncateHistory) return { clearInput: true, toastShown: false };
233248

234249
try {
@@ -240,11 +255,12 @@ async function handleClearCommand(
240255
});
241256
return { clearInput: true, toastShown: true };
242257
} catch (error) {
243-
console.error("Failed to clear history:", error);
258+
const normalized = error instanceof Error ? error : new Error("Failed to clear history");
259+
console.error("Failed to clear history:", normalized);
244260
setToast({
245261
id: Date.now().toString(),
246262
type: "error",
247-
message: "Failed to clear history",
263+
message: normalized.message,
248264
});
249265
return { clearInput: false, toastShown: true };
250266
}
@@ -270,11 +286,12 @@ async function handleTruncateCommand(
270286
});
271287
return { clearInput: true, toastShown: true };
272288
} catch (error) {
273-
console.error("Failed to truncate history:", error);
289+
const normalized = error instanceof Error ? error : new Error("Failed to truncate history");
290+
console.error("Failed to truncate history:", normalized);
274291
setToast({
275292
id: Date.now().toString(),
276293
type: "error",
277-
message: "Failed to truncate history",
294+
message: normalized.message,
278295
});
279296
return { clearInput: false, toastShown: true };
280297
}
@@ -320,22 +337,20 @@ async function handleForkCommand(
320337
return { clearInput: true, toastShown: true };
321338
}
322339
} catch (error) {
323-
const errorMsg = error instanceof Error ? error.message : "Failed to fork workspace";
324-
console.error("Fork error:", error);
340+
const normalized = error instanceof Error ? error : new Error("Failed to fork workspace");
341+
console.error("Fork error:", normalized);
325342
setToast({
326343
id: Date.now().toString(),
327344
type: "error",
328345
title: "Fork Failed",
329-
message: errorMsg,
346+
message: normalized.message,
330347
});
331348
return { clearInput: false, toastShown: true };
332349
} finally {
333350
setIsSending(false);
334351
}
335352
}
336353

337-
338-
339354
/**
340355
* Parse runtime string from -r flag into RuntimeConfig for backend
341356
* Supports formats:
@@ -479,11 +494,9 @@ export function formatNewCommand(
479494
}
480495

481496
// ============================================================================
482-
// Workspace Forking (re-exported from workspaceFork for convenience)
497+
// Workspace Forking (Inline implementation)
483498
// ============================================================================
484499

485-
export { forkWorkspace };
486-
487500
// ============================================================================
488501
// Compaction
489502
// ============================================================================
@@ -772,10 +785,3 @@ export async function handleCompactCommand(
772785
/**
773786
* Dispatch a custom event to switch workspaces
774787
*/
775-
export function dispatchWorkspaceSwitch(workspaceInfo: FrontendWorkspaceMetadata): void {
776-
window.dispatchEvent(
777-
new CustomEvent(CUSTOM_EVENTS.WORKSPACE_FORK_SWITCH, {
778-
detail: workspaceInfo,
779-
})
780-
);
781-
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { CUSTOM_EVENTS } from "@/common/constants/events";
2+
import type { FrontendWorkspaceMetadata } from "@/common/types/workspace";
3+
4+
export function isWorkspaceForkSwitchEvent(
5+
event: Event
6+
): event is CustomEvent<FrontendWorkspaceMetadata> {
7+
return event.type === CUSTOM_EVENTS.WORKSPACE_FORK_SWITCH;
8+
}
9+
10+
export function dispatchWorkspaceSwitch(workspaceInfo: FrontendWorkspaceMetadata): void {
11+
window.dispatchEvent(
12+
new CustomEvent(CUSTOM_EVENTS.WORKSPACE_FORK_SWITCH, {
13+
detail: workspaceInfo,
14+
})
15+
);
16+
}

0 commit comments

Comments
 (0)