Skip to content

Commit 85b14ce

Browse files
restart engine when user switch workspace. fix issuse anomalyco#174 (anomalyco#177)
* Restarting engine when user switch workspace * feat(skills): add uninstall confirm * refactor: remove deprecated skill and publish files, streamline project structure * Enhance README with OpenWork features Added description about OpenWork's features and functionality. * feat(skills): refine add section * chore(release): bump version to 0.3.0 * style: update onboarding UI with new color scheme and logo sizes * feat: implement directory path normalization and enhance session filtering logic --------- Co-authored-by: Benjamin Shafii <[email protected]>
1 parent 71ebdd8 commit 85b14ce

9 files changed

Lines changed: 93 additions & 30 deletions

File tree

‎packages/desktop/src/app/components/onboarding-workspace-selector.tsx‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,23 @@ export default function OnboardingWorkspaceSelector(props: {
4949
};
5050

5151
return (
52-
<div class="bg-zinc-900 border border-zinc-800 w-full max-w-lg rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[90vh]">
52+
<div class="bg-gray-2 border border-gray-6 rounded-2xl overflow-hidden flex flex-col max-h-[90vh]">
5353
<div class="p-6 flex-1 overflow-y-auto space-y-8">
5454
<div class="space-y-4">
55-
<div class="flex items-center gap-3 text-sm font-medium text-white">
56-
<div class="w-6 h-6 rounded-full bg-zinc-800 flex items-center justify-center text-xs">1</div>
55+
<div class="flex items-center gap-3 text-sm font-medium text-gray-12">
56+
<div class="w-6 h-6 rounded-full bg-gray-4 flex items-center justify-center text-xs">1</div>
5757
Select Folder
5858
</div>
5959
<div class="ml-9">
6060
<div
61-
class={`w-full border border-dashed border-zinc-700 bg-zinc-900/50 rounded-xl p-4 text-left transition ${
61+
class={`w-full border border-dashed border-gray-6 bg-gray-1/40 rounded-xl p-4 text-left transition ${
6262
pickingFolder() ? "opacity-70" : "hover:border-zinc-500"
6363
}`.trim()}
6464
>
65-
<div class="flex items-center gap-3 text-zinc-200">
66-
<FolderPlus size={20} class="text-zinc-400" />
65+
<div class="flex items-center gap-3 text-gray-10">
66+
<FolderPlus size={20} class="text-gray-6" />
6767
<input
68-
class="flex-1 min-w-0 bg-transparent text-sm font-medium text-zinc-100 placeholder-zinc-600 focus:outline-none"
68+
class="flex-1 min-w-0 bg-transparent text-sm font-medium text-gray-10 placeholder-gray-600 focus:outline-none"
6969
value={selectedFolder()}
7070
onInput={(e) => setSelectedFolder(e.currentTarget.value)}
7171
placeholder={props.defaultPath}
@@ -74,7 +74,7 @@ export default function OnboardingWorkspaceSelector(props: {
7474
type="button"
7575
onClick={handlePickFolder}
7676
disabled={pickingFolder()}
77-
class="text-xs text-zinc-500 hover:text-zinc-200 transition-colors"
77+
class="text-xs text-gray-6 hover:text-gray-10 transition-colors"
7878
>
7979
<Show
8080
when={pickingFolder()}
@@ -92,8 +92,8 @@ export default function OnboardingWorkspaceSelector(props: {
9292
</div>
9393

9494
<div class="space-y-4">
95-
<div class="flex items-center gap-3 text-sm font-medium text-white">
96-
<div class="w-6 h-6 rounded-full bg-zinc-800 flex items-center justify-center text-xs">2</div>
95+
<div class="flex items-center gap-3 text-sm font-medium text-gray-12">
96+
<div class="w-6 h-6 rounded-full bg-gray-4 flex items-center justify-center text-xs">2</div>
9797
Choose Preset
9898
</div>
9999
<div class={`ml-9 grid gap-3 ${!canContinue() ? "opacity-50" : ""}`.trim()}>
@@ -106,8 +106,8 @@ export default function OnboardingWorkspaceSelector(props: {
106106
}}
107107
class={`p-4 rounded-xl border cursor-pointer transition-all ${
108108
preset() === opt.id
109-
? "bg-indigo-500/10 border-indigo-500/50"
110-
: "bg-zinc-900 border-zinc-800 hover:border-zinc-700"
109+
? "bg-gray-4 border-gray-6 hover:border-gray-7"
110+
: "bg-gray-1/40 border-gray-6 hover:border-gray-7"
111111
} ${!canContinue() ? "pointer-events-none" : ""}`.trim()}
112112
>
113113
<div class="flex justify-between items-start">

‎packages/desktop/src/app/context/session.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ import type {
1313
PlaceholderAssistantMessage,
1414
TodoItem,
1515
} from "../types";
16-
import { addOpencodeCacheHint, modelFromUserMessage, normalizeEvent, normalizeSessionStatus } from "../utils";
16+
import {
17+
addOpencodeCacheHint,
18+
modelFromUserMessage,
19+
normalizeDirectoryPath,
20+
normalizeEvent,
21+
normalizeSessionStatus,
22+
} from "../utils";
1723
import { unwrap } from "../lib/opencode";
1824

1925
export type SessionModelState = {
@@ -158,8 +164,10 @@ export function createSessionStore(options: {
158164
const c = options.client();
159165
if (!c) return;
160166
const list = unwrap(await c.session.list());
161-
const root = (scopeRoot ?? "").trim();
162-
const filtered = root ? list.filter((session) => session.directory === root) : list;
167+
const root = normalizeDirectoryPath(scopeRoot);
168+
const filtered = root
169+
? list.filter((session) => normalizeDirectoryPath(session.directory) === root)
170+
: list;
163171
setStore("sessions", reconcile(sortById(filtered), { key: "id" }));
164172
}
165173

‎packages/desktop/src/app/context/workspace.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ export function createWorkspaceStore(options: {
160160
const next = workspaces().find((w) => w.id === id) ?? null;
161161
if (!next) return;
162162

163+
const wasHostMode = options.mode() === "host" && options.client();
164+
const oldWorkspacePath = projectDir();
165+
const workspaceChanged = oldWorkspacePath !== next.path;
166+
163167
syncActiveWorkspaceId(id);
164168
setProjectDir(next.path);
165169

@@ -196,6 +200,48 @@ export function createWorkspaceStore(options: {
196200
}
197201

198202
await options.loadWorkspaceTemplates({ workspaceRoot: next.path }).catch(() => undefined);
203+
204+
if (workspaceChanged && options.client() && !wasHostMode) {
205+
options.setSelectedSessionId(null);
206+
options.setMessages([]);
207+
options.setTodos([]);
208+
options.setPendingPermissions([]);
209+
options.setSessionStatusById({});
210+
await options.loadSessions(next.path).catch(() => undefined);
211+
}
212+
213+
// In Host mode, restart the engine when workspace changes
214+
if (wasHostMode && workspaceChanged) {
215+
options.setError(null);
216+
options.setBusy(true);
217+
options.setBusyLabel("status.restarting_engine");
218+
options.setBusyStartedAt(Date.now());
219+
220+
try {
221+
// Stop the current engine
222+
const info = await engineStop();
223+
setEngine(info);
224+
225+
// Start engine with new workspace directory
226+
const newInfo = await engineStart(next.path, { preferSidecar: options.engineSource() === "sidecar" });
227+
setEngine(newInfo);
228+
229+
// Reconnect to server
230+
if (newInfo.baseUrl) {
231+
const ok = await connectToServer(newInfo.baseUrl, newInfo.projectDir ?? undefined);
232+
if (!ok) {
233+
options.setError("Failed to reconnect after workspace switch");
234+
}
235+
}
236+
} catch (e) {
237+
const message = e instanceof Error ? e.message : safeStringify(e);
238+
options.setError(addOpencodeCacheHint(message));
239+
} finally {
240+
options.setBusy(false);
241+
options.setBusyLabel(null);
242+
options.setBusyStartedAt(null);
243+
}
244+
}
199245
}
200246

201247
async function connectToServer(nextBaseUrl: string, directory?: string) {

‎packages/desktop/src/app/pages/dashboard.tsx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
} from "../types";
1010
import type { McpDirectoryInfo } from "../constants";
1111
import type { WorkspaceInfo } from "../lib/tauri";
12-
import { formatRelativeTime } from "../utils";
12+
import { formatRelativeTime, normalizeDirectoryPath } from "../utils";
1313

1414
import Button from "../components/button";
1515
import OpenWorkLogo from "../components/openwork-logo";
@@ -551,8 +551,9 @@ export default function DashboardView(props: DashboardViewProps) {
551551
</span>
552552
<Show
553553
when={
554-
props.activeWorkspaceRoot &&
555-
s.directory === props.activeWorkspaceRoot
554+
normalizeDirectoryPath(props.activeWorkspaceRoot) &&
555+
normalizeDirectoryPath(s.directory) ===
556+
normalizeDirectoryPath(props.activeWorkspaceRoot)
556557
}
557558
>
558559
<span class="text-[11px] px-2 py-0.5 rounded-full border border-gray-7/60 text-gray-10">
@@ -617,8 +618,9 @@ export default function DashboardView(props: DashboardViewProps) {
617618
</span>
618619
<Show
619620
when={
620-
props.activeWorkspaceRoot &&
621-
s.directory === props.activeWorkspaceRoot
621+
normalizeDirectoryPath(props.activeWorkspaceRoot) &&
622+
normalizeDirectoryPath(s.directory) ===
623+
normalizeDirectoryPath(props.activeWorkspaceRoot)
622624
}
623625
>
624626
<span class="text-[11px] px-2 py-0.5 rounded-full border border-gray-7/60 text-gray-10">

‎packages/desktop/src/app/pages/onboarding.tsx‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ export default function OnboardingView(props: OnboardingViewProps) {
9191
<div class="absolute inset-0 bg-[radial-gradient(circle_at_center,_var(--tw-gradient-stops))] from-gray-2 via-gray-1 to-gray-1 opacity-50" />
9292
<div class="z-10 flex flex-col items-center gap-6">
9393
<div class="relative">
94-
<div class="w-16 h-16 rounded-full border-2 border-gray-6 flex items-center justify-center animate-spin-slow">
95-
<div class="w-12 h-12 rounded-full border-2 border-t-gray-12 border-gray-6 animate-spin flex items-center justify-center bg-gray-1">
96-
<OpenWorkLogo size={20} class="text-gray-12" />
97-
</div>
98-
</div>
94+
<OpenWorkLogo size={40} />
9995
</div>
10096
<div class="text-center">
10197
<h2 class="text-xl font-medium mb-2">
@@ -118,8 +114,8 @@ export default function OnboardingView(props: OnboardingViewProps) {
118114

119115
<div class="max-w-lg w-full z-10 space-y-6">
120116
<div class="text-center space-y-2">
121-
<div class="w-12 h-12 bg-gray-2/80 border border-gray-6/70 rounded-2xl mx-auto flex items-center justify-center shadow-2xl shadow-gray-12/10 mb-6">
122-
<OpenWorkLogo size={18} />
117+
<div class="">
118+
<OpenWorkLogo size={48} />
123119
</div>
124120
<h2 class="text-2xl font-bold tracking-tight">
125121
{props.workspaces.length <= 1 ? translate("onboarding.create_first_workspace") : translate("onboarding.create_workspace")}
@@ -444,8 +440,8 @@ export default function OnboardingView(props: OnboardingViewProps) {
444440
<div class="max-w-xl w-full z-10 space-y-12">
445441
<div class="text-center space-y-4">
446442
<div class="flex items-center justify-center gap-3 mb-6">
447-
<div class="w-12 h-12 bg-gray-2/80 border border-gray-6/70 rounded-xl flex items-center justify-center">
448-
<OpenWorkLogo size={24} />
443+
<div class="">
444+
<OpenWorkLogo size={48} />
449445
</div>
450446
<h1 class="text-3xl font-bold tracking-tight text-gray-12">OpenWork</h1>
451447
</div>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ export default function SessionView(props: SessionViewProps) {
388388
};
389389

390390
const handlePromptKeyDown = (event: KeyboardEvent) => {
391-
if (event.isComposing) return;
392391
if (event.key === "Enter" && event.shiftKey) return;
392+
if (event.isComposing && event.key !== "Enter") return;
393393

394394
const menuOpen = commandMenuOpen();
395395
const matches = commandMatches();

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ export function formatBytes(bytes: number) {
169169
return `${rounded} ${units[idx]}`;
170170
}
171171

172+
export function normalizeDirectoryPath(input?: string | null) {
173+
const trimmed = (input ?? "").trim();
174+
if (!trimmed) return "";
175+
const unified = trimmed.replace(/\\/g, "/");
176+
const withoutTrailing = unified.replace(/\/+$/, "");
177+
const normalized = withoutTrailing || "/";
178+
return isWindowsPlatform() ? normalized.toLowerCase() : normalized;
179+
}
180+
172181
export function normalizeEvent(raw: unknown): OpencodeEvent | null {
173182
if (!raw || typeof raw !== "object") {
174183
return null;

‎packages/desktop/src/i18n/locales/en.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ export default {
624624
"status.loading_session": "Loading session",
625625
"status.creating_task": "Creating new task",
626626
"status.starting_engine": "Starting engine",
627+
"status.restarting_engine": "Restarting engine",
627628
"status.installing_opencode": "Installing OpenCode",
628629
"status.disconnecting": "Disconnecting",
629630
"app.connection_lost": "Server connection lost. Please reload.",

‎packages/desktop/src/i18n/locales/zh.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ export default {
631631
"status.loading_session": "正在加载会话",
632632
"status.creating_task": "正在创建新任务",
633633
"status.starting_engine": "正在启动引擎",
634+
"status.restarting_engine": "正在重启引擎",
634635
"status.installing_opencode": "正在安装 OpenCode",
635636
"status.disconnecting": "正在断开连接",
636637
"app.connection_lost": "服务器连接已断开。请重新加载。",

0 commit comments

Comments
 (0)