跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

提交记录
修改docs/getting-started.md+1 −1看文件
@@ -40,7 +40,7 @@
4040
4141### 选择环境存储位置
4242
43删除:Windows 安装器中选择的是程序目录。如果希望镜像下载和虚拟磁盘都放在 D 盘,首次登录后在独立初始化界面的“系统与存储”中选择专用空文件夹,例如 `D:\CageData`,点击“使用此位置”,再配置代理并开始安装。macOS 和 Linux 使用相同流程。安装、必要授权与网络检查完成后才进入工作台;中断后重新打开仍可继续。Debian 环境默认设置下,虚拟磁盘在用户主目录的 `.claude-cage/state/lima`,镜像下载缓存在系统用户缓存目录下的 `lima`(Windows 为 `%LOCALAPPDATA%\lima`)。
43新增:Windows 安装器中选择的是程序目录。如果希望镜像下载和虚拟磁盘都放在 D 盘,首次登录后在独立初始化界面的“系统与存储”中修改已填入默认值的“存储目录”,或选择专用空文件夹,例如 `D:\CageData`,点击“下一步:配置代理”时保存。macOS 和 Linux 使用相同流程。安装、必要授权与网络检查完成后才进入工作台;中断后重新打开仍可继续。Debian 环境默认设置下,虚拟磁盘在用户主目录的 `.claude-cage/state/lima`,镜像下载缓存在系统用户缓存目录下的 `lima`(Windows 为 `%LOCALAPPDATA%\lima`)。
4444
4545选择支持私有文件权限和稀疏文件的本地磁盘。Windows 可用 NTFS,Linux 可用 ext4、XFS 或 Btrfs。Mac 需要 APFS 卷并启用所有权。使用 Mac 外接盘时,在 Finder 的磁盘“显示简介”中取消“忽略此宗卷的所有权”。
4646
修改docs/guide/installation.md+1 −1看文件
@@ -38,7 +38,7 @@ Windows ARM64 和 Linux ARM64 暂不支持。平台依赖详情见 [Windows 指
3838
3939首次登录后,Cage 显示独立的初始化界面。先选择适合项目的客机系统,可选择“自动匹配本机系统版本”或具体系统。自动匹配会在代理配置后获取对应的官方镜像,安装干净的独立系统,主机个人文件与登录资料不会复制。以后启动沿用原系统和磁盘,更新 Cage 不会替换客机系统。
4040
41删除:在“本机环境存储”中查看默认位置;需要更换时点击“选择文件夹”,选定本地磁盘上的专用空文件夹,再点击“使用此位置”。Windows 安装器里的程序目录与环境数据目录分开;例如应用装在 C 盘,环境可放在 `D:\CageData`。
41新增:“存储目录”已填入默认位置。需要更换时直接编辑,或点击“选择文件夹”选定本地磁盘上的专用空文件夹;点击“下一步:配置代理”时保存,目录无效时留在当前页提示修改。Windows 安装器里的程序目录与环境数据目录分开;例如应用装在 C 盘,环境可放在 `D:\CageData`。
4242
4343选择支持权限管理与稀疏文件的磁盘:Windows 可用 NTFS,Linux 可用 ext4 / XFS / Btrfs,macOS 使用已启用所有权的 APFS。不要选择磁盘根目录、网络盘、已有项目或应用安装目录。已有环境换盘请按[存储迁移](maintenance.md#迁移环境到另一块磁盘)操作。
4444
修改ui/scripts/archive-bulk-smoke.mjs+3 −3看文件
@@ -61,14 +61,14 @@ try {
6161 await panel.getByRole("status").filter({hasText:"已取消归档 1 个会话"}).waitFor();
6262 assert.deepEqual(operations.splice(0),[{id:"a2",operation:"restore"}],"filtered select all affected hidden sessions");
6363 await search.fill("");
64删除: // Changing project filters also clears selection, and the dropdown pushes content down.
64新增: // Changing filters clears selection; its floating list keeps content in place.
6565 await checkbox(panel,allName).check();
6666 const filter = panel.getByRole("combobox",{name:"项目筛选"});
6767 const toolbar = panel.getByRole("group",{name:"批量处理会话"});
6868 const before = await toolbar.boundingBox();
6969 await filter.click();
70删除: const list = await panel.getByRole("listbox",{name:"项目筛选选项"}).boundingBox();
71删除: assert.ok((await toolbar.boundingBox()).y >= list.y + list.height);
70新增: const list = await page.getByRole("listbox",{name:"项目筛选选项"}).boundingBox();
71新增: assert.ok(Math.abs((await toolbar.boundingBox()).y-before.y)<1 && list.height>0);
7272 await filter.press("Escape");
7373 assert.ok(Math.abs((await toolbar.boundingBox()).y-before.y)<2);
7474 await filter.press("End"); await filter.press("Enter");
修改ui/scripts/browser-vertical-tabs-smoke.mjs+1 −1看文件
@@ -50,7 +50,7 @@ try {
5050 const before = await help.boundingBox();
5151 await picker.click();
5252 const expanded = await help.boundingBox();
53删除: assert.ok(expanded.y > before.y + 40, "options must push the following content down");
53新增: assert.ok(Math.abs(expanded.y - before.y) < 1, "floating options must not move the following content");
5454 await page.keyboard.press("Escape");
5555 assert.ok(Math.abs((await help.boundingBox()).y - before.y) < 1, "closing options restores the layout");
5656 await picker.click();
修改ui/scripts/cli-session-management-smoke.mjs+4 −4看文件
@@ -103,10 +103,10 @@ try {
103103 await group.waitFor();
104104 const before = await group.boundingBox();
105105 await projectFilter.click();
106删除: const options = panel.getByRole("listbox",{name:"项目筛选选项"});
106新增: const options = page.getByRole("listbox",{name:"项目筛选选项"});
107107 const opened = await options.boundingBox();
108108 const shifted = await group.boundingBox();
109删除: assert.ok(shifted.y > before.y + 20 && opened.y + opened.height <= shifted.y,"project filter covered content");
109新增: assert.ok(Math.abs(shifted.y-before.y)<1 && opened.height>0,"floating project filter moved content");
110110 await projectFilter.press("Escape");
111111 assert.ok(Math.abs((await group.boundingBox()).y - before.y) < 2,"filter did not restore layout");
112112 await projectFilter.press("End"); await projectFilter.press("Enter");
@@ -114,7 +114,7 @@ try {
114114 assert.equal(await panel.getByRole("heading",{name:"电脑保留的历史",exact:true}).count(),0);
115115 await projectFilter.press("Home"); await projectFilter.press("Enter");
116116 const filter = panel.getByRole("combobox",{name:"会话筛选"});
117删除: await filter.click(); await panel.getByRole("option",{name:"已置顶",exact:true}).click();
117新增: await filter.click(); await page.getByRole("option",{name:"已置顶",exact:true}).click();
118118 assert.equal(await panel.getByRole("article").count(),1);
119119 await filter.press("Home"); await filter.press("Enter");
120120 const search = panel.getByRole("searchbox",{name:"搜索已归档的会话"});
@@ -143,7 +143,7 @@ try {
143143 const phoneFilter = phone.getByRole("combobox",{name:"项目筛选"});
144144 await phoneFilter.click();
145145 const phoneOptions = await phone.getByRole("listbox",{name:"项目筛选选项"}).boundingBox();
146删除: assert.ok((await phoneGroup.boundingBox()).y >= phoneOptions.y + phoneOptions.height,"phone filter covered content");
146新增: assert.ok(Math.abs((await phoneGroup.boundingBox()).y-phoneBefore.y)<1 && phoneOptions.height>0,"floating phone filter moved content");
147147 await phoneFilter.press("Escape");
148148 assert.ok(Math.abs((await phoneGroup.boundingBox()).y-phoneBefore.y)<2);
149149 await phone.getByRole("heading",{name:"已归档会话",exact:true}).click();
修改ui/scripts/exit-policy-region-smoke.mjs+3 −3看文件
@@ -31,12 +31,12 @@ try {
3131 await country.press("Escape");
3232 const before = await layoutTop(country);
3333 await picker.click();
34删除: const options = picker.locator("..").getByRole("listbox");
34新增: const options = page.getByRole("listbox");
3535 await options.waitFor();
3636 const expanded = await layoutTop(country);
3737 const list = await options.boundingBox();
38删除: assert.ok(expanded > before, "expanded options must move the following fields down");
39删除: assert.ok((await layoutTop(options)) + list.height <= expanded, "options must not cover the next control");
38新增: assert.ok(Math.abs(expanded - before) < 1, "floating options must not move the following fields");
39新增: assert.ok(list.height > 0, "options must remain visible");
4040 await picker.press("ArrowDown");
4141 await picker.press("Enter");
4242 await page.getByLabel("允许的城市", { exact: true }).waitFor({ state: "hidden" });
修改ui/scripts/guest-install-smoke.mjs+1 −1看文件
@@ -23,7 +23,7 @@ for (const [id, name, platform] of [["macos", "macOS", "darwin"], ["windows-11",
2323 const option = page.getByRole("option", { name, exact: true });
2424 await option.waitFor();
2525 const row = await option.boundingBox(), below = await storage.boundingBox();
26删除: assert.ok(below.y > storageBefore.y && row.y + row.height <= below.y);
26新增: assert.ok(Math.abs(below.y - storageBefore.y) < 1 && row.height > 0);
2727 await picker.press("Escape");
2828 assert.equal((await storage.boundingBox()).y, storageBefore.y);
2929 await picker.press("Enter"); await picker.press("End"); await picker.press("Enter");
修改ui/scripts/guest-system-picker-smoke.mjs+2 −2看文件
@@ -22,10 +22,10 @@ for (const [platform, id] of [["darwin","macos"], ["windows","windows-11"], ["li
2222 const storage = page.getByRole("button",{name:"选择环境存储位置"});
2323 const initialY = (await storage.boundingBox()).y;
2424 await picker.click();
25删除: const option = region.getByRole("option").last();
25新增: const option = page.getByRole("option").last();
2626 assert.equal(await option.getAttribute("aria-disabled"),"true");
2727 const position = await option.boundingBox();
28删除: assert.ok((await storage.boundingBox()).y >= position.y + position.height);
28新增: assert.ok(Math.abs((await storage.boundingBox()).y - initialY) < 1 && position.height > 0);
2929 await picker.press("Escape");
3030 assert.ok(Math.abs((await storage.boundingBox()).y - initialY) <= 1, "collapsed picker restores the following control");
3131 }
修改ui/scripts/host-clone-smoke.mjs+3 −3看文件
@@ -53,14 +53,14 @@ for (const [platform, system, version, edition] of [
5353 const initialHeight = (await region.boundingBox()).height;
5454 await picker.focus();
5555 await picker.press("ArrowDown");
56删除: const option = region.getByRole("option", {
56新增: const option = page.getByRole("option", {
5757 name: "自动匹配本机系统版本",
5858 exact: true,
5959 });
6060 await option.waitFor();
6161 assert.ok(
62删除: (await region.boundingBox()).height > initialHeight,
63删除: "options occupy layout space",
62新增: Math.abs((await region.boundingBox()).height - initialHeight) < 1,
63新增: "floating options must not change layout height",
6464 );
6565 await picker.press("Home");
6666 await picker.press("Enter");
修改ui/scripts/initialization-smoke.mjs+49 −4看文件
@@ -13,7 +13,7 @@ for (const [platform, system] of [["darwin", "macos"], ["windows", "windows-11"]
1313 beforeNavigate: async (page, state) => {
1414 state.status.local_vm_storage = true;
1515 await page.route("**/api/environment/storage", route => route.fulfill({ json: { directory: "/preview/cage-state", has_environment: false } }));
16删除: await page.route("**/api/environment/guest-systems", route => route.fulfill({ json: { fresh: true, available: true, system } }));
16新增: await page.route("**/api/environment/guest-systems", route => route.fulfill({ json: { fresh: true, available: true, system, linux_systems: ["ubuntu-22.04"] } }));
1717 await page.route("**/api/environment/guest-systems/clone", route => route.fulfill({ json: { key: "matched-image", enough_space: true, minimum_free_gib: 51, free_gib: 120, download_bytes: 19769944180, plan: { host: { system, version: system === "windows-11" ? "25H2" : "26.5", build: "123", edition: "Professional", language: "zh-CN" }, version: "26.5", build: "456", bytes: 19769944180 } } }));
1818 await page.route("**/api/start", route => {
1919 starts++;
@@ -36,14 +36,21 @@ for (const [platform, system] of [["darwin", "macos"], ["windows", "windows-11"]
3636 try {
3737 assert.equal(await page.getByRole("complementary", { name: "项目与终端" }).count(), 0);
3838 const picker = page.getByRole("combobox", { name: "客户机系统" });
39删除: const storage = page.getByRole("region", { name: "本机环境存储" });
40删除: await storage.getByText("/preview/cage-state").waitFor();
39新增: const storage = page.getByRole("region", { name: "环境存储目录" });
40新增: await storage.getByLabel("存储目录", { exact: true }).waitFor();
41新增: assert.equal(await storage.getByLabel("存储目录", { exact: true }).inputValue(), "/preview/cage-state");
42新增: assert.equal(await storage.getByText("当前环境目录", { exact: true }).count(), 0);
43新增: assert.equal(await storage.getByText("新存储位置", { exact: true }).count(), 0);
4144 const before = await storage.boundingBox();
4245 await picker.click();
4346 const option = page.getByRole("option", { name: "自动匹配本机系统版本", exact: true });
4447 await option.waitFor();
48新增: for (const name of [/^Debian/, /^Ubuntu/, /^macOS/, /^Windows/]) assert.equal(await page.getByRole("option", { name }).count(), 1);
4549 const expanded = await storage.boundingBox();
46删除: assert.ok(expanded.y > before.y);
50新增: assert.ok(Math.abs(expanded.y - before.y) < 1, "floating system choices must not move storage");
51新增: const menu = await page.getByRole("listbox").boundingBox();
52新增: assert.ok(menu.x >= 0 && menu.y >= 0 && menu.x + menu.width <= 1280 && menu.y + menu.height <= 850, "floating menu must stay inside the viewport");
53新增: if (evidence) await page.screenshot({ path: `${evidence}/${platform}-systems-floating.png`, fullPage: true });
4754 await picker.press("Home"); await picker.press("Enter");
4855 await page.getByText("Cage 会检测本机系统版本。配置代理后匹配官方镜像,并显示下载量与空间要求。").waitFor();
4956 if (system === "windows-11") await page.getByRole("checkbox").check();
@@ -87,6 +94,44 @@ for (const [platform, system] of [["darwin", "macos"], ["windows", "windows-11"]
8794 } finally { await browser.close(); }
8895}
8996
97新增:{
98新增: let location = { directory: "/preview/default-state", has_environment: false }, writes = 0, fail = true;
99新增: const f = await createWorkbench({ initialization: { required: true, tracked: true }, beforeNavigate: async (page, state) => {
100新增: state.status.local_vm_storage = true;
101新增: await page.route("**/api/environment/guest-systems", route => route.fulfill({ json: { fresh: true, available: true, system: "macos", linux_systems: ["ubuntu-22.04"] } }));
102新增: await page.route("**/api/environment/storage", route => {
103新增: if (route.request().method() === "GET") return route.fulfill({ json: location });
104新增: const body = route.request().postDataJSON();
105新增: writes++;
106新增: assert.equal(body.previous, "/preview/default-state");
107新增: assert.equal(body.migrate, false);
108新增: if (fail) return route.fulfill({ status: 400, contentType: "text/plain; charset=utf-8", body: "请选择专用空文件夹" });
109新增: location = { ...location, directory: body.directory };
110新增: state.status.job = { id: "save-storage", kind: "storage", running: false };
111新增: return route.fulfill({ json: state.status.job });
112新增: });
113新增: } });
114新增: try {
115新增: const input = f.page.getByLabel("存储目录", { exact: true });
116新增: assert.equal(await input.inputValue(), "/preview/default-state");
117新增: await input.fill("/preview/chosen-state");
118新增: assert.equal(writes, 0, "editing must not save before Next");
119新增: await f.page.getByRole("button", { name: "下一步:配置代理" }).click();
120新增: await f.page.getByRole("alert").filter({ hasText: "请选择专用空文件夹" }).waitFor();
121新增: assert.equal(await input.inputValue(), "/preview/chosen-state");
122新增: assert.equal(await f.page.getByRole("heading", { name: "连接你的网络代理" }).count(), 0);
123新增: fail = false;
124新增: await f.page.getByRole("button", { name: "下一步:配置代理" }).click();
125新增: await f.page.getByRole("heading", { name: "连接你的网络代理" }).waitFor();
126新增: assert.equal(location.directory, "/preview/chosen-state");
127新增: assert.equal(writes, 2);
128新增: await f.page.getByRole("button", { name: "上一步", exact: true }).click();
129新增: assert.equal(await input.inputValue(), "/preview/chosen-state");
130新增: assert.deepEqual(f.errors, []);
131新增: console.log("PASS storage: one default-filled directory, save on Next, rejected path preserved, retry and back navigation");
132新增: } finally { await f.browser.close(); }
133新增:}
134新增:
90135{
91136 let imported = false, applied = false;
92137 const f = await createWorkbench({ initialization: { required: true, tracked: true }, beforeNavigate: async (page, state) => {
修改ui/scripts/installation-preview.mjs+1 −1看文件
@@ -51,7 +51,7 @@ http.createServer(async (req, res) => {
5151 else if (url.pathname === "/api/settings") value = { workspace: "/preview/workspace", browser_home_url: "https://www.bing.com/", timezone: "Asia/Shanghai", locale: "zh_CN.UTF-8", keyboard: status.keyboard };
5252 else if (url.pathname === "/api/appearance") value = { ...defaultAppearance, mode: "light" };
5353 else if (url.pathname === "/api/proxy") value = { active: true, selected: "preview-node", port: 17896, core_available: true, state: "prepared", sources: [{ id: "preview", name: "预览代理", nodes: [{ id: "preview-node", name: "预览节点", type: "http" }] }] };
54删除: else if (url.pathname === "/api/environment/guest-systems") value = { fresh: !pending, available: true, system, pending };
54新增: else if (url.pathname === "/api/environment/guest-systems") value = { fresh: !pending, available: true, system, pending, linux_systems: ["ubuntu-22.04"] };
5555 else if (url.pathname === "/api/environment/guest-systems/clone") value = { plan, key: "preview-only", enough_space: scenario !== "space", download_bytes: scenario === "cached" ? 0 : scenario === "resume" ? Math.floor(host.bytes / 3) : host.bytes, minimum_free_gib: 32 + Math.ceil(host.bytes / 1073741824), free_gib: scenario === "space" ? 10 : 120, installation_started: Boolean(pending) };
5656 else if (url.pathname === "/api/host/git") value = { state: "ok", ready: true, message: "本机 Git 安全保护已启用。" };
5757 else if (url.pathname === "/api/terminals") value = [];
修改ui/scripts/mobile-inline-select-smoke.mjs+7 −5看文件
@@ -6,7 +6,7 @@ import { smokeCaptureDirectory } from "./smoke-captures.mjs";
66const require = createRequire(import.meta.url);
77const engines = require(process.env.CAGE_PLAYWRIGHT_MODULE || "playwright");
88const engine = process.env.CAGE_TEST_BROWSER || "chromium";
9删除:const browser = await engines[engine].launch();
9新增:const browser = await engines[engine].launch({executablePath:process.env.CAGE_TEST_BROWSER_PATH});
1010const output = await smokeCaptureDirectory("mobile-inline-select");
1111const origin = process.env.CAGE_UI_URL || "http://127.0.0.1:5399";
1212const errors = [];
@@ -38,7 +38,7 @@ try {
3838 const create = page.getByRole("button", { name: "新建会话", exact: true });
3939 const collapsed = await create.boundingBox();
4040 await picker.press("Enter");
41删除: assert.ok((await create.boundingBox()).y > collapsed.y);
41新增: assert.ok(Math.abs((await create.boundingBox()).y-collapsed.y)<1);
4242 await picker.press("End");
4343 await picker.press("Enter");
4444 await picker.getByText("gamma", { exact: true }).waitFor();
@@ -49,9 +49,10 @@ try {
4949 assert.equal(await picker.getAttribute("aria-expanded"), "false");
5050 assert.equal((await create.boundingBox()).y, collapsed.y);
5151 await picker.tap();
52新增: await picker.tap();
5253 await create.tap();
5354 await page.getByRole("textbox", { name: "消息", exact: true }).waitFor();
54删除: assert.equal(creations, 1, "one tap after an expanded project selector must create exactly one session");
55新增: assert.equal(creations, 1, "one tap after closing the project selector must create exactly one session");
5556 assert.equal(sessions[0].workspace, "/work/gamma");
5657 await page.screenshot({ path: join(output, `${engine}-new-session.png`) });
5758 await page.close();
@@ -86,12 +87,13 @@ try {
8687 await phone.getByRole("button", { name: "收藏夹", exact: true }).tap();
8788 await phone.getByRole("button", { name: "收藏此页", exact: true }).tap();
8889 await phone.getByRole("combobox", { name: "保存到", exact: true }).tap();
90新增: await phone.getByRole("combobox", { name: "保存到", exact: true }).tap();
8991 await phone.getByRole("button", { name: "保存收藏", exact: true }).tap();
9092 await phone.getByRole("button", { name: "取消此页收藏", exact: true }).waitFor();
91删除: assert.equal(writes, 1, "one tap after the expanded folder selector must save exactly once");
93新增: assert.equal(writes, 1, "one tap after closing the folder selector must save exactly once");
9294 await phone.screenshot({ path: join(output, `${engine}-saved-favorite.png`) });
9395 assert.deepEqual(errors, []);
94删除: console.log(`${engine}: inline layout, keyboard selection, Escape, focus restoration and first-tap session/favorite mutations passed.`);
96新增: console.log(`${engine}: floating layout, keyboard selection, Escape, focus restoration and session/favorite mutations passed.`);
9597} finally {
9698 await browser.close();
9799}
修改ui/scripts/proxy-chain-ui-smoke.mjs+2 −2看文件
@@ -48,7 +48,7 @@ try {
4848 const before=await relativeExit();
4949 await via.click();
5050 const after=await relativeExit();
51删除: assert.ok(after-before>80,'dropdown must push the following exit down');
51新增: assert.ok(Math.abs(after-before)<1,'floating dropdown must not move the following exit');
5252 const list=await page.getByRole('listbox',{name:'中转节点选项'}).boundingBox();
5353 const container=await page.locator('.proxy-route').boundingBox();
5454 assert.ok(list.x>=container.x && list.x+list.width<=container.x+container.width,'dropdown escapes its container');
@@ -131,5 +131,5 @@ try {
131131 await page.evaluate(()=>new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve))));
132132 await page.screenshot({path:path.join(output,'dark.png'),animations:'disabled'});
133133 assert.deepEqual(errors,[]);
134删除: console.log(JSON.stringify({passed:true,submissions:submissions.length,checks:['network-check exit-rules entry','cross-source route draft','inline layout reflow','keyboard selection and focus','explicit atomic apply','reload persistence','failed apply keeps draft','retry','multiple transit nodes','undo','leave and section-change confirmation','saving DNS preserves route draft','single-node mode','narrow viewport'],browserErrors:errors}));
134新增: console.log(JSON.stringify({passed:true,submissions:submissions.length,checks:['network-check exit-rules entry','cross-source route draft','floating options keep layout fixed','keyboard selection and focus','explicit atomic apply','reload persistence','failed apply keeps draft','retry','multiple transit nodes','undo','leave and section-change confirmation','saving DNS preserves route draft','single-node mode','narrow viewport'],browserErrors:errors}));
135135} finally {await browser.close();}
修改ui/scripts/remote-hosts-smoke.mjs+3 −4看文件
@@ -43,16 +43,15 @@ try {
4343 await page.getByLabel("SSH 用户名", { exact: true }).fill("cage-test");
4444 const auth = page.getByRole("combobox", { name: "SSH 登录方式" });
4545 const keyField = page.getByLabel("本机私钥文件", { exact: true });
46删除: // The centered dialog itself moves when its height changes. Compare gaps
47删除: // inside the dialog to check whether the list takes up layout space.
46新增: // Opening the floating list keeps both the dialog and its fields in place.
4847 const gap = async () => (await keyField.boundingBox()).y - (await auth.boundingBox()).y;
4948 const before = await gap();
5049 await auth.click();
5150 await page.getByRole("option", { name: "本机 SSH agent" }).waitFor();
5251 const expanded = await keyField.boundingBox();
53删除: assert.ok(await gap() > before + 30, "inline choices must push subsequent fields down");
52新增: assert.ok(Math.abs(await gap() - before) < 1, "floating choices must not move subsequent fields");
5453 const list = await page.getByRole("listbox").boundingBox();
55删除: assert.ok(list.y + list.height <= expanded.y, "choices must not cover the next field");
54新增: assert.ok(list.height > 0 && Math.abs(expanded.y - (await keyField.boundingBox()).y) < 1);
5655 await auth.press("Escape");
5756 assert.equal(await auth.getAttribute("aria-expanded"), "false");
5857 await page.getByRole("listbox").waitFor({state:"hidden"});
修改ui/scripts/ubuntu-guest-choice-smoke.mjs+1 −1看文件
@@ -28,7 +28,7 @@ for (const [platform, system] of [["darwin", "macos"], ["windows", "windows-11"]
2828 await option.waitFor();
2929 const box = await option.boundingBox();
3030 const expanded = await storage.boundingBox();
31删除: assert.ok(expanded.y > initial.y && box.y + box.height <= expanded.y, "inline options overlap the next control");
31新增: assert.ok(Math.abs(expanded.y - initial.y) < 1 && box.height > 0, "floating options must not move the next control");
3232 await picker.press("Escape");
3333 assert.equal((await storage.boundingBox()).y, initial.y);
3434 await picker.press("Enter");
修改ui/scripts/workbench-fixture.mjs+1 −1看文件
@@ -385,5 +385,5 @@ export async function createWorkbench({
385385
386386export async function chooseInline(picker, value) {
387387 await picker.click();
388删除: await picker.locator("..").getByRole("option").and(picker.page().locator(`[data-value=${JSON.stringify(String(value))}]`)).click();
388新增: await picker.page().getByRole("option").and(picker.page().locator(`[data-value=${JSON.stringify(String(value))}]`)).click();
389389}
修改ui/src/guest-system-picker.jsx+5 −4看文件
@@ -91,13 +91,14 @@ export function GuestSystemPicker({ system, onChange, preserveOnUnmount = false,
9191 return (
9292 <div className="guest-system-picker">
9393 <span>客户机系统</span>
94删除: {view.system || view.linux_systems?.length ? <InlineSelect aria-label="客户机系统" value={system.clone ? "host" : os} disabled={system.pending}
94新增: <InlineSelect aria-label="客户机系统" value={system.clone ? "host" : os} disabled={system.pending}
9595 onValueChange={(value) => onChange({ guest_system: value === "host" ? view.system : value, clone: value === "host", clone_key: "", clone_ready: false, media: "", sha256: "", editor_terms: false })}>
9696 {Boolean(view.system) && <option value="host" disabled={!view.available}>自动匹配本机系统版本{view.available ? "" : "(暂不可用)"}</option>}
9797 <option value="debian-13">Debian 13</option>
98删除: {(view.linux_systems || []).map((id) => <option key={id} value={id}>{names[id]}</option>)}
99删除: {["macos", "windows-11"].includes(view.system) && <option value={view.system} disabled={!view.available}>{names[view.system]}{view.available ? "" : "(暂不可用)"}</option>}
100删除: </InlineSelect> : <strong>Debian 13</strong>}
98新增: <option value="ubuntu-22.04" disabled={!view.linux_systems?.includes("ubuntu-22.04")}>Ubuntu 22.04{view.linux_systems?.includes("ubuntu-22.04") ? "" : "(此构建暂不可用)"}</option>
99新增: <option value="macos" disabled={view.system !== "macos" || !view.available}>macOS{view.system === "macos" ? view.available ? "" : "(暂不可用)" : "(需要 Apple Silicon Mac)"}</option>
100新增: <option value="windows-11" disabled={view.system !== "windows-11" || !view.available}>Windows 11{view.system === "windows-11" ? view.available ? "" : "(暂不可用)" : "(需要 Windows 11 与 Hyper-V)"}</option>
101新增: </InlineSelect>
101102 {system.clone && !system.activate && (deferMatch ? <small className="guest-install-fields">Cage 会检测本机系统版本。配置代理后匹配官方镜像,并显示下载量与空间要求。</small> : <HostCloneSummary pending={system.pending} onChange={onChange} />)}
102103 {!system.clone && os !== "debian-13" && !system.activate && <div className="guest-install-fields">
103104 {os === "ubuntu-22.04" ? <>
新增ui/src/initialization-storage.jsx+33 −0看文件
@@ -0,0 +1,33 @@
1新增:import React, { useEffect, useState } from "react";
2新增:import { FolderOpen } from "lucide-react";
3新增:import { api, native, nativeAvailable } from "./api";
4新增:
5新增:export function InitializationStorage({ value, onChange, disabled }) {
6新增: const [error, setError] = useState("");
7新增: const [attempt, retry] = useState(0);
8新增: useEffect(() => {
9新增: if (value) return;
10新增: let live = true;
11新增: api("/environment/storage").then(location => {
12新增: if (live) onChange({ location, directory: location.directory });
13新增: }).catch(error => { if (live) setError(error.message); });
14新增: return () => { live = false; };
15新增: }, [Boolean(value), onChange, attempt]);
16新增: const locked = disabled || !value || value.location.has_environment;
17新增: async function choose() {
18新增: try {
19新增: const directory = await native("chooseFolder", { purpose: "environmentStorage" });
20新增: if (directory) { onChange({ ...value, directory }); setError(""); }
21新增: } catch (error) { setError(error.message); }
22新增: }
23新增: return <section className="initialization-storage" aria-label="环境存储目录">
24新增: <label htmlFor="initialization-directory">存储目录</label>
25新增: <p>系统镜像、下载缓存和虚拟磁盘保存在这里。已填入默认目录,也可以选择其他本地磁盘上的专用空文件夹。</p>
26新增: <div className="initialization-directory-control">
27新增: <input id="initialization-directory" value={value?.directory || ""} disabled={locked} spellCheck={false} placeholder={value ? "请输入存储目录的完整路径" : "正在读取默认目录…"} onChange={event => onChange({ ...value, directory: event.target.value })} />
28新增: {nativeAvailable() && <button type="button" disabled={locked} onClick={choose}><FolderOpen size={16} />选择文件夹</button>}
29新增: </div>
30新增: {value?.location.has_environment && <p>已有虚拟磁盘,继续使用原存储目录。完成初始化后可在设置中迁移。</p>}
31新增: {error && <p role="alert">{error}<button onClick={() => { setError(""); retry(value => value + 1); }}>重新读取</button></p>}
32新增: </section>;
33新增:}
修改ui/src/initialization.css+7 −0看文件
@@ -17,6 +17,13 @@
1717.initialization .guest-install-fields small { font-size: 14px; line-height: 1.65; }
1818.initialization .host-clone-summary { padding: 18px; gap: 10px; background: var(--chrome); }
1919.initialization .environment-storage { padding-top: 22px; border-top: 1px solid var(--line); }
20新增:.initialization-storage { padding-top: 22px; border-top: 1px solid var(--line); }
21新增:.initialization-storage > label { font-size: 16px; font-weight: 550; color: var(--strong); }
22新增:.initialization-storage > p { color: var(--muted); font-size: 14px; margin: 8px 0 16px; }
23新增:.initialization-directory-control { display: flex; gap: 10px; }
24新增:.initialization-directory-control input { flex: 1; min-width: 0; min-height: 42px; box-sizing: border-box; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; background: var(--input); color: var(--ink); font: inherit; }
25新增:.initialization-directory-control button { flex: none; }
26新增:@media (max-width: 500px) { .initialization-directory-control { flex-wrap: wrap; } .initialization-directory-control input { flex-basis: 100%; } }
2027.initialization .environment-storage > h4 { font-size: 16px; margin: 0 0 8px; }
2128.initialization .field-help { color: var(--muted); font-size: 14px; }
2229.initialization .environment-storage label { display: grid; gap: 8px; margin: 16px 0 10px; }
修改ui/src/initialization.jsx+25 −3看文件
@@ -4,7 +4,7 @@ import { api, native, nativeAvailable } from "./api";
44import { isRemoteClient } from "./client-context.mjs";
55import { useAccount } from "./account";
66import { GuestSystemPicker, HostCloneSummary, validGuestChoice } from "./guest-system-picker";
7删除:import { EnvironmentStorage } from "./environment-storage";
7新增:import { InitializationStorage } from "./initialization-storage";
88import { ProxySettings } from "./proxy-settings";
99import { SetupProgress } from "./setup-progress";
1010import { DiagnosticSettings } from "./diagnostics.jsx";
@@ -54,6 +54,7 @@ function Initialization({ initial, onComplete }) {
5454 const [status, setStatus] = useState(null);
5555 const [proxy, setProxy] = useState(null);
5656 const [choice, setChoice] = useState(undefined);
57新增: const [storage, setStorage] = useState(null);
5758 const [pending, setPending] = useState(null);
5859 const [submitting, setSubmitting] = useState(false);
5960 const [error, setError] = useState("");
@@ -174,6 +175,27 @@ function Initialization({ initial, onComplete }) {
174175 setProxyDirty(false);
175176 setStep(step === "install" ? "proxy" : pending || account?.guest_system ? "install" : "system");
176177 }
178新增: async function nextFromSystem() {
179新增: await run(async () => {
180新增: const directory = storage.directory.trim();
181新增: if (directory !== storage.location.directory) {
182新增: const accepted = await api("/environment/storage", { directory, previous: storage.location.directory, migrate: false });
183新增: let job;
184新增: do {
185新增: await new Promise(resolve => setTimeout(resolve, 300));
186新增: if (!alive.current) return;
187新增: const next = await api("/status");
188新增: setStatus(next); job = next.job;
189新增: if (job.id !== accepted.id) throw new Error("存储操作状态已变化,请核对目录后重试。");
190新增: } while (job.running);
191新增: if (job.error) throw new Error(job.error);
192新增: const location = await api("/environment/storage");
193新增: if (location.directory !== directory) throw new Error("存储目录尚未保存,请重新选择后重试。");
194新增: setStorage({ location, directory: location.directory });
195新增: }
196新增: setStep("proxy");
197新增: });
198新增: }
177199 const failed = Boolean(job.error || error);
178200 const progress = job.setup_progress && { ...job, setup_progress: job.setup_progress };
179201 const title = step === "system" ? "为 Cage 准备独立环境" : step === "proxy" ? "连接你的网络代理" : ready ? "Cage 已准备就绪" : failed ? "继续完成环境安装" : busy ? "正在准备你的环境" : "安装并检查客机环境";
@@ -187,7 +209,7 @@ function Initialization({ initial, onComplete }) {
187209 <div className="initialization-stage" key={step}>
188210 {step === "system" && <>
189211 <GuestSystemPicker system={choice} onChange={setChoice} preserveOnUnmount deferMatch />
190删除: <EnvironmentStorage status={status} onConfirm={confirm} />
212新增: <InitializationStorage value={storage} onChange={setStorage} disabled={busy} />
191213 </>}
192214 {step === "proxy" && <><ProxySettings initializing status={status} onConfirm={confirm} onDirty={setProxyDirty} onApplied={async () => { setProxy(await api("/proxy")); pollNow.current?.(); }} />{choice?.clone && !needsProxySetup(null, status, proxy) && <HostCloneSummary pending={choice.pending} onChange={setChoice} />}</>}
193215 {step === "install" && (ready ? <div className="initialization-ready"><ShieldCheck size={36} /><h2>环境已就绪</h2><p>独立客机已安装,工具、文件和登录状态会持续保存。以后打开 Cage 可直接进入工作台。</p></div> : <>
@@ -201,7 +223,7 @@ function Initialization({ initial, onComplete }) {
201223 {error && <p className="initialization-notice" role="alert"><SafetyMessage message={error} /></p>}
202224 <footer className="initialization-actions">
203225 {step === "system" ? <span /> : <button className="text-button" disabled={busy} onClick={back}><ChevronLeft size={16} />上一步</button>}
204删除: {step === "system" && <button className="primary" disabled={busy || choice === undefined || (!choice?.clone && !validGuestChoice(choice)) || choice?.clone && choice.guest_system === "windows-11" && !choice.editor_terms || Boolean(connectionError)} onClick={() => setStep("proxy")}>下一步:配置代理</button>}
226新增: {step === "system" && <button className="primary" disabled={busy || !storage?.directory.trim() || choice === undefined || (!choice?.clone && !validGuestChoice(choice)) || choice?.clone && choice.guest_system === "windows-11" && !choice.editor_terms || Boolean(connectionError)} onClick={nextFromSystem}>{submitting && <LoaderCircle size={16} className="spin" />}下一步:配置代理</button>}
205227 {step === "proxy" && <button className="primary" disabled={busy || proxyDirty || !account?.guest_system && !pending && !validGuestChoice(choice) || needsProxySetup(null, status, proxy) || Boolean(connectionError)} onClick={install}>{submitting ? <LoaderCircle size={16} className="spin" /> : null}开始安装</button>}
206228 {step === "install" && ready && <button className="primary" disabled={submitting || Boolean(connectionError)} onClick={enter}>进入工作台</button>}
207229 </footer>
修改ui/src/inline-select.css+6 −2看文件
@@ -16,9 +16,11 @@
1616.inline-select-trigger svg { flex: none; }
1717.inline-select-trigger[aria-expanded="true"] svg { transform: rotate(180deg); }
1818.inline-select-list {
19删除: position: relative;
19新增: position: fixed;
20新增: z-index: 10000;
2021 display: grid;
21删除: margin-top: 3px;
22新增: box-sizing: border-box;
23新增: margin: 0;
2224 padding: 3px;
2325 max-height: min(14rem, 32vh);
2426 overflow: auto;
@@ -29,6 +31,8 @@
2931 font-size: inherit;
3032 font-weight: 400;
3133 text-align: start;
34新增: box-shadow: 0 8px 24px #00000020, 0 2px 6px #0000000c;
35新增: overscroll-behavior: contain;
3236}
3337.inline-select-list [role="option"] {
3438 display: flex;
修改ui/src/inline-select.jsx+8 −5看文件
@@ -1,8 +1,10 @@
11import React, { Children, useEffect, useId, useRef, useState } from "react";
2新增:import { createPortal } from "react-dom";
3新增:import { useSelectPopup } from "./select-popup";
24import { Check, ChevronDown } from "lucide-react";
35import "./inline-select.css";
46
5删除:// Keep focus on the control while its list occupies space below it.
7新增:// Keep keyboard focus on the control; the popup does not change page layout.
68export function InlineSelect({
79 children,
810 value,
@@ -43,6 +45,7 @@ export function InlineSelect({
4345 const active = filtered.findIndex(
4446 (item) => item.value === cursor && !item.disabled,
4547 );
48新增: const position = useSelectPopup(visible, control, list, filtered.length);
4649 useEffect(() => {
4750 if (visible && active >= 0) {
4851 const row = list.current.querySelector(`[data-index="${active}"]`);
@@ -58,9 +61,8 @@ export function InlineSelect({
5861 }, [visible, active]);
5962 useEffect(() => {
6063 if (!open) return;
61删除: // Collapse after the outside click lands so reflow cannot move its target.
6264 const outside = (event) => {
63删除: if (!root.current.contains(event.target)) setOpen(false);
65新增: if (!root.current.contains(event.target) && !list.current?.contains(event.target)) setOpen(false);
6466 };
6567 document.addEventListener("click", outside, true);
6668 return () => document.removeEventListener("click", outside, true);
@@ -153,13 +155,14 @@ export function InlineSelect({
153155 <ChevronDown size={14} aria-hidden="true" />
154156 </button>
155157 )}
156删除: {visible && (
158新增: {visible && createPortal(
157159 <span
158160 ref={list}
159161 id={id}
160162 role="listbox"
161163 aria-label={(props["aria-label"] || "") + "选项"}
162164 className="inline-select-list"
165新增: style={position}
163166 onMouseDown={(event) => event.preventDefault()}
164167 onClick={(event) => event.preventDefault()}
165168 >
@@ -190,7 +193,7 @@ export function InlineSelect({
190193 </span>
191194 </React.Fragment>
192195 ))}
193删除: </span>
196新增: </span>, document.body
194197 )}
195198 </span>
196199 );
修改ui/src/mobile-cli/inline-select.jsx+8 −5看文件
@@ -1,11 +1,14 @@
11import React, { useEffect, useId, useRef, useState } from "react";
2新增:import { createPortal } from "react-dom";
23import { Check, ChevronDown } from "lucide-react";
4新增:import { useSelectPopup } from "../select-popup";
35
4删除:// Options follow the trigger in normal flow and keep the combobox focused.
6新增:// The floating options keep the combobox focused without shifting the page.
57export function InlineSelect({ label, value, options, onChange, onLongPress, footer, disabled, icon }) {
68 const id = useId();
79 const root = useRef(null);
810 const trigger = useRef(null);
11新增: const list = useRef(null);
912 const hold = useRef(null);
1013 const held = useRef(false);
1114 const origin = useRef(null);
@@ -13,11 +16,11 @@ export function InlineSelect({ label, value, options, onChange, onLongPress, foo
1316 const [cursor, setCursor] = useState(value);
1417 const selected = options.find(item => item.value === value);
1518 const visible = open && !disabled;
19新增: const position = useSelectPopup(visible, trigger, list, options.length);
1620 const cancelHold = () => { clearTimeout(hold.current); hold.current = null; };
1721 useEffect(() => {
1822 if (!visible) return;
19删除: const outside = event => { if (!root.current.contains(event.target)) setOpen(false); };
20删除: // Let the outside click reach its target before the inline list reflows.
23新增: const outside = event => { if (!root.current.contains(event.target) && !list.current?.contains(event.target)) setOpen(false); };
2124 document.addEventListener("click", outside, true);
2225 return () => document.removeEventListener("click", outside, true);
2326 }, [visible]);
@@ -80,7 +83,7 @@ export function InlineSelect({ label, value, options, onChange, onLongPress, foo
8083 onClick={() => {if (held.current) {held.current = false; return;} setCursor(value); setOpen(!visible);}}>
8184 {icon}<span>{selected?.label || label}</span><ChevronDown size={14} aria-hidden="true" />
8285 </button>
83删除: {visible && <div className="inline-select-popover">
86新增: {visible && createPortal(<div className="inline-select-popover" ref={list} style={position}>
8487 <div className="inline-select-options" role="listbox" id={id} aria-label={label + "选项"}>
8588 {options.map((item, index) => <div key={item.value} role="option" id={id + "-" + index}
8689 aria-selected={item.value === value} data-active={item.value === cursor || undefined}
@@ -90,6 +93,6 @@ export function InlineSelect({ label, value, options, onChange, onLongPress, foo
9093 </div>)}
9194 </div>
9295 {footer && <p className="inline-select-hint" id={id + "-hint"}>{footer}</p>}
93删除: </div>}
96新增: </div>, document.body)}
9497 </div>;
9598}
修改ui/src/mobile-cli/mobile.css+1 −1看文件
@@ -67,7 +67,7 @@ h2 { font-size: 17px; line-height: 1.45; font-weight: 620; }
6767.inline-select-trigger > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
6868.inline-select-trigger svg { flex: none; }
6969.inline-select-trigger[aria-expanded="true"] > svg:last-child { transform: rotate(180deg); }
70删除:.inline-select-popover { width: 100%; margin: 3px 0 5px; border: 1px solid var(--line); border-radius: 10px; padding: 4px; background: var(--paper); }
70新增:.inline-select-popover { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 4px; background: var(--paper); color: var(--ink); overflow: auto; box-shadow: 0 8px 24px #00000020; overscroll-behavior: contain; }
7171.inline-select-options { max-height: min(280px, 38vh); overflow-y: auto; }
7272.inline-select-options [role="option"] { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; padding: 10px 12px; border-radius: 8px; font-size: 14px; overflow-wrap: anywhere; cursor: pointer; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
7373.inline-select-options [role="option"] svg { flex: none; }
新增ui/src/select-popup.jsx+31 −0看文件
@@ -0,0 +1,31 @@
1新增:import { useLayoutEffect, useState } from "react";
2新增:
3新增:// Both desktop and mobile mount the list outside scroll/overflow containers.
4新增:export function useSelectPopup(visible, control, list, count) {
5新增: const [position, setPosition] = useState(null);
6新增: useLayoutEffect(() => {
7新增: if (!visible) return;
8新增: const place = () => {
9新增: const rect = control.current.getBoundingClientRect();
10新增: const style = getComputedStyle(control.current);
11新增: const gap = 4, margin = 8;
12新增: const below = window.innerHeight - rect.bottom - gap - margin;
13新增: const above = rect.top - gap - margin;
14新增: const upward = below < Math.min(list.current.scrollHeight + 8, 224) && above > below;
15新增: const maxHeight = Math.max(40, Math.min(280, upward ? above : below));
16新增: const width = Math.min(rect.width, window.innerWidth - margin * 2);
17新增: const height = Math.min(list.current.scrollHeight + 8, maxHeight);
18新增: const next = { position: "fixed", zIndex: 10000, boxSizing: "border-box", margin: 0, left: Math.max(margin, Math.min(rect.left, window.innerWidth - width - margin)), top: upward ? Math.max(margin, rect.top - gap - height) : rect.bottom + gap, width, maxHeight, fontFamily: style.fontFamily, fontSize: style.fontSize, lineHeight: style.lineHeight };
19新增: for (const key of ["--ink", "--paper", "--line", "--selected", "--focus", "--muted", "--control-cursor"]) next[key] = style.getPropertyValue(key);
20新增: setPosition(next);
21新增: };
22新增: const scroll = event => { if (!list.current?.contains(event.target)) place(); };
23新增: place();
24新增: const observer = new ResizeObserver(place);
25新增: observer.observe(control.current);
26新增: window.addEventListener("resize", place);
27新增: document.addEventListener("scroll", scroll, true);
28新增: return () => { observer.disconnect(); window.removeEventListener("resize", place); document.removeEventListener("scroll", scroll, true); };
29新增: }, [visible, control, list, count]);
30新增: return position || { visibility: "hidden" };
31新增:}