跳到主要内容

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

浏览文件

workspace-state.mjs

68 行 · 2.5 KB历史下载
1export function readLocal(key, fallback) {
2 try {
3 return JSON.parse(localStorage.getItem(key)) ?? fallback;
4 } catch {
5 return fallback;
6 }
7}
8
9export function orderedTabs(tabs, saved) {
10 const order = saved.order || [];
11 return [...tabs].sort((a, b) => {
12 const pinned =
13 Number(Boolean(saved[b.id]?.pinned)) -
14 Number(Boolean(saved[a.id]?.pinned));
15 if (pinned) return pinned;
16 const index = (id) =>
17 order.includes(id) ? order.indexOf(id) : order.length;
18 return index(a.id) - index(b.id);
19 });
20}
21
22const clientMount = /^\/run\/cage-client-projects\/[0-9a-f]{32}$/;
23const folderName = (path) => path?.split(/[\\/]/).filter(Boolean).at(-1);
24
25export function rememberClientProjectName(share) {
26 if (!clientMount.test(share.guest_path)) return;
27 try { sessionStorage.setItem(share.guest_path, folderName(share.path)); }
28 catch { /* The mount is usable without browser storage. */ }
29}
30
31export function projectName(path, defaultWorkspace) {
32 if (clientMount.test(path)) {
33 try { return sessionStorage.getItem(path) || "本机共享项目"; }
34 catch { return "本机共享项目"; }
35 }
36 if (path === defaultWorkspace && path?.endsWith("-workspace")) return "默认工作区";
37 return folderName(path) || "新项目";
38}
39
40export function tabName(tab, saved, project) {
41 return (tab.incognito ? "无痕 · " : "") + (
42 saved[tab.id]?.title ||
43 (tab.kind === "editor"
44 ? `文件 · ${tab.workspace ? projectName(tab.workspace) : project}`
45 : tab.title) ||
46 "新标签页"
47 );
48}
49
50// The focused tab and its neighbour retain their screen positions on focus changes.
51export function focusTab(layout, id) {
52 if (layout.active === id) return layout;
53 if (!id) return { active: "" };
54 if (layout.other === id)
55 return { active: id, other: layout.active, side: layout.side === "left" ? "right" : "left" };
56 if (layout.other && id.startsWith("terminal:") !== layout.active.startsWith("terminal:") &&
57 id.startsWith("terminal:") === layout.other.startsWith("terminal:"))
58 return { ...focusTab(layout, layout.other), active: id };
59 return { ...layout, active: id };
60}
61
62export function splitTab(layout, tabs, id, side) {
63 if (!tabs.some(tab => tab.id === id)) return layout;
64 const opposite = layout.side === side ? layout.other : layout.active;
65 const other = [opposite, layout.other, layout.active, ...tabs.map(tab => tab.id)]
66 .find(candidate => candidate !== id && tabs.some(tab => tab.id === candidate));
67 return other ? { active: id, other, side } : layout;
68}