@hjd-hitsz/claudex-web 4.1.4 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +2 -0
- package/CHANGELOG.md +47 -0
- package/README.md +13 -1
- package/bin/auth.mjs +86 -0
- package/bin/claudex-web.mjs +20 -0
- package/bin/p2p.mjs +134 -0
- package/build-info.json +4 -4
- package/client/dist/app.js +104 -104
- package/client/dist/code-highlight-style.js +1 -1
- package/client/dist/document-editor.js +55 -54
- package/client/dist/file-panel.js +5 -5
- package/client/dist/notification-worker.js +2 -1
- package/client/dist/p2p-sw.js +162 -0
- package/client/dist/style.css +1 -1
- package/client/dist/terminal-panel.js +11 -11
- package/docs/architecture/backends.md +9 -2
- package/docs/architecture/behavior.md +167 -53
- package/docs/architecture.md +36 -337
- package/docs/background-tasks.md +30 -26
- package/docs/deployment.md +47 -6
- package/docs/development.md +111 -153
- package/docs/images/desktop-dark.png +0 -0
- package/docs/images/desktop-light.png +0 -0
- package/docs/images/mobile-sidebar.png +0 -0
- package/docs/images/mobile.png +0 -0
- package/docs/releases/v4.1.5.md +6 -0
- package/docs/releases/v4.2.0.md +13 -0
- package/docs/versioning.md +13 -3
- package/package.json +14 -5
- package/packages/background-terminal/LICENSE +674 -0
- package/packages/background-terminal/README.md +17 -0
- package/packages/background-terminal/background-jobs.mjs +457 -0
- package/packages/background-terminal/background-mcp.mjs +79 -0
- package/packages/background-terminal/background-protocol.mjs +80 -0
- package/packages/background-terminal/cli.mjs +14 -0
- package/packages/background-terminal/client.mjs +61 -0
- package/packages/background-terminal/codex.mjs +88 -0
- package/packages/background-terminal/delivery.mjs +192 -0
- package/packages/background-terminal/log.mjs +25 -0
- package/packages/background-terminal/native-watches.mjs +160 -0
- package/packages/background-terminal/package.json +15 -0
- package/packages/background-terminal/service.mjs +126 -0
- package/packages/translation-engine/package.json +1 -1
- package/server/src/application.mjs +82 -10
- package/server/src/auth-http.mjs +187 -0
- package/server/src/auth-login.mjs +144 -0
- package/server/src/auth-totp.mjs +233 -0
- package/server/src/auth.mjs +169 -220
- package/server/src/backends/claude/background-tasks.mjs +88 -35
- package/server/src/backends/claude/messages.mjs +1 -1
- package/server/src/backends/claude/worker-client.mjs +47 -35
- package/server/src/backends/claude/worker-lines.mjs +17 -0
- package/server/src/backends/claude/worker-server.mjs +49 -69
- package/server/src/backends/codex/adapter.mjs +46 -5
- package/server/src/backends/codex/background-service.mjs +85 -0
- package/server/src/backends/codex/background-task-views.mjs +87 -0
- package/server/src/backends/codex/background-terminals.mjs +91 -0
- package/server/src/backends/codex/events.mjs +11 -0
- package/server/src/backends/codex/methods.mjs +1 -0
- package/server/src/backends/codex/native-background-handoff.mjs +72 -0
- package/server/src/backends/codex/requests.mjs +51 -38
- package/server/src/backends/codex/subscriptions.mjs +34 -4
- package/server/src/backends/configuration.mjs +8 -0
- package/server/src/backends/manager.mjs +35 -33
- package/server/src/backends/storage.mjs +3 -14
- package/server/src/config.mjs +13 -0
- package/server/src/http/business.mjs +21 -0
- package/server/src/http/router.mjs +12 -25
- package/server/src/p2p/http.mjs +136 -0
- package/server/src/p2p/peers.mjs +132 -0
- package/server/src/p2p/service.mjs +229 -0
- package/server/src/p2p/storage.mjs +45 -0
- package/server/src/p2p/tunnel.mjs +95 -0
- package/server/src/p2p-http.mjs +149 -0
- package/server/src/p2p-peer.mjs +135 -0
- package/server/src/private-file.mjs +14 -0
- package/server/src/summary-translation.mjs +1 -1
- package/server/src/thread-folders.mjs +3 -13
- package/server/src/translation-service.mjs +3 -8
- package/server/src/workspace/file-search.mjs +244 -0
- package/server/src/workspace/service.mjs +17 -3
- package/shared/codex-preferences.mjs +9 -0
- package/shared/p2p-wire.mjs +157 -0
|
@@ -2,14 +2,25 @@ import { workspaceMethods } from "../../../shared/product-contract.mjs";
|
|
|
2
2
|
import { fileRequest } from "./files.mjs";
|
|
3
3
|
import { executeCommand } from "./commands.mjs";
|
|
4
4
|
import { createTerminals } from "./terminals.mjs";
|
|
5
|
+
import { createFileSearch } from "./file-search.mjs";
|
|
5
6
|
|
|
6
|
-
// 网页交互终端和主机文件操作由服务持有,原生搜索由所属后端提供。
|
|
7
7
|
export function createWorkspace({ broadcast, configDir }) {
|
|
8
8
|
const terminals = createTerminals(broadcast);
|
|
9
|
+
const files = createFileSearch();
|
|
9
10
|
const methods = new Set(workspaceMethods);
|
|
10
11
|
return {
|
|
11
|
-
handles
|
|
12
|
+
handles(method, backend, workspaceOwner) {
|
|
13
|
+
if (backend && method === "fuzzyFileSearch")
|
|
14
|
+
return (
|
|
15
|
+
backend.type === "claude" ||
|
|
16
|
+
["127.0.0.1", "localhost", "[::1]"].includes(
|
|
17
|
+
new URL(backend.url).hostname,
|
|
18
|
+
)
|
|
19
|
+
);
|
|
20
|
+
return methods.has(method) && (!backend || workspaceOwner === "bridge");
|
|
21
|
+
},
|
|
12
22
|
request(method, params) {
|
|
23
|
+
if (method === "fuzzyFileSearch") return files.search(params);
|
|
13
24
|
if (method.startsWith("fs/"))
|
|
14
25
|
return fileRequest(method, params, configDir);
|
|
15
26
|
if (method === "command/exec" && !params.tty)
|
|
@@ -22,6 +33,9 @@ export function createWorkspace({ broadcast, configDir }) {
|
|
|
22
33
|
throw new Error(`未知工作区操作:${method}`);
|
|
23
34
|
},
|
|
24
35
|
snapshot: terminals.snapshot,
|
|
25
|
-
close
|
|
36
|
+
close() {
|
|
37
|
+
files.close();
|
|
38
|
+
terminals.close();
|
|
39
|
+
},
|
|
26
40
|
};
|
|
27
41
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function isCodexPreference(input) {
|
|
2
|
+
return (
|
|
3
|
+
input.id === "codex" &&
|
|
4
|
+
("backgroundTerminalEnabled" in input || "hiddenModels" in input) &&
|
|
5
|
+
Object.keys(input).every((key) =>
|
|
6
|
+
["id", "type", "backgroundTerminalEnabled", "hiddenModels"].includes(key),
|
|
7
|
+
)
|
|
8
|
+
);
|
|
9
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { MAX_RPC_MESSAGE_BYTES } from "./rpc-limits.mjs";
|
|
2
|
+
|
|
3
|
+
const frameSize = 16 * 1024;
|
|
4
|
+
const maxJsonBytes = 64 * 1024;
|
|
5
|
+
export const MAX_P2P_BODY_BYTES = 512 * 1024;
|
|
6
|
+
export const P2P_STREAM_CHUNK_BYTES = 64 * 1024;
|
|
7
|
+
const bufferLimit = 256 * 1024;
|
|
8
|
+
const maxQueueBytes = 2 * MAX_RPC_MESSAGE_BYTES;
|
|
9
|
+
const encoder = new TextEncoder();
|
|
10
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
11
|
+
|
|
12
|
+
export function createP2pWire({
|
|
13
|
+
sendFrame,
|
|
14
|
+
bufferedAmount,
|
|
15
|
+
receive,
|
|
16
|
+
close,
|
|
17
|
+
maxInboundBytes,
|
|
18
|
+
}) {
|
|
19
|
+
let closed = false;
|
|
20
|
+
let pending = Promise.resolve();
|
|
21
|
+
let queuedBytes = 0;
|
|
22
|
+
let incoming;
|
|
23
|
+
let deadline;
|
|
24
|
+
|
|
25
|
+
function shutdown() {
|
|
26
|
+
closed = true;
|
|
27
|
+
incoming = null;
|
|
28
|
+
clearTimeout(deadline);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function fail(error) {
|
|
32
|
+
if (closed) return;
|
|
33
|
+
shutdown();
|
|
34
|
+
close(error);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function send(message, binary = new Uint8Array()) {
|
|
38
|
+
if (closed) return Promise.reject(new Error("直连已断开"));
|
|
39
|
+
const rpc = message.type === "rpc";
|
|
40
|
+
if (rpc) binary = encoder.encode(message.text);
|
|
41
|
+
const json = encoder.encode(
|
|
42
|
+
JSON.stringify(rpc ? { type: "rpc" } : message),
|
|
43
|
+
);
|
|
44
|
+
const size = json.length + binary.byteLength + 8;
|
|
45
|
+
if (
|
|
46
|
+
json.length > maxJsonBytes ||
|
|
47
|
+
binary.byteLength > (rpc ? MAX_RPC_MESSAGE_BYTES : MAX_P2P_BODY_BYTES) ||
|
|
48
|
+
queuedBytes + size > maxQueueBytes
|
|
49
|
+
) {
|
|
50
|
+
const error = new Error("直连消息超过传输限制");
|
|
51
|
+
fail(error);
|
|
52
|
+
return Promise.reject(error);
|
|
53
|
+
}
|
|
54
|
+
queuedBytes += size;
|
|
55
|
+
const operation = pending.then(async () => {
|
|
56
|
+
const prefix = new Uint8Array(8 + json.length);
|
|
57
|
+
const header = new DataView(prefix.buffer);
|
|
58
|
+
header.setUint32(0, json.length);
|
|
59
|
+
header.setUint32(4, binary.byteLength);
|
|
60
|
+
prefix.set(json, 8);
|
|
61
|
+
for (let offset = 0; offset < size; offset += frameSize - 1) {
|
|
62
|
+
const end = Math.min(offset + frameSize - 1, size);
|
|
63
|
+
const packet = new Uint8Array(end - offset + 1);
|
|
64
|
+
packet[0] = (offset === 0 ? 1 : 0) | (end === size ? 2 : 0);
|
|
65
|
+
if (offset < prefix.length) packet.set(prefix.subarray(offset, end), 1);
|
|
66
|
+
if (end > prefix.length)
|
|
67
|
+
packet.set(
|
|
68
|
+
binary.subarray(
|
|
69
|
+
Math.max(0, offset - prefix.length),
|
|
70
|
+
end - prefix.length,
|
|
71
|
+
),
|
|
72
|
+
1 + Math.max(0, prefix.length - offset),
|
|
73
|
+
);
|
|
74
|
+
const waitStarted = Date.now();
|
|
75
|
+
while (!closed && bufferedAmount() > bufferLimit) {
|
|
76
|
+
if (Date.now() - waitStarted >= 30000)
|
|
77
|
+
throw new Error("直连发送超时");
|
|
78
|
+
await new Promise((resolve) => setTimeout(resolve, 8));
|
|
79
|
+
}
|
|
80
|
+
if (closed) throw new Error("直连已断开");
|
|
81
|
+
sendFrame(packet);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
pending = operation.catch(fail).finally(() => {
|
|
85
|
+
queuedBytes -= size;
|
|
86
|
+
});
|
|
87
|
+
return operation;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function frame(input) {
|
|
91
|
+
if (closed) return;
|
|
92
|
+
try {
|
|
93
|
+
if (!(input instanceof ArrayBuffer) && !ArrayBuffer.isView(input))
|
|
94
|
+
throw new Error("直连需要二进制帧");
|
|
95
|
+
const packet = ArrayBuffer.isView(input)
|
|
96
|
+
? new Uint8Array(input.buffer, input.byteOffset, input.byteLength)
|
|
97
|
+
: new Uint8Array(input);
|
|
98
|
+
const flags = packet[0];
|
|
99
|
+
if (
|
|
100
|
+
packet.length < 2 ||
|
|
101
|
+
packet.length > frameSize ||
|
|
102
|
+
flags > 3 ||
|
|
103
|
+
Boolean(flags & 1) === Boolean(incoming)
|
|
104
|
+
)
|
|
105
|
+
throw new Error("无效的直连帧顺序");
|
|
106
|
+
let body = packet.subarray(1);
|
|
107
|
+
if (flags & 1) {
|
|
108
|
+
const header = new DataView(body.buffer, body.byteOffset, body.length);
|
|
109
|
+
const jsonLength = header.getUint32(0);
|
|
110
|
+
const binaryLength = header.getUint32(4);
|
|
111
|
+
if (
|
|
112
|
+
jsonLength < 2 ||
|
|
113
|
+
jsonLength > maxJsonBytes ||
|
|
114
|
+
binaryLength > MAX_RPC_MESSAGE_BYTES ||
|
|
115
|
+
jsonLength + binaryLength > (maxInboundBytes?.() ?? Infinity)
|
|
116
|
+
)
|
|
117
|
+
throw new Error("无效的直连消息长度");
|
|
118
|
+
incoming = {
|
|
119
|
+
payload: new Uint8Array(jsonLength + binaryLength),
|
|
120
|
+
offset: 0,
|
|
121
|
+
jsonLength,
|
|
122
|
+
};
|
|
123
|
+
deadline = setTimeout(() => fail(new Error("直连接收超时")), 120000);
|
|
124
|
+
body = body.subarray(8);
|
|
125
|
+
}
|
|
126
|
+
const { payload, offset, jsonLength } = incoming;
|
|
127
|
+
if (
|
|
128
|
+
offset + body.length > payload.length ||
|
|
129
|
+
Boolean(flags & 2) !== (offset + body.length === payload.length)
|
|
130
|
+
)
|
|
131
|
+
throw new Error("无效的直连消息边界");
|
|
132
|
+
payload.set(body, offset);
|
|
133
|
+
incoming.offset += body.length;
|
|
134
|
+
if (flags & 2) {
|
|
135
|
+
incoming = null;
|
|
136
|
+
clearTimeout(deadline);
|
|
137
|
+
const message = JSON.parse(
|
|
138
|
+
decoder.decode(payload.subarray(0, jsonLength)),
|
|
139
|
+
);
|
|
140
|
+
if (!message || typeof message.type !== "string")
|
|
141
|
+
throw new Error("无效的直连消息类型");
|
|
142
|
+
const binary = payload.subarray(jsonLength);
|
|
143
|
+
if (message.type === "rpc")
|
|
144
|
+
receive({ type: "rpc", text: decoder.decode(binary) });
|
|
145
|
+
else {
|
|
146
|
+
if (binary.length > MAX_P2P_BODY_BYTES)
|
|
147
|
+
throw new Error("直连请求超过大小限制");
|
|
148
|
+
receive(message, binary);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
fail(error);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return { send, frame, close: shutdown };
|
|
157
|
+
}
|