跳到主要内容

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

提交记录
修改docs/getting-started.md+2 −0看文件
@@ -209,6 +209,8 @@ Desktop 的主机文件操作只接受已授权项目或已保存下载记录中
209209
210210Windows 和 Linux 默认采用 Ctrl 按键习惯,工作台快捷键中的 `⌘` 对应 `Ctrl`;终端复制粘贴使用 `Ctrl+Shift+C/V`,保留 `Ctrl+C` 中断命令。
211211
212新增:在 Claude Desktop、Claude Code 和普通终端的多行输入中,按 `Shift+Enter` 在当前输入内换行,按 `Enter` 提交消息或执行命令。网页和 Desktop 的目标输入框须支持多行;终端程序须支持多行粘贴或识别 Shift+Enter。Bash、zsh 启用多行粘贴时,换行不会执行已写好的命令;自行关闭此模式或使用其他终端程序时,行为取决于程序的按键支持。中文输入法仍在选择候选词时,回车先由输入法处理。
213新增:
212214复制粘贴支持纯文本、中文、多行和 emoji。先点击目标输入框,再使用快捷键或工具栏按钮;普通浏览器限制剪贴板权限时,可用“文本传递”面板。Cage 仅在主动复制或粘贴时访问本机剪贴板,不持续轮询。
213215
214216Cage 浏览器中的网页复制按钮也可同步纯文本到本机。点击后保持当前网页和 Cage 窗口处于前台,出现“已复制到本机”即可在其他应用粘贴。如果网页采用不受支持的旧式复制方式,或复制期间切换了标签、输入位置或窗口,可重新复制,或使用复制快捷键和“文本传递”面板。
修改ui/scripts/remote-input-smoke.mjs+19 −0看文件
@@ -183,6 +183,12 @@ try {
183183 );
184184 assert.equal(await target.inputValue(), "");
185185 await clear();
186新增: await page.keyboard.press("Shift+Enter");
187新增: assert.deepEqual((await keys()).map(({ sym, down }) => [sym, down]), [
188新增: [0xffe1, 1], [0xff0d, 1], [0xff0d, 0], [0xffe1, 0],
189新增: ], "Shift+Enter must preserve the modifier through the real RFB encoder");
190新增: assert.deepEqual(await texts(), [], "newline must not also commit textarea text");
191新增: await clear();
186192 await page.keyboard.down("Shift");
187193 await page.evaluate(() => {
188194 probe.rfb._cagePasteJob = { id: "punctuation", phase: "fence", timer: setTimeout(() => {}, 1000), resolve() {} };
@@ -359,6 +365,18 @@ try {
359365 await clear();
360366 await page.evaluate(() => probe.installNative());
361367 await page.waitForFunction(() => probe.nativeRequests.some(value => value.operation === "activate"));
368新增: await page.evaluate(() => {
369新增: const owner = probe.nativeRequests.find(value => value.operation === "activate").owner;
370新增: for (const kind of ["keydown", "keyup"]) {
371新增: window.dispatchEvent(new CustomEvent("cage-native-input", {
372新增: detail: { owner, kind, key: "Enter", code: "Enter", shiftKey: true },
373新增: }));
374新增: }
375新增: });
376新增: assert.deepEqual((await keys()).map(({ sym, down }) => [sym, down]), [
377新增: [0xffe1, 1], [0xff0d, 1], [0xff0d, 0], [0xffe1, 0],
378新增: ], "native Enter's shiftKey must survive without a preceding DOM Shift event");
379新增: await clear();
362380 await page.evaluate(() => {
363381 const owner = probe.nativeRequests.find(value => value.operation === "activate").owner;
364382 const emit = value => window.dispatchEvent(new CustomEvent("cage-native-input", { detail: { owner, ...value } }));
@@ -397,6 +415,7 @@ try {
397415 passed: true,
398416 checks: [
399417 "real noVNC keyboard and RFB encoding",
418新增: "Shift+Enter and native modifier recovery",
400419 "English input",
401420 "fullwidth question mark and punctuation",
402421 "English question mark and modifier release",
新增ui/scripts/terminal-newline-smoke.mjs+67 −0看文件
@@ -0,0 +1,67 @@
1新增:// Exercises the production xterm handler and final WebSocket input messages.
2新增:import assert from "node:assert/strict";
3新增:import { createWorkbench } from "./workbench-fixture.mjs";
4新增:
5新增:for (const platform of ["MacIntel", "Win32", "Linux x86_64"]) {
6新增: const inputs = [];
7新增: let releaseClipboard;
8新增: const { browser, page, errors } = await createWorkbench({
9新增: mockWebSockets: false,
10新增: nativeRequest: request => request.action === "clipboardReadContent"
11新增: ? new Promise(resolve => { releaseClipboard = resolve; }) : null,
12新增: beforeNavigate: page => page.addInitScript(platform => {
13新增: Object.defineProperty(navigator, "platform", { value: platform });
14新增: }, platform),
15新增: });
16新增: let socket;
17新增: try {
18新增: await page.routeWebSocket("**/api/**", remote => {
19新增: if (!remote.url().includes("/terminals/")) return remote.close();
20新增: socket = remote;
21新增: remote.onMessage(message => {
22新增: const { type, data } = JSON.parse(message);
23新增: if (type === "input") inputs.push(data);
24新增: });
25新增: remote.send(Buffer.from("$ "));
26新增: });
27新增: await page.getByRole("button", { name: "启动 Cage 环境", exact: true }).click();
28新增: await page.getByRole("button", { name: "新建终端", exact: true }).first().click();
29新增: await page.getByRole("menuitem", { name: "普通终端", exact: true }).click();
30新增: await page.locator(".xterm-helper-textarea").focus();
31新增: async function press(key, expected) {
32新增: const start = inputs.length;
33新增: await page.keyboard.press(key);
34新增: await assertInputs(start, expected);
35新增: }
36新增: async function assertInputs(start, expected) {
37新增: const deadline = Date.now() + 3000;
38新增: while (inputs.length < start + expected.length && Date.now() < deadline)
39新增: await new Promise(resolve => setTimeout(resolve, 10));
40新增: assert.deepEqual(inputs.slice(start), expected);
41新增: }
42新增: await press("Shift+Enter", ["\x1b[13;2u"]);
43新增: await press("Enter", ["\r"]);
44新增: await press("Control+c", ["\x03"]);
45新增: socket.send(Buffer.from("\x1b[?2004hMODE_READY"));
46新增: await page.locator(".xterm-rows").getByText(/MODE_READY/).waitFor();
47新增: await press("Shift+Enter", ["\x1b[200~\n\x1b[201~"]);
48新增: await press("Shift+Enter", ["\x1b[200~\n\x1b[201~"]);
49新增: await press("Enter", ["\r"]);
50新增: const beforePaste = inputs.length;
51新增: await page.keyboard.press(platform === "MacIntel" ? "Meta+v" : "Control+Shift+V");
52新增: const deadline = Date.now() + 3000;
53新增: while (!releaseClipboard && Date.now() < deadline)
54新增: await new Promise(resolve => setTimeout(resolve, 10));
55新增: assert.ok(releaseClipboard, "the paste gesture must start its clipboard read");
56新增: await page.keyboard.press("Shift+Enter");
57新增: await page.keyboard.press("Enter");
58新增: assert.equal(inputs.length, beforePaste, "newline and submission must wait for pending paste");
59新增: releaseClipboard({ text: "CAGE_PASTE" });
60新增: await assertInputs(beforePaste, ["\x1b[200~CAGE_PASTE\x1b[201~", "\x1b[200~\n\x1b[201~", "\r"]);
61新增: socket.send(Buffer.from("\x1b[?2004lMODE_OFF"));
62新增: await page.locator(".xterm-rows").getByText(/MODE_OFF/).waitFor();
63新增: await press("Shift+Enter", ["\x1b[13;2u"]);
64新增: assert.deepEqual(errors, []);
65新增: console.log(`${platform}: Shift+Enter, repeated newlines, paste ordering, Enter and Ctrl+C passed`);
66新增: } finally { await browser.close(); }
67新增:}
修改ui/src/remote-input.js+23 −0看文件
@@ -458,6 +458,29 @@ export function installRemoteInput(
458458 ? code[3].toLowerCase()
459459 : event.key.toLowerCase();
460460 if (["Shift", "Control", "Alt", "Meta"].includes(event.key)) physical.add(code);
461新增: if (event.key === "Shift") {
462新增: const sym = getKeysym(event);
463新增: transport.sendKey(sym, code, true);
464新增: remote.set(code, sym);
465新增: event.preventDefault();
466新增: event.stopImmediatePropagation();
467新增: return;
468新增: }
469新增: if (event.key === "Enter" && event.shiftKey && !event.metaKey && !event.ctrlKey && !event.altKey) {
470新增: // Native IME focus can change after Shift was pressed. RFB carries
471新增: // modifier key events, not the Enter event's shiftKey flag.
472新增: const shift = physical.has("ShiftRight") ? [0xffe2, "ShiftRight"] : [0xffe1, "ShiftLeft"];
473新增: const sym = getKeysym(event);
474新增: if (!remote.has(shift[1])) transport.sendKey(...shift, true);
475新增: transport.sendKey(sym, code, true);
476新增: transport.sendKey(sym, code, false);
477新增: if (physical.has(shift[1])) remote.set(shift[1], shift[0]);
478新增: else transport.sendKey(...shift, false);
479新增: handled.add(code);
480新增: event.preventDefault();
481新增: event.stopImmediatePropagation();
482新增: return;
483新增: }
461484 if (
462485 mapping &&
463486 event.metaKey &&
修改ui/src/remote-input.test.mjs+37 −1看文件
@@ -90,7 +90,7 @@ function fixture(native = false, browserComposition = false, options = {}) {
9090 nativeAvailable: () => native,
9191 getKeycode: (e) => e.code,
9292 getKeysym: (e) =>
93删除: ({ Shift: 0xffe1, Control: 0xffe3, Alt: 0xffe9, Meta: 0xffeb })[e.key] ??
93新增: ({ Shift: e.code === "ShiftRight" ? 0xffe2 : 0xffe1, Control: 0xffe3, Alt: 0xffe9, Meta: 0xffeb, Enter: 0xff0d })[e.key] ??
9494 (e.key.length === 1 ? e.key.codePointAt(0) : null),
9595 Keysyms: {
9696 lookup: (codepoint) =>
@@ -180,6 +180,42 @@ function fixture(native = false, browserComposition = false, options = {}) {
180180 reads: () => reads,
181181 };
182182}
183新增:for (const guest of ["linux", "windows", "darwin"]) {
184新增: test(`${guest}: Shift+Enter restores a modifier missed during focus changes`, () => {
185新增: const f = fixture();
186新增: f.setGuestPlatform(guest);
187新增: try {
188新增: assert.equal(f.key("keydown", "Enter", "Enter", { shiftKey: true }).defaultPrevented, true);
189新增: f.key("keyup", "Enter", "Enter", { shiftKey: true });
190新增: assert.deepEqual(f.keys, [
191新增: [0xffe1, "ShiftLeft", true], [0xff0d, "Enter", true],
192新增: [0xff0d, "Enter", false], [0xffe1, "ShiftLeft", false],
193新增: ]);
194新增: f.keys.length = 0;
195新增: f.key("keydown", "Enter", "Enter", { shiftKey: true, isComposing: true });
196新增: assert.deepEqual(f.keys, [], "IME confirmation must not insert a newline");
197新增: } finally { f.controller.dispose(); }
198新增: });
199新增: for (const code of ["ShiftLeft", "ShiftRight"]) {
200新增: test(`${guest}: Shift+Enter keeps held ${code} until its release`, () => {
201新增: const f = fixture();
202新增: f.setGuestPlatform(guest);
203新增: try {
204新增: const sym = code === "ShiftRight" ? 0xffe2 : 0xffe1;
205新增: f.key("keydown", "Shift", code, { shiftKey: true });
206新增: f.key("keydown", "Enter", "Enter", { shiftKey: true });
207新增: f.key("keyup", "Enter", "Enter", { shiftKey: true });
208新增: assert.ok(!f.keys.some(([key, , down]) => key === sym && !down));
209新增: f.key("keyup", "Shift", code);
210新增: assert.deepEqual(f.keys.at(-1), [sym, code, false]);
211新增: f.keys.length = 0;
212新增: f.win.dispatchEvent(new Event("blur"));
213新增: assert.deepEqual(f.keys, [], "released Shift must not remain held remotely");
214新增: } finally { f.controller.dispose(); }
215新增: });
216新增: }
217新增:}
218新增:
183219test("Mac find and redo preserve the Linux Ctrl/Shift chord", () => {
184220 const f = fixture();
185221 try {
修改ui/src/views.jsx+11 −0看文件
@@ -450,6 +450,17 @@ export function TerminalView({ session, visible, focused = true, onStatus, onCon
450450 },
451451 });
452452 terminal.attachCustomKeyEventHandler((event) => {
453新增: if (event.key === "Enter" && event.shiftKey && !event.metaKey && !event.ctrlKey && !event.altKey &&
454新增: !event.isComposing && event.keyCode !== 229) {
455新增: event.preventDefault();
456新增: if (event.type === "keydown") {
457新增: // Bracketed insertion adds a line inside shell/CLI editors. Programs
458新增: // without paste mode receive the distinct CSI-u Shift+Enter key.
459新增: void enqueue(() => send(terminal.modes.bracketedPasteMode
460新增: ? "\x1b[200~\n\x1b[201~" : "\x1b[13;2u")).catch(() => {});
461新增: }
462新增: return false;
463新增: }
453464 if (!terminalModifier(event) || event.type !== "keydown") return true;
454465 const key = event.key.toLowerCase();
455466 if (key === "c") {