@cjhyy/code-shell-server 0.8.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/README.md +77 -0
- package/dist/attachment-service.d.ts +80 -0
- package/dist/attachment-service.js +587 -0
- package/dist/bin/code-shell-serve.d.ts +2 -0
- package/dist/bin/code-shell-serve.js +7 -0
- package/dist/client-message-id.d.ts +1 -0
- package/dist/client-message-id.js +8 -0
- package/dist/image-byte-probe.d.ts +17 -0
- package/dist/image-byte-probe.js +330 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/index.mobile-remote.d.ts +21 -0
- package/dist/index.mobile-remote.js +21 -0
- package/dist/index.serve.d.ts +3 -0
- package/dist/index.serve.js +3 -0
- package/dist/index.storage.d.ts +10 -0
- package/dist/index.storage.js +10 -0
- package/dist/index.worker.d.ts +2 -0
- package/dist/index.worker.js +2 -0
- package/dist/mobile-remote/access-passcode.d.ts +80 -0
- package/dist/mobile-remote/access-passcode.js +354 -0
- package/dist/mobile-remote/cloudflared-binary.d.ts +76 -0
- package/dist/mobile-remote/cloudflared-binary.js +242 -0
- package/dist/mobile-remote/codex-parse.d.ts +34 -0
- package/dist/mobile-remote/codex-parse.js +131 -0
- package/dist/mobile-remote/codex-room-agent.d.ts +94 -0
- package/dist/mobile-remote/codex-room-agent.js +213 -0
- package/dist/mobile-remote/mobile-attachments.d.ts +21 -0
- package/dist/mobile-remote/mobile-attachments.js +119 -0
- package/dist/mobile-remote/mobile-chat-turn.d.ts +32 -0
- package/dist/mobile-remote/mobile-chat-turn.js +67 -0
- package/dist/mobile-remote/mobile-history.d.ts +22 -0
- package/dist/mobile-remote/mobile-history.js +27 -0
- package/dist/mobile-remote/mobile-run-dispatch.d.ts +17 -0
- package/dist/mobile-remote/mobile-run-dispatch.js +56 -0
- package/dist/mobile-remote/mobile-static.d.ts +43 -0
- package/dist/mobile-remote/mobile-static.js +154 -0
- package/dist/mobile-remote/mobile-upload-service.d.ts +57 -0
- package/dist/mobile-remote/mobile-upload-service.js +370 -0
- package/dist/mobile-remote/pairing.d.ts +8 -0
- package/dist/mobile-remote/pairing.js +23 -0
- package/dist/mobile-remote/path-bins.d.ts +7 -0
- package/dist/mobile-remote/path-bins.js +16 -0
- package/dist/mobile-remote/pending-approvals.d.ts +14 -0
- package/dist/mobile-remote/pending-approvals.js +54 -0
- package/dist/mobile-remote/remote-host-manager.d.ts +117 -0
- package/dist/mobile-remote/remote-host-manager.js +345 -0
- package/dist/mobile-remote/resident-agent.d.ts +98 -0
- package/dist/mobile-remote/resident-agent.js +216 -0
- package/dist/mobile-remote/room-manager.d.ts +286 -0
- package/dist/mobile-remote/room-manager.js +765 -0
- package/dist/mobile-remote/trusted-device-store.d.ts +19 -0
- package/dist/mobile-remote/trusted-device-store.js +118 -0
- package/dist/mobile-remote/tunnel-manager.d.ts +105 -0
- package/dist/mobile-remote/tunnel-manager.js +375 -0
- package/dist/mobile-remote/types.d.ts +1 -0
- package/dist/mobile-remote/types.js +1 -0
- package/dist/mobile-remote/viewer-identity.d.ts +5 -0
- package/dist/mobile-remote/viewer-identity.js +5 -0
- package/dist/serve/cli.d.ts +15 -0
- package/dist/serve/cli.js +115 -0
- package/dist/serve/headless-server.d.ts +40 -0
- package/dist/serve/headless-server.js +276 -0
- package/dist/sessions-service.d.ts +73 -0
- package/dist/sessions-service.js +303 -0
- package/dist/static-files.d.ts +1 -0
- package/dist/static-files.js +25 -0
- package/dist/worker-bridge-core.d.ts +154 -0
- package/dist/worker-bridge-core.js +315 -0
- package/package.json +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @cjhyy/code-shell-server
|
|
2
|
+
|
|
3
|
+
CodeShell 服务端传输层(纯 Node、零 Electron):mobile remote 的 HTTP/WS host、配对、passcode 门、tunnel、rooms、上传,以及 **headless 无账号 Web host(`code-shell-serve`)**。
|
|
4
|
+
|
|
5
|
+
## 聚焦入口
|
|
6
|
+
|
|
7
|
+
宿主代码应选择职责最窄的稳定入口:
|
|
8
|
+
|
|
9
|
+
| 入口 | 职责 |
|
|
10
|
+
| ---------------------------------------- | ----------------------------------------------------------------- |
|
|
11
|
+
| `@cjhyy/code-shell-server/storage` | 磁盘 Session、附件暂存、图片探测和稳定 client-message ID |
|
|
12
|
+
| `@cjhyy/code-shell-server/worker` | 与传输无关的 stdio worker 生命周期和行协议桥接 |
|
|
13
|
+
| `@cjhyy/code-shell-server/mobile-remote` | 配对、访问门禁、rooms、上传、LAN/tunnel host 和移动端协议类型 |
|
|
14
|
+
| `@cjhyy/code-shell-server/serve` | Headless HTTP/WebSocket host 与 `code-shell-serve` CLI 组合默认值 |
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { listDiskSessions } from "@cjhyy/code-shell-server/storage";
|
|
18
|
+
import { RemoteHostManager } from "@cjhyy/code-shell-server/mobile-remote";
|
|
19
|
+
import { WorkerBridgeCore } from "@cjhyy/code-shell-server/worker";
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
包根入口仍是四个入口的兼容并集。新消费方应避免根入口,以免只使用 storage
|
|
23
|
+
或 transport 时也求值无关的宿主组合。
|
|
24
|
+
|
|
25
|
+
`/storage`、`/worker` 和 `/mobile-remote` 没有 Coding/Web 静态导入。外部
|
|
26
|
+
Agent 策略由产品宿主通过 `ResidentAgentOptions.appendSystemPrompt` 注入。
|
|
27
|
+
`/serve` 则是有意保留的开箱即用产品入口:CLI 被调用时解析 Coding stdio
|
|
28
|
+
worker 和已构建的 Web app。
|
|
29
|
+
|
|
30
|
+
## code-shell-serve — 无账号 Web host
|
|
31
|
+
|
|
32
|
+
在任意机器上把一个 workspace 变成浏览器可访问的 CodeShell:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# 构建(repo 内):core → coding → server → web app
|
|
36
|
+
bun run build && bun run --cwd packages/web build:app
|
|
37
|
+
|
|
38
|
+
# 启动
|
|
39
|
+
node packages/server/dist/bin/code-shell-serve.js \
|
|
40
|
+
--cwd ~/work/my-repo \
|
|
41
|
+
--port 8790 \
|
|
42
|
+
--passcode <你的口令> # 省略则首次启动生成随机口令并打印一次
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
浏览器打开 `http://127.0.0.1:8790`:输入口令(记住 cookie 后不再询问)→ 会话列表 / 新建对话 / 流式输出 / 工具审批 / 停止。
|
|
46
|
+
|
|
47
|
+
### 架构
|
|
48
|
+
|
|
49
|
+
```text
|
|
50
|
+
浏览器 SPA(packages/web dist-app,说 core JSON-RPC 协议)
|
|
51
|
+
│ WS /ws(passcode/cookie 门禁)
|
|
52
|
+
headless serve(本包 serve/)
|
|
53
|
+
│ stdio line-JSON-RPC(WorkerBridgeCore:按需 spawn、崩溃记账)
|
|
54
|
+
agent-server-stdio worker(@cjhyy/code-shell-capability-coding)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
- 浏览器是 core 协议的一等前端(`agent/run` / `agent/streamEvent` / `agent/approvalRequest` / `agent/approve` / `agent/cancel`),serve 只是一根经过认证的薄管道;所有已认证 tab 看到同一条事件流。
|
|
58
|
+
- **访问控制只有 passcode + remember-cookie**(决策见 TODO 约束边界「服务端部署不做账号体系」):scrypt 哈希存储、防爆破锁定、轮换口令使所有旧 cookie 失效。无注册登录、无多用户。
|
|
59
|
+
- 默认只绑 `127.0.0.1`;`--host 0.0.0.0` 暴露到局域网是运维者的显式选择。公网建议走反向代理/tunnel 终结 TLS。
|
|
60
|
+
- 会话持久在磁盘(worker 的数据目录);serve 或 worker 重启后浏览器重连即恢复列表,worker 在下一条消息时按需重启。
|
|
61
|
+
|
|
62
|
+
### CLI 参数
|
|
63
|
+
|
|
64
|
+
| 参数 | 默认 | 说明 |
|
|
65
|
+
| --------------- | --------------------- | ---------------------- |
|
|
66
|
+
| `--cwd` | 当前目录 | worker 的 workspace 根 |
|
|
67
|
+
| `--port` | 8790 | 监听端口 |
|
|
68
|
+
| `--host` | 127.0.0.1 | 监听地址 |
|
|
69
|
+
| `--passcode` | (生成) | 设置/轮换访问口令 |
|
|
70
|
+
| `--data-dir` | `~/.code-shell/serve` | access.json 位置 |
|
|
71
|
+
| `--static-root` | 自动解析 web dist-app | 覆盖静态资源目录 |
|
|
72
|
+
|
|
73
|
+
### Web 客户端开发
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
bun run --cwd packages/web dev:app # vite dev server,/ws 代理到 127.0.0.1:8790
|
|
77
|
+
```
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export type InputAttachmentKind = "image" | "file" | "directory";
|
|
2
|
+
export type InputAttachmentOrigin = "paste" | "os-drop" | "file-panel" | "picker" | "mention" | "generated" | "mobile" | "im-gateway" | "tool";
|
|
3
|
+
export interface InputAttachmentMeta {
|
|
4
|
+
id: string;
|
|
5
|
+
sessionId: string;
|
|
6
|
+
kind: InputAttachmentKind;
|
|
7
|
+
origin: InputAttachmentOrigin;
|
|
8
|
+
path: string;
|
|
9
|
+
absPath: string;
|
|
10
|
+
relPath?: string;
|
|
11
|
+
mime?: string;
|
|
12
|
+
size: number;
|
|
13
|
+
sha256: string;
|
|
14
|
+
originalName?: string;
|
|
15
|
+
createdAt: number;
|
|
16
|
+
sourcePath?: string;
|
|
17
|
+
width?: number;
|
|
18
|
+
height?: number;
|
|
19
|
+
vision?: {
|
|
20
|
+
include: boolean;
|
|
21
|
+
mediaPath?: string;
|
|
22
|
+
detail?: "low" | "standard" | "high";
|
|
23
|
+
};
|
|
24
|
+
directory?: {
|
|
25
|
+
treePath?: string;
|
|
26
|
+
truncated?: boolean;
|
|
27
|
+
entryCount?: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface StageImageDataUrlInput {
|
|
31
|
+
cwd: string;
|
|
32
|
+
sessionId: string;
|
|
33
|
+
name?: string;
|
|
34
|
+
mime?: string;
|
|
35
|
+
dataUrl: string;
|
|
36
|
+
origin: InputAttachmentOrigin;
|
|
37
|
+
}
|
|
38
|
+
export interface StageImageBytesInput {
|
|
39
|
+
cwd: string;
|
|
40
|
+
sessionId: string;
|
|
41
|
+
name?: string;
|
|
42
|
+
mime: string;
|
|
43
|
+
bytes?: Uint8Array;
|
|
44
|
+
sourceFile?: string;
|
|
45
|
+
origin: InputAttachmentOrigin;
|
|
46
|
+
}
|
|
47
|
+
export interface StageFileBytesInput {
|
|
48
|
+
cwd: string;
|
|
49
|
+
sessionId: string;
|
|
50
|
+
name?: string;
|
|
51
|
+
mime?: string;
|
|
52
|
+
bytes: Uint8Array;
|
|
53
|
+
origin: InputAttachmentOrigin;
|
|
54
|
+
}
|
|
55
|
+
export interface AttachmentCleanupInput {
|
|
56
|
+
cwd: string;
|
|
57
|
+
sessionId?: string;
|
|
58
|
+
now?: number;
|
|
59
|
+
}
|
|
60
|
+
export interface AttachmentInspectInput {
|
|
61
|
+
cwd: string;
|
|
62
|
+
sessionId?: string;
|
|
63
|
+
}
|
|
64
|
+
export declare const DRAFT_ATTACHMENT_TTL_MS: number;
|
|
65
|
+
export declare const SENT_ATTACHMENT_TTL_MS: number;
|
|
66
|
+
export declare const MAX_STAGED_IMAGE_BYTES: number;
|
|
67
|
+
export declare const MAX_STAGED_FILE_BYTES: number;
|
|
68
|
+
export declare function stageImageDataUrl(input: StageImageDataUrlInput): Promise<InputAttachmentMeta>;
|
|
69
|
+
/** Stage already-transferred bytes without expanding them back through base64. */
|
|
70
|
+
export declare function stageImageBytes(input: StageImageBytesInput): Promise<InputAttachmentMeta>;
|
|
71
|
+
/** Stage an untrusted non-image file inside the canonical attachment root. */
|
|
72
|
+
export declare function stageFileBytes(input: StageFileBytesInput): Promise<InputAttachmentMeta>;
|
|
73
|
+
export declare function markAttachmentsSent(cwd: string, sessionId: string, attachments: InputAttachmentMeta[]): Promise<void>;
|
|
74
|
+
export declare function listRecentAttachments(input: AttachmentInspectInput): Promise<InputAttachmentMeta[]>;
|
|
75
|
+
export declare function cleanupAttachments(input: AttachmentCleanupInput): Promise<{
|
|
76
|
+
removed: string[];
|
|
77
|
+
sessionsRemoved: string[];
|
|
78
|
+
}>;
|
|
79
|
+
export declare function cleanupSessionAttachments(cwd: string, sessionId: string): Promise<void>;
|
|
80
|
+
export declare function assertSafeSessionId(sessionId: unknown): asserts sessionId is string;
|