Skip to content

Commit 4706178

Browse files
committed
fix(agent): 切工作目录闪 2 次 (initRuntime 二次 reload)
根因: setCwd 写 APP_CWD 后 reload, reload 后 initRuntime 走 hostCwd 兜底 检查时仍命中 reload 条件 → 二次 reload 表现为 '切工作目录闪 2 次'. 原条件 (web/src/service/agent.ts:111): if (hostCwd && cwd !== hostCwd && APP_CWD_FALLBACK !== hostCwd) { reload; } // 注释说 '无 APP_CWD' 但代码没检查 cwd 是否空 复现: 用户初始 APP_CWD='' (hostCwd 兜底), 选非 hostCwd 目录: 1. setCwd 写 APP_CWD=新值, reload anomalyco#1 2. reload 后 initRuntime: cwd=新值 (有 APP_CWD), hostCwd 不等 → 二次 reload anomalyco#2 修复: 加 '!cwd' 短路 — 仅在无 APP_CWD (纯 hostCwd 兜底) 场景才 reload 重建 codeblitz 根, 已在 setCwd 写过 APP_CWD 后不再触发.
1 parent 20c92fd commit 4706178

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎web/src/service/agent.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ export class AgentServiceImpl implements IAgent, ClientAppContribution {
103103
defaultShell: defaultShell || '/bin/bash',
104104
healthy,
105105
};
106-
// 2.4 hostCwd 兜底场景 (无 APP_CWD): WORKSPACE_ROOT (constant.js patch) 模块加载时可能还是
107-
// /workspace (initRuntime 异步注入晚于模块求值) — 首次探测到 hostCwd 后写 sessionStorage
108-
// 标记并 reload 一次, 让 codeblitz 用真实 cwd 重建 (BrowserFS 挂载/URI 全链路).
106+
// 2.4 hostCwd 兜底场景 (仅在没设 APP_CWD 时): WORKSPACE_ROOT (constant.js patch) 模块加载时
107+
// 可能还是 /workspace (initRuntime 异步注入晚于模块求值) — 首次探测到 hostCwd 后写
108+
// sessionStorage 标记并 reload 一次, 让 codeblitz 用真实 cwd 重建 (BrowserFS 挂载/URI 全链路).
109109
// 写 sessionStorage 而非 localStorage: APP_CWD 语义是用户选择, hostCwd 只是兜底;
110110
// reload 后该标记仍在 → constant.js 读到真实路径 → 二次 initRuntime 不再 reload.
111-
if (hostCwd && cwd !== hostCwd && sessionStorage.getItem('APP_CWD_FALLBACK') !== hostCwd) {
111+
// 关键: 已在 setCwd 写过 APP_CWD 后, 不要因为 cwd (新值) 跟 hostCwd 不同而再 reload — 那是用户主动选择,
112+
// 二次 reload 表现为 "切换工作目录闪 2 次".
113+
if (!cwd && hostCwd && sessionStorage.getItem('APP_CWD_FALLBACK') !== hostCwd) {
112114
try {
113115
sessionStorage.setItem('APP_CWD_FALLBACK', hostCwd);
114116
console.log('[agent] hostCwd 注入 (无 APP_CWD), reload 重建 codeblitz 根:', hostCwd);

0 commit comments

Comments
 (0)