homeagent-runner 0.4.18 → 0.4.19
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/CHANGELOG.md +12 -0
- package/README.md +6 -6
- package/README.zh-CN.md +22 -22
- package/dist/shared/protocol.js +1 -1
- package/docs/ARCHITECTURE.md +46 -44
- package/docs/ARCHITECTURE.zh-CN.md +102 -0
- package/docs/CLIENTS.md +38 -36
- package/docs/CLIENTS.zh-CN.md +132 -0
- package/docs/COMPARISON.md +24 -22
- package/docs/COMPARISON.zh-CN.md +38 -0
- package/docs/DEPLOYMENT.md +119 -106
- package/docs/DEPLOYMENT.zh-CN.md +316 -0
- package/docs/DEVELOPMENT_WORKFLOW.md +41 -39
- package/docs/DEVELOPMENT_WORKFLOW.zh-CN.md +128 -0
- package/docs/OPEN_SOURCE.md +69 -65
- package/docs/OPEN_SOURCE.zh-CN.md +133 -0
- package/docs/README.md +24 -20
- package/docs/README.zh-CN.md +31 -0
- package/docs/REMOTE_ASSIST.md +31 -29
- package/docs/REMOTE_ASSIST.zh-CN.md +48 -0
- package/docs/TOOLS.md +86 -84
- package/docs/TOOLS.zh-CN.md +122 -0
- package/docs/VALIDATION.md +114 -107
- package/docs/VALIDATION.zh-CN.md +179 -0
- package/docs/WEBCODEX_CODE_AUDIT.md +81 -79
- package/docs/WEBCODEX_CODE_AUDIT.zh-CN.md +109 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.19 — XAuth OIDC administrator login and sole-administrator binding
|
|
4
|
+
|
|
5
|
+
- Add optional self-hosted [XAuth](https://github.com/jhxxr/XAuth) OIDC administrator
|
|
6
|
+
login (`XAUTH_ISSUER`, `XAUTH_CLIENT_ID`, `XAUTH_CLIENT_SECRET`) with `S256` PKCE,
|
|
7
|
+
server-stored signed state, nonce validation, JWKS caching/rotation and `RS256` ID
|
|
8
|
+
token verification, supporting XAuth-only or dual XAuth + `ADMIN_PASSWORD` sign-in.
|
|
9
|
+
- Automatically bind the first authenticated XAuth account (`sub`) in SQLite as the
|
|
10
|
+
workspace's sole administrator and reject all subsequent XAuth accounts (`403`),
|
|
11
|
+
surfacing the bound administrator identity and session auth method in the Dashboard.
|
|
12
|
+
- Provide aligned English and Simplified Chinese documentation across all 11 guides
|
|
13
|
+
under `docs/` alongside `README.md` and `README.zh-CN.md`.
|
|
14
|
+
|
|
3
15
|
## 0.4.18 — Windows PowerShell persistent shell bootstrap
|
|
4
16
|
|
|
5
17
|
- Initialize persistent Windows PowerShell sessions with an explicit `-NonInteractive -EncodedCommand`
|
package/README.md
CHANGED
|
@@ -59,8 +59,8 @@ flowchart TB
|
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
- **Protocol Compatibility**: Built on the official MCP SDK v2 (`Streamable HTTP` at `/mcp`), supporting both `2026-07-28` discovery/envelopes and `2025` legacy protocol clients.
|
|
62
|
-
- **Authentication**: Supports OAuth 2.1 authorization-code flow with `S256` PKCE, scoped Personal Access Tokens (`Bearer`), and one-time browser or pairing-code device enrollment.
|
|
63
|
-
- **Release Scope**: Current release **v0.4.
|
|
62
|
+
- **Authentication**: Supports Web Dashboard sign-in via admin password or [XAuth](https://github.com/jhxxr/XAuth) OIDC (binding the first XAuth account as the sole administrator), plus OAuth 2.1 authorization-code flow with `S256` PKCE, scoped Personal Access Tokens (`Bearer`), and one-time browser or pairing-code device enrollment.
|
|
63
|
+
- **Release Scope**: Current release **v0.4.19** supports a single administrator and multiple devices/projects. Persistent interactive PTY shells, detached jobs surviving runner replacement, automatic worktree registration, and preview tunnels are intentionally out of scope.
|
|
64
64
|
|
|
65
65
|
## Interface Preview
|
|
66
66
|
|
|
@@ -116,7 +116,7 @@ Follow this sequence: **1. Deploy the Server → 2. Pair a Runner → 3. Connect
|
|
|
116
116
|
Requires Docker Engine, Docker Compose v2, and Git. Point your domain's DNS record to the server and open inbound TCP ports `80` and `443`. Replace `mcp.example.com` below with your own domain:
|
|
117
117
|
|
|
118
118
|
```sh
|
|
119
|
-
git clone --branch v0.4.
|
|
119
|
+
git clone --branch v0.4.19 --depth 1 https://github.com/jhxxr/HomeAgent.git
|
|
120
120
|
cd HomeAgent
|
|
121
121
|
|
|
122
122
|
# Generate random ADMIN_PASSWORD and SESSION_SECRET in .env without installing Node.js on the host
|
|
@@ -155,7 +155,7 @@ homeagent-server
|
|
|
155
155
|
```
|
|
156
156
|
|
|
157
157
|
- **Local Access**: Open `http://localhost:3210` and sign in using the `ADMIN_PASSWORD` written to `.env` in the current working directory. SQLite data is stored at `data/server.sqlite`.
|
|
158
|
-
- **Public Access**: Set `PUBLIC_URL=https://mcp.example.com` and `TRUST_PROXY_HOPS=1` in `.env`, then reverse-proxy traffic to `127.0.0.1:3210`. Use `systemd` or a process manager for background execution (see [Native Server Deployment](docs/DEPLOYMENT.md
|
|
158
|
+
- **Public Access**: Set `PUBLIC_URL=https://mcp.example.com` and `TRUST_PROXY_HOPS=1` in `.env`, then reverse-proxy traffic to `127.0.0.1:3210`. Use `systemd` or a process manager for background execution (see [Native Server Deployment](docs/DEPLOYMENT.md#native-server-deployment)).
|
|
159
159
|
|
|
160
160
|
### 2. Install & Pair a Runner
|
|
161
161
|
|
|
@@ -189,7 +189,7 @@ homeagent
|
|
|
189
189
|
|
|
190
190
|
- **OAuth 2.1**: Point your MCP client to `https://mcp.example.com/mcp` and approve the requested device, project, and scope permissions in your browser.
|
|
191
191
|
- **Personal Access Token (`Bearer`)**: Issue a scoped token (`read`, `write`, `execute`, `git`) in the Dashboard and configure your client with `Authorization: Bearer <token>`.
|
|
192
|
-
- **Version Alignment**: Keep `homeagent-server` and `homeagent-runner` on the same release (`v0.4.
|
|
192
|
+
- **Version Alignment**: Keep `homeagent-server` and `homeagent-runner` on the same release (`v0.4.19`). Check versions anytime with `homeagent-server --version`, `homeagent --version`, or in the Dashboard header.
|
|
193
193
|
- **Client Guides**: See [Connecting AI Clients](docs/CLIENTS.md) for step-by-step instructions across Claude, ChatGPT, Cursor, and the MCP SDK.
|
|
194
194
|
|
|
195
195
|
## AI Prompting Guide
|
|
@@ -299,7 +299,7 @@ runtime/ # Windows Job Object process-tree supervisor sources
|
|
|
299
299
|
licenses/ # Locked runtime dependency license notices
|
|
300
300
|
```
|
|
301
301
|
|
|
302
|
-
*Note: Detailed operational guides in `docs/` are
|
|
302
|
+
*Note: Detailed operational guides in `docs/` are available in both English (canonical, unsuffixed files) and Simplified Chinese (`.zh-CN.md` files), using identical CLI commands and configuration keys across platforms.*
|
|
303
303
|
|
|
304
304
|
| Guide | Description |
|
|
305
305
|
| --- | --- |
|
package/README.zh-CN.md
CHANGED
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
<a href="#ai-远程开发教程与提示词模板">提示词教程</a> ·
|
|
27
27
|
<a href="#远程协助">远程协助</a> ·
|
|
28
28
|
<a href="#mcp-工具">MCP 工具</a> ·
|
|
29
|
-
<a href="docs/DEPLOYMENT.md">部署指南</a> ·
|
|
30
|
-
<a href="docs/CLIENTS.md">AI 客户端</a> ·
|
|
31
|
-
<a href="docs/README.md">完整文档</a> ·
|
|
29
|
+
<a href="docs/DEPLOYMENT.zh-CN.md">部署指南</a> ·
|
|
30
|
+
<a href="docs/CLIENTS.zh-CN.md">AI 客户端</a> ·
|
|
31
|
+
<a href="docs/README.zh-CN.md">完整文档</a> ·
|
|
32
32
|
<a href="CHANGELOG.md">更新日志</a>
|
|
33
33
|
</p>
|
|
34
34
|
|
|
@@ -59,8 +59,8 @@ flowchart TB
|
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
- **协议兼容**:基于 MCP 官方 SDK v2 实现 Streamable HTTP(`/mcp`),同时支持 `2026-07-28` 发现与信封规范及 `2025` 协议兼容。
|
|
62
|
-
-
|
|
63
|
-
- **版本边界**:当前版本 **v0.4.
|
|
62
|
+
- **认证体系**:控制台支持管理员密码与 [XAuth](https://github.com/jhxxr/XAuth) OIDC 登录(首个登录的 XAuth 账号自动绑定为唯一管理员);客户端支持带 `S256` PKCE 的 OAuth 2.1 授权码流程、按范围受限的 Bearer 令牌(PAT),以及浏览器/配对码一次性设备绑定。
|
|
63
|
+
- **版本边界**:当前版本 **v0.4.19** 支持单管理员、多设备与多项目。持久交互式 PTY 终端、跨 Runner 重启保留脱离进程、自动 worktree 注册及预览隧道不在当前实现范围内。
|
|
64
64
|
|
|
65
65
|
## 界面预览
|
|
66
66
|
|
|
@@ -116,7 +116,7 @@ Server 与 Runner 拆分为两个独立的 npm 包,分别安装在中继服务
|
|
|
116
116
|
准备 Docker Engine、Docker Compose v2 和 Git,将域名解析到服务器并放行 TCP `80` / `443` 端口。将下方示例中的 `mcp.example.com` 替换为你的域名:
|
|
117
117
|
|
|
118
118
|
```sh
|
|
119
|
-
git clone --branch v0.4.
|
|
119
|
+
git clone --branch v0.4.19 --depth 1 https://github.com/jhxxr/HomeAgent.git
|
|
120
120
|
cd HomeAgent
|
|
121
121
|
|
|
122
122
|
# 使用容器生成随机密码和会话密钥,无需在宿主机安装 Node.js
|
|
@@ -141,7 +141,7 @@ docker compose --profile proxy ps
|
|
|
141
141
|
curl --fail https://mcp.example.com/health
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
-
Caddy 会自动申请 TLS 证书并代理 HTTP 与 WebSocket。浏览器打开 `https://mcp.example.com`,使用 `.env` 中的 `ADMIN_PASSWORD` 登录控制台。`3210` 端口仅绑定宿主机 `127.0.0.1`,SQLite 数据保存在 `server-data` 命名卷中。备份、升级与现有 Nginx 反代配置详见 [部署指南](docs/DEPLOYMENT.md)。
|
|
144
|
+
Caddy 会自动申请 TLS 证书并代理 HTTP 与 WebSocket。浏览器打开 `https://mcp.example.com`,使用 `.env` 中的 `ADMIN_PASSWORD` 登录控制台。`3210` 端口仅绑定宿主机 `127.0.0.1`,SQLite 数据保存在 `server-data` 命名卷中。备份、升级与现有 Nginx 反代配置详见 [部署指南](docs/DEPLOYMENT.zh-CN.md)。
|
|
145
145
|
|
|
146
146
|
#### 方式 B:npm 原生运行(适合 Linux / Windows 本机试用或已有 Node.js 环境)
|
|
147
147
|
|
|
@@ -155,7 +155,7 @@ homeagent-server
|
|
|
155
155
|
```
|
|
156
156
|
|
|
157
157
|
- **本机访问**:打开 `http://localhost:3210`,管理员密码位于当前目录 `.env` 的 `ADMIN_PASSWORD` 中,SQLite 默认保存在 `data/server.sqlite`。
|
|
158
|
-
- **公网访问**:将 `.env` 中的 `PUBLIC_URL` 改为固定 HTTPS 域名并设置 `TRUST_PROXY_HOPS=1`,再通过 Nginx / Caddy 反代至 `127.0.0.1:3210`。长期后台运行可配置 `systemd`(见 [原生部署 Server](docs/DEPLOYMENT.md#原生部署-server))。
|
|
158
|
+
- **公网访问**:将 `.env` 中的 `PUBLIC_URL` 改为固定 HTTPS 域名并设置 `TRUST_PROXY_HOPS=1`,再通过 Nginx / Caddy 反代至 `127.0.0.1:3210`。长期后台运行可配置 `systemd`(见 [原生部署 Server](docs/DEPLOYMENT.zh-CN.md#原生部署-server))。
|
|
159
159
|
|
|
160
160
|
### 2. 安装并配对 Runner
|
|
161
161
|
|
|
@@ -189,8 +189,8 @@ homeagent
|
|
|
189
189
|
|
|
190
190
|
- **OAuth 2.1 连接**:在 MCP 客户端填入 `https://mcp.example.com/mcp`,在弹出的浏览器页面中勾选允许访问的设备、项目与权限范围。
|
|
191
191
|
- **Bearer 令牌(PAT)连接**:在控制台为已配对设备签发指定 `read / write / execute / git` 范围的客户端令牌,并以 `Authorization: Bearer <token>` 方式接入。
|
|
192
|
-
- **版本一致性**:升级时请保持 `homeagent-server` 与 `homeagent-runner` 版本一致(`v0.4.
|
|
193
|
-
- **客户端配置详情**:各客户端完整接入步骤见 [AI 客户端连接指南](docs/CLIENTS.md)。
|
|
192
|
+
- **版本一致性**:升级时请保持 `homeagent-server` 与 `homeagent-runner` 版本一致(`v0.4.19`),可通过 `homeagent-server --version`、`homeagent --version` 或控制台顶部查看。
|
|
193
|
+
- **客户端配置详情**:各客户端完整接入步骤见 [AI 客户端连接指南](docs/CLIENTS.zh-CN.md)。
|
|
194
194
|
|
|
195
195
|
## AI 远程开发教程与提示词模板
|
|
196
196
|
|
|
@@ -259,7 +259,7 @@ homeagent
|
|
|
259
259
|
homeagent assist "https://mcp.example.com/assist#id=...&token=..."
|
|
260
260
|
```
|
|
261
261
|
3. **本机逐项审批**:设备持有人在本地 Runner 中添加 **1–16 个项目目录**,逐项目设置只读/文件写入与可执行程序白名单,并选择统一时长(30 分钟 / 2 小时 / 8 小时)。
|
|
262
|
-
4. **随时立即停止**:仅在本机最终批准后才开放访问;本机点击「立即停止」、退出、到期或断线都会立刻终止全部托管任务并收回访问。详见 [远程协助指南](docs/REMOTE_ASSIST.md)。
|
|
262
|
+
4. **随时立即停止**:仅在本机最终批准后才开放访问;本机点击「立即停止」、退出、到期或断线都会立刻终止全部托管任务并收回访问。详见 [远程协助指南](docs/REMOTE_ASSIST.zh-CN.md)。
|
|
263
263
|
|
|
264
264
|
## MCP 工具
|
|
265
265
|
|
|
@@ -273,7 +273,7 @@ homeagent
|
|
|
273
273
|
| **进程与持久终端** | `start_process`, `run_command`, `wait_process`, `read_process_output`, `tail_process_output`, `write_process_input`, `list_processes`, `stop_process`, `start_shell`, `run_shell`, `list_shells`, `stop_shell` |
|
|
274
274
|
| **Git 工作流** | `git_status`, `git_diff`, `git_log`, `git_add`, `git_commit`, `git_commit_paths`, `git_branches`, `git_switch_branch`, `git_fetch`, `git_pull`, `git_push` |
|
|
275
275
|
|
|
276
|
-
所有机器工具均通过 `projectId` 指定项目(当多台已授权设备同时在线时还须指定 `deviceId`)。进程采用由启动客户端主体和项目共同拥有的任务 UUID(不接受任意系统 PID),并通过 Linux 进程组或 Windows Job Object 管理子孙进程。详见 [日常开发工作流](docs/DEVELOPMENT_WORKFLOW.md) 与 [工具参考](docs/TOOLS.md)。
|
|
276
|
+
所有机器工具均通过 `projectId` 指定项目(当多台已授权设备同时在线时还须指定 `deviceId`)。进程采用由启动客户端主体和项目共同拥有的任务 UUID(不接受任意系统 PID),并通过 Linux 进程组或 Windows Job Object 管理子孙进程。详见 [日常开发工作流](docs/DEVELOPMENT_WORKFLOW.zh-CN.md) 与 [工具参考](docs/TOOLS.zh-CN.md)。
|
|
277
277
|
|
|
278
278
|
### 双层 Web 权限管理
|
|
279
279
|
|
|
@@ -301,16 +301,16 @@ licenses/ # 锁定的生产依赖许可证文本
|
|
|
301
301
|
|
|
302
302
|
| 文档 | 说明 |
|
|
303
303
|
| --- | --- |
|
|
304
|
-
| [文档索引](docs/README.md) | 全部使用、运维、安全与设计文档总览 |
|
|
305
|
-
| [部署与运维](docs/DEPLOYMENT.md) | Docker Compose、Caddy、Nginx、Cloudflare Tunnel、配对、自启动与备份恢复 |
|
|
306
|
-
| [AI 客户端连接](docs/CLIENTS.md) | Claude、ChatGPT、Cursor 及 MCP SDK 接入指南 |
|
|
307
|
-
| [日常开发工作流](docs/DEVELOPMENT_WORKFLOW.md) | 命令别名与环境配置、按行读取、多文件原子编辑、恢复日志与工作流边界 |
|
|
308
|
-
| [远程协助指南](docs/REMOTE_ASSIST.md) | 一次性邀请、多项目本机审批、独立到期与安全边界 |
|
|
309
|
-
| [工具与配置参考](docs/TOOLS.md) | 工具参数、Scope、分页限额与管理端 API |
|
|
310
|
-
| [架构与技术选型](docs/ARCHITECTURE.md) | 模块划分、信任边界、消息协议、持久化与并发控制 |
|
|
304
|
+
| [文档索引](docs/README.zh-CN.md) | 全部使用、运维、安全与设计文档总览 |
|
|
305
|
+
| [部署与运维](docs/DEPLOYMENT.zh-CN.md) | Docker Compose、Caddy、Nginx、Cloudflare Tunnel、配对、自启动与备份恢复 |
|
|
306
|
+
| [AI 客户端连接](docs/CLIENTS.zh-CN.md) | Claude、ChatGPT、Cursor 及 MCP SDK 接入指南 |
|
|
307
|
+
| [日常开发工作流](docs/DEVELOPMENT_WORKFLOW.zh-CN.md) | 命令别名与环境配置、按行读取、多文件原子编辑、恢复日志与工作流边界 |
|
|
308
|
+
| [远程协助指南](docs/REMOTE_ASSIST.zh-CN.md) | 一次性邀请、多项目本机审批、独立到期与安全边界 |
|
|
309
|
+
| [工具与配置参考](docs/TOOLS.zh-CN.md) | 工具参数、Scope、分页限额与管理端 API |
|
|
310
|
+
| [架构与技术选型](docs/ARCHITECTURE.zh-CN.md) | 模块划分、信任边界、消息协议、持久化与并发控制 |
|
|
311
311
|
| [安全模型](SECURITY.md) | 命令执行的真实权限边界、默认限制与漏洞报告方式 |
|
|
312
|
-
| [验证记录](docs/VALIDATION.md) | 已执行的自动化验证与环境验收范围 |
|
|
313
|
-
| [参考项目对比](docs/COMPARISON.md) 与 [源码审计](docs/WEBCODEX_CODE_AUDIT.md) | 与参考项目的架构对比及 29 个工具域逐项映射 |
|
|
312
|
+
| [验证记录](docs/VALIDATION.zh-CN.md) | 已执行的自动化验证与环境验收范围 |
|
|
313
|
+
| [参考项目对比](docs/COMPARISON.zh-CN.md) 与 [源码审计](docs/WEBCODEX_CODE_AUDIT.zh-CN.md) | 与参考项目的架构对比及 29 个工具域逐项映射 |
|
|
314
314
|
|
|
315
315
|
## 源码开发与验证
|
|
316
316
|
|
|
@@ -333,7 +333,7 @@ npm run notices:check
|
|
|
333
333
|
npm audit --omit=dev --audit-level=high
|
|
334
334
|
```
|
|
335
335
|
|
|
336
|
-
开发规范详见 [CONTRIBUTING.md](CONTRIBUTING.md),源码归档与双包 npm 发布检查详见 [开源与发布检查](docs/OPEN_SOURCE.md)。
|
|
336
|
+
开发规范详见 [CONTRIBUTING.md](CONTRIBUTING.md),源码归档与双包 npm 发布检查详见 [开源与发布检查](docs/OPEN_SOURCE.zh-CN.md)。
|
|
337
337
|
|
|
338
338
|
## 安全说明与许可证
|
|
339
339
|
|
package/dist/shared/protocol.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { remotePermissionsSchema } from './permissions.js';
|
|
3
3
|
import { assistContextSchema, assistDescriptorSchema, assistMultiDescriptorSchema, assistCleanupSchema, ASSIST_FEATURE, ASSIST_MULTI_FEATURE } from './assist.js';
|
|
4
|
-
export const VERSION = '0.4.
|
|
4
|
+
export const VERSION = '0.4.19';
|
|
5
5
|
export const RUNNER_PROTOCOL = 2;
|
|
6
6
|
export const MAX_FRAME = 2 * 1024 * 1024;
|
|
7
7
|
export const SCOPES = ['read', 'write', 'execute', 'git'];
|
package/docs/ARCHITECTURE.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Architecture and Technology Choices
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**English** · [简体中文](ARCHITECTURE.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
HomeAgent v0.4.19 builds on the v0.3 context/editor/output-log/patch foundation with a permission protocol, a Dashboard permission editor, controlled Git network tools, fuzzy unified diffs, persistent stateful shell sessions and lightweight LSP integration. The MCP catalogue now contains **45 tools** (44 Zod schemas in `src/shared/tools.ts` plus the separately defined `list_devices`). Device capability ceilings and client authorizations are stored separately; temporary grants expire and trigger job revocation. Execution semantics and persistence/recovery of the newer tools are covered in the [Development Workflow](DEVELOPMENT_WORKFLOW.md).
|
|
6
|
+
|
|
7
|
+
## Data Flow and Trust Boundaries
|
|
6
8
|
|
|
7
9
|
```mermaid
|
|
8
10
|
flowchart LR
|
|
@@ -17,38 +19,38 @@ flowchart LR
|
|
|
17
19
|
P --> G[Git]
|
|
18
20
|
```
|
|
19
21
|
|
|
20
|
-
MCP
|
|
22
|
+
MCP clients cannot call the admin API; device credentials cannot access MCP; a Dashboard cookie cannot act as a Runner credential. A single administrator manages multiple devices, and external clients receive explicit device and scope grants through OAuth or PAT.
|
|
21
23
|
|
|
22
|
-
Server
|
|
24
|
+
Server and Runner are both trusted code. The Runner does not trust paths, tool arguments or scopes from a request: it re-checks the Server-delivered project policy and the real filesystem boundary. The Runner cannot, however, defend against a fully compromised Server forging a principal, so the Server host and database must be protected. Content inside project directories is potentially untrusted input and must never be able to modify Runner configuration or the credential directory.
|
|
23
25
|
|
|
24
|
-
##
|
|
26
|
+
## Technology Choices
|
|
25
27
|
|
|
26
|
-
|
|
|
28
|
+
| Layer | Choice | Rationale and limits |
|
|
27
29
|
| --- | --- | --- |
|
|
28
|
-
|
|
|
29
|
-
| MCP | `@modelcontextprotocol/server` 2.4.0
|
|
30
|
-
| HTTP | Express 5 |
|
|
31
|
-
| Runner
|
|
32
|
-
|
|
|
33
|
-
| Dashboard |
|
|
34
|
-
|
|
|
30
|
+
| Runtime | Node.js 24 LTS, TypeScript strict | Shared Linux/Windows implementation, native process/file APIs, built-in SQLite; minimum 24.14, container pinned to 24.22.1 |
|
|
31
|
+
| MCP | `@modelcontextprotocol/server` 2.4.0, `@modelcontextprotocol/node` 2.1.2 | Official v2 `createMcpHandler`: 2026-07-28 server/discover with per-request envelopes, plus stateless 2025 initialize/tools; the v1 SDK 1.32.2 is retained only for self-hosted OAuth authorization-server helper routes and legacy-client tests |
|
|
32
|
+
| HTTP | Express 5 | Compatible with the SDK OAuth routes; avoids hand-rolled protocol handling |
|
|
33
|
+
| Runner channel | `ws`, TLS terminated by the reverse proxy | Outbound connection, request UUIDs, heartbeats, connection replacement, reconnect, frame-size limits |
|
|
34
|
+
| Data | `node:sqlite` WAL | No separate database service, suited to a personal single node; not designed for shared multi-replica databases |
|
|
35
|
+
| Dashboard | Plain HTML/CSS/JS | No frontend build chain, external CDN, fonts or runtime cloud dependency; 5-second refresh |
|
|
36
|
+
| Deployment | Docker Compose + optional Caddy/Nginx | Same-host, VPS and intranet reverse-proxy setups; Cloudflare is optional and introduces a third-party link |
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
Protocol negotiation is handled by the official v2 serving entry; tool definitions are generated into JSON Schema by Zod. The 2026 path uses server/discover and a per-request `_meta` envelope; the 2025 compatibility path uses initialize. Both create a fresh Server per request and emit no `MCP-Session-Id`. The project advertises tool capabilities only: it does not promise resources, prompts, MCP Apps, sampling or Host continuation. The Dashboard shows client authorizations, administrator login sessions and Runner jobs as distinct concepts; none of them is an upstream Workflow Session. Long-running jobs live on the Runner and do not depend on an HTTP session.
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
References: [MCP transport spec](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports), [MCP authorization spec](https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization), [TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk), [Node.js SQLite](https://nodejs.org/api/sqlite.html).
|
|
39
41
|
|
|
40
|
-
##
|
|
42
|
+
## Modules and Execution Order
|
|
41
43
|
|
|
42
|
-
1. `server/app.ts
|
|
43
|
-
2. `server/hub.ts
|
|
44
|
-
3. `runner/agent.ts
|
|
45
|
-
4. `server/security.ts
|
|
46
|
-
5. `server/jobs.ts
|
|
47
|
-
6. `runner/files.ts
|
|
44
|
+
1. `server/app.ts`, `server/mcp.ts`: HTTP admin API, standard new/legacy MCP entry points, WebSocket upgrade and application lifecycle.
|
|
45
|
+
2. `server/hub.ts`: online devices, authenticated hello, call routing, timeout cancellation, disconnect errors and per-call auditing.
|
|
46
|
+
3. `runner/agent.ts`, `runner/lock.ts`: outbound connection, backoff reconnect, heartbeat monitoring, concurrency limits, OS state-directory lock and local dispatch.
|
|
47
|
+
4. `server/security.ts`, `oauth.ts`, pairing API: cookie/CSRF, DCR, S256 PKCE, resource binding, refresh rotation, one-time device codes.
|
|
48
|
+
5. `server/jobs.ts`, `public/`: persistent job observation, device status, project summaries, pairing, pause/resume/revoke, login sessions, client tokens and audits.
|
|
49
|
+
6. `runner/files.ts`, `processes.ts`, `shells.ts`, `lsp.ts`, `git.ts`: file, long-process, persistent-shell, LSP and Git tools; `policy.ts` performs unified validation.
|
|
48
50
|
|
|
49
|
-
##
|
|
51
|
+
## Internal Protocol
|
|
50
52
|
|
|
51
|
-
Runner
|
|
53
|
+
The Runner protocol version is `2` and older handshakes are rejected. One WebSocket message carries one JSON envelope, at most 2 MiB, with compression disabled. The long-lived device token is used only in the Authorization header of the TLS handshake; the device ID travels in `X-Device-ID`, never in the URL.
|
|
52
54
|
|
|
53
55
|
```json
|
|
54
56
|
{"type":"hello","protocol":2,"name":"workstation","platform":"win32/x64","version":"current","instanceId":"12345678-1234-4234-8234-123456789abc","capabilities":["read_file"],"projects":[]}
|
|
@@ -59,42 +61,42 @@ Runner 协议版本为 `2`,不接受旧版握手,一个 WebSocket 消息对
|
|
|
59
61
|
{"type":"cancel","id":"request-uuid"}
|
|
60
62
|
```
|
|
61
63
|
|
|
62
|
-
Zod
|
|
64
|
+
Zod strictly validates tool arguments and message structure. The Server accepts a result only for a request dispatched to the current connection; another device or a replaced older connection cannot submit that request's result. The Runner allows at most 32 concurrent calls; the Server allows 32 pending calls per device and 256 in total.
|
|
63
65
|
|
|
64
|
-
Runner v0.2
|
|
66
|
+
Since Runner v0.2, the Runner also reports `instanceId`, tool capabilities, `job_update`, and a `jobs_snapshot` of at most 100 items per page and 10,000 items in total. The Server validates snapshot page order, immutable principal/project/admission time, monotonic revision and no regression from terminal state. Only after the snapshot completes can the Dashboard control historical jobs of that exact instance. Metadata excludes argv, raw cwd, output and error bodies. Late events from an old connection cannot overwrite a newer one.
|
|
65
67
|
|
|
66
|
-
WS
|
|
68
|
+
A native WS ping is sent every 15 seconds; a missing pong disconnects. The Runner reconnects proactively after 45 seconds without a heartbeat and must send hello within 10 seconds of connecting. Reconnect uses exponential backoff capped at roughly 30 seconds with jitter. Pausing a device closes the connection and stops hosted jobs; resuming lets the Runner reconnect. Revocation stops automatic connection and requires explicit re-pairing. After a Server disconnect the Runner revokes project access and stops hosted jobs, then re-applies the Server configuration on reconnect.
|
|
67
69
|
|
|
68
|
-
###
|
|
70
|
+
### Permission Synchronization and Revocation
|
|
69
71
|
|
|
70
|
-
Server
|
|
72
|
+
The Server is the single source of truth for device project settings: it stores current projects, permanent fallback projects, the applied revision and application errors. The local connection config accepts no project list or permission switches. On `welcome` or `permissions`, the Runner serially stops active calls and hosted processes, validates every root, protected path, project ID and Git setting, then replies with `permissions_applied`. If application fails, the Runner stays uncallable rather than continuing with the previous, potentially more privileged, configuration.
|
|
71
73
|
|
|
72
|
-
|
|
74
|
+
Every MCP dispatch re-resolves the current token family's permanent or temporary authorization from the Server and dynamically filters `tools/list`. `authorization_changed` makes the Runner stop jobs created by that authorization; temporary-grant expiry is cleaned up by a Server timer, while the Runner independently stops calls and jobs according to their expiry timestamps. `expectedRevision` prevents a stale Dashboard editor from overwriting newer permission changes.
|
|
73
75
|
|
|
74
76
|
## Remote Assist
|
|
75
77
|
|
|
76
|
-
Remote Assist
|
|
78
|
+
Remote Assist reuses the Server/MCP and outbound Runner channel but uses dedicated one-time invitations and temporary devices that never enter ordinary permanent authorizations. The protocol-2 ordinary handshake is unchanged; the legacy single-project handshake is `remote-assist-v1`, while multi-project uses `remote-assist-multi-v1` with versioned inspect/claim and `assist_multi_welcome`. Activation requires the full approved project set, session/localConsentRevision, local approval and a permission-application receipt. A multi-project Runner refuses to downgrade when it meets an older Server.
|
|
77
79
|
|
|
78
|
-
Runner
|
|
80
|
+
The Runner holds an independent local scope and monotonic deadline fence. The effective execution scope is the intersection of the current client, the session and the per-project local approval; 1–16 projects each constrain scopes/programs, and overlapping roots or programs inside a shared root are rejected. The Server cannot replace that object or supply a permanent fallback. MCP resolves the exact target device first, then derives a project-specific family grant without writing back to the token/refresh original device snapshot; Assist never allows omitting `deviceId`. Admin output impersonation, ordinary permission edits and other families cannot bypass it. Timing starts at final approval; stopping covers all projects, first fencing admission and then bounded process cleanup, with cleanup status tracked separately from the session terminal state.
|
|
79
81
|
|
|
80
|
-
|
|
82
|
+
See the [Remote Assist Guide](REMOTE_ASSIST.md).
|
|
81
83
|
|
|
82
|
-
##
|
|
84
|
+
## Pairing and Authentication
|
|
83
85
|
|
|
84
|
-
|
|
86
|
+
A pairing code is a 40-bit random value (10 hex characters) that expires after 10 minutes. The Runner also holds a 256-bit polling credential; the administrator can only approve a code and cannot exchange it directly for a device token. Claim and state transitions use SQLite transactions and the code is consumed immediately on success. The Server stores only the SHA-256 of device tokens.
|
|
85
87
|
|
|
86
|
-
OAuth
|
|
88
|
+
OAuth metadata, DCR, authorization codes, S256 PKCE, token and revoke routes come from the official SDK; the actual authorization state and tokens are implemented by this project. The browser confirms the client, callback URL, devices and scopes. Authorization codes are valid for 2 minutes and single-use; access tokens last 1 hour, refresh tokens 30 days with rotation on every use. Reusing a consumed refresh token revokes the whole token family. A token's `resource` is always bound to the current `/mcp`.
|
|
87
89
|
|
|
88
|
-
|
|
90
|
+
PATs are valid for 1–365 days, must name already-paired devices and may specify projects or device-scoped `projectGrants`. New OAuth grants must select concrete devices and projects; refresh does not widen that snapshot, and legacy v0.1 grants are not silently rewritten — revoke and re-authorize to narrow project scope. Tokens are stored as SHA-256 digests; OAuth client confidential secrets are encrypted with AES-256-GCM using a key derived from `SESSION_SECRET`. Rotating `SESSION_SECRET` invalidates old cookies and OAuth clients. Dispatch re-checks the current token, and family revocation cancels queued calls; side effects already produced and already-started independent jobs are not rolled back automatically.
|
|
89
91
|
|
|
90
|
-
##
|
|
92
|
+
## Persistence and Jobs
|
|
91
93
|
|
|
92
|
-
Server
|
|
94
|
+
The Server database stores devices, pairing records, clients, authorization codes, tokens, browser sessions and audits. Audits contain only an argument digest, never argument bodies or output. Expired temporary authorization state and audits beyond the retention period are cleaned at startup and hourly.
|
|
93
95
|
|
|
94
|
-
Server
|
|
96
|
+
The Server also keeps at most 10,000 job metadata rows per device, expired by the audit retention period; when the cap is reached only older terminal records are evicted. Online, terminal-retained, offline-unconfirmed and Runner-unreported are distinct observation states. Queries filter by device, project and principal before taking a bounded result; process output is never copied into the Server database.
|
|
95
97
|
|
|
96
|
-
Runner
|
|
98
|
+
The Runner's `jobs.sqlite` stores principal, project, start/end times, state, exit code and output counts; `<job-uuid>.output` holds merged stdout/stderr, 8 MiB by default. Once a job reaches its output cap, the pipe keeps being drained while new output is discarded and marked truncated, preventing output backpressure and unbounded disk growth. At most the configured number of historical jobs is kept; older finished records are pruned when the next job starts.
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
Jobs are not replayed across a Server disconnect. An HTTP 45-second timeout or disconnect can leave a result unknown; file edits and commits must be inspected before deciding to retry. Process launch supports `idempotencyKey`: for 48 hours launches are de-duplicated by principal, project and argument digest; admission is persisted first, and after a crash the interrupted/unknown result is preserved without spawning again. Replay-rejection receipts survive historical-job cleanup (up to 10,000 keys); after expiry, de-duplication is no longer guaranteed. This is not exactly-once for every tool, nor a detached supervisor.
|
|
99
101
|
|
|
100
|
-
Runner
|
|
102
|
+
A clean Runner exit stops and awaits hosted process trees, then closes the database and lock. Run and pairing are mutually exclusive for the same `stateDir`; the OS releases SQLite locks from a crashed process, with no PID-file guesswork. On Windows, the supervisor uses suspended admission plus a Job Object and watches for Runner death; on Linux, the original group is cleaned when the leader exits, and force-killing the Runner still needs systemd control-group or container cleanup. Unfinished records are marked interrupted at startup; no process is killed by an old PID and nothing is auto-resumed. There is no PTY, no detached job surviving a Runner restart, no workflow session, no clustering and no multi-tenancy. A full source-level comparison is in the [WebCodex Source Audit](WEBCODEX_CODE_AUDIT.md).
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# 架构与技术选型
|
|
2
|
+
|
|
3
|
+
[English](ARCHITECTURE.md) · **简体中文**
|
|
4
|
+
|
|
5
|
+
HomeAgent v0.4.19 在 v0.3 的 context/editor/output-log/patch 基础上,增加权限协议、Dashboard 权限编辑器、受控 Git 网络工具、统一 diff 模糊重定位、持久状态化 Shell 会话与轻量 LSP 集成。MCP 目录当前共 **45 个工具**(`src/shared/tools.ts` 中的 44 个 Zod schema,加上单独定义的 `list_devices`)。设备能力上限与客户端授权分层保存,临时授权可过期并触发任务收回。新增工具的执行语义和持久化恢复详见 [日常开发工作流](DEVELOPMENT_WORKFLOW.zh-CN.md)。
|
|
6
|
+
|
|
7
|
+
## 数据流与信任边界
|
|
8
|
+
|
|
9
|
+
```mermaid
|
|
10
|
+
flowchart LR
|
|
11
|
+
AI[AI MCP Client] -->|HTTPS /mcp + OAuth or PAT| S[Server]
|
|
12
|
+
B[Owner Browser] -->|Secure cookie + CSRF| D[Dashboard / Admin API]
|
|
13
|
+
D --> S
|
|
14
|
+
S --> DB[(SQLite)]
|
|
15
|
+
R[Runner] -->|Outbound WSS /runner + device credential| S
|
|
16
|
+
R --> P[Local project policy]
|
|
17
|
+
P --> F[File tools]
|
|
18
|
+
P --> T[Tracked processes]
|
|
19
|
+
P --> G[Git]
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
MCP 客户端不能调用管理 API;设备凭据不能访问 MCP;Dashboard cookie 不能作为 Runner 凭据。单管理员管理多个设备,外部客户端通过 OAuth 或 PAT 获得明确设备和权限范围。
|
|
23
|
+
|
|
24
|
+
Server 和 Runner 都是可信代码。Runner 不信任请求中的路径、工具参数和权限范围,必须再次检查 Server 下发的项目策略及实际文件系统边界;但 Runner 不能抵御被完全攻陷的 Server 伪造主体,因此必须保护 Server 主机和数据库。项目目录中的内容是潜在不可信输入,不能允许它修改 Runner 配置或凭据目录。
|
|
25
|
+
|
|
26
|
+
## 选型
|
|
27
|
+
|
|
28
|
+
| 层 | 选择 | 理由与限制 |
|
|
29
|
+
| --- | --- | --- |
|
|
30
|
+
| 运行时 | Node.js 24 LTS、TypeScript strict | Linux/Windows 共用实现,原生进程/文件 API,内置 SQLite;最低 24.14,容器固定 24.22.1 |
|
|
31
|
+
| MCP | `@modelcontextprotocol/server` 2.4.0、`@modelcontextprotocol/node` 2.1.2 | 官方 v2 `createMcpHandler`:2026-07-28 server/discover/逐请求 envelope,以及无状态 2025 initialize/tools;v1 SDK 1.32.2 仅保留自托管 OAuth 授权服务器辅助路由和旧客户端测试 |
|
|
32
|
+
| HTTP | Express 5 | 与 SDK OAuth 路由兼容,减少自制协议处理 |
|
|
33
|
+
| Runner 通道 | `ws`,TLS 由反代终止 | 主动连接、请求 UUID、心跳、连接替换、断线重连、帧大小限制 |
|
|
34
|
+
| 数据 | `node:sqlite` WAL | 无附加数据库服务,适合个人单节点;不支持多副本共享数据库 |
|
|
35
|
+
| Dashboard | 原生 HTML/CSS/JS | 无前端构建链、外部 CDN、字体或运行时云依赖;5 秒刷新 |
|
|
36
|
+
| 部署 | Docker Compose + 可选 Caddy/Nginx | 同机、VPS、内网反代均可;Cloudflare 是可选方案,会引入第三方链路 |
|
|
37
|
+
|
|
38
|
+
MCP 由官方 v2 serving entry 处理协议协商,工具定义由 Zod 生成 JSON Schema。2026 使用 server/discover 和每请求 `_meta` envelope;2025 兼容路径使用 initialize。两者都每请求创建独立 Server,不生成 `MCP-Session-Id`。本项目只广告工具能力,不承诺资源、prompts、MCP Apps、sampling 或 Host continuation。Dashboard 分别展示客户端授权、管理员登录会话和 Runner 任务;它们不等同于上游 Workflow Session。长任务保存在 Runner,不依赖 HTTP 会话。
|
|
39
|
+
|
|
40
|
+
依据:[MCP 传输规范](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports)、[MCP 授权规范](https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization)、[TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)、[Node.js SQLite](https://nodejs.org/api/sqlite.html)。
|
|
41
|
+
|
|
42
|
+
## 模块与执行顺序
|
|
43
|
+
|
|
44
|
+
1. `server/app.ts`、`server/mcp.ts`:HTTP 管理 API、标准新旧 MCP 入口、WebSocket upgrade 和应用生命周期。
|
|
45
|
+
2. `server/hub.ts`:在线设备、认证后的 hello、调用路由、超时取消、断线错误和每次调用审计。
|
|
46
|
+
3. `runner/agent.ts`、`runner/lock.ts`:主动连接、回退重连、心跳监测、并发限额、OS 状态目录锁及本机分发。
|
|
47
|
+
4. `server/security.ts`、`oauth.ts`、配对 API:Cookie/CSRF、DCR、S256 PKCE、资源绑定、刷新轮换、设备一次性码。
|
|
48
|
+
5. `server/jobs.ts`、`public/`:持久任务观察、设备状态、项目摘要、配对、暂停/恢复/撤销、登录会话、客户端令牌和审计。
|
|
49
|
+
6. `runner/files.ts`、`processes.ts`、`shells.ts`、`lsp.ts`、`git.ts`:文件、长进程、持久 Shell、LSP 与 Git 工具;`policy.ts` 统一验证。
|
|
50
|
+
|
|
51
|
+
## 内部协议
|
|
52
|
+
|
|
53
|
+
Runner 协议版本为 `2`,不接受旧版握手,一个 WebSocket 消息对应一个 JSON 信封,最大 2 MiB,禁用压缩。长期设备令牌仅在 TLS 握手的 Authorization 头使用;设备 ID 位于 `X-Device-ID`,不放在 URL。
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{"type":"hello","protocol":2,"name":"workstation","platform":"win32/x64","version":"current","instanceId":"12345678-1234-4234-8234-123456789abc","capabilities":["read_file"],"projects":[]}
|
|
57
|
+
{"type":"welcome","protocol":2,"deviceId":"device-uuid","authorizations":[],"permissions":{"revision":3,"projects":[{"id":"app","name":"App","root":"E:/Projects/app","readOnly":false,"commands":[],"commandMode":"unrestricted","filesystemScope":"device","allowGitWrite":true,"allowGitNetwork":true,"allowGitPush":false}],"expiresAt":null,"fallbackProjects":[]}}
|
|
58
|
+
{"type":"permissions_applied","revision":3,"projects":[{"id":"app","name":"App","readOnly":false,"commands":[],"commandMode":"unrestricted","filesystemScope":"device","allowGitWrite":true,"allowGitNetwork":true,"allowGitPush":false}]}
|
|
59
|
+
{"type":"call","id":"request-uuid","tool":"read_file","args":{"projectId":"app","path":"README.md"},"principal":{"id":"pat:uuid","scopes":["read"],"devices":["device-uuid"],"projects":["app"]}}
|
|
60
|
+
{"type":"result","id":"request-uuid","result":{"content":[{"type":"text","text":"..."}]}}
|
|
61
|
+
{"type":"cancel","id":"request-uuid"}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Zod 严格验证工具参数与消息结构。Server 只接受发给当前连接的请求结果,其他设备或被替换的旧连接不能提交该请求的结果。Runner 最多 32 个同时调用,Server 每设备最多 32 个、总计最多 256 个待处理调用。
|
|
65
|
+
|
|
66
|
+
自 Runner v0.2 起,Runner 另外报告 `instanceId`、工具 capabilities、`job_update`,以及每页最多 100 项、总计最多 10,000 项的 `jobs_snapshot`。Server 校验快照页序、主体/项目/准入时间不可变、revision 单调及终态不可回退。快照完成后才能从 Dashboard 控制该确切实例的历史任务。元数据不含 argv、原始 cwd、输出或错误正文。旧连接的迟到事件不会覆盖新连接。
|
|
67
|
+
|
|
68
|
+
WS 原生 ping 每 15 秒发送一次,漏回 pong 将断开;Runner 45 秒无心跳会主动重连。连接后 10 秒内必须发送 hello。重连使用指数回退,最高约 30 秒并附随机抖动。设备暂停关闭连接并停止托管任务,恢复后 Runner 可重新连接;撤销则停止自动连接,需要显式配对。Server 断线后 Runner 收回项目访问并停止托管任务,重连后重新应用 Server 配置。
|
|
69
|
+
|
|
70
|
+
### 权限同步与收回
|
|
71
|
+
|
|
72
|
+
Server 是设备项目设置的唯一来源,保存当前项目、永久回退项目、应用 revision 和应用错误。本机连接配置不接受项目列表或权限开关;Runner 收到 `welcome` 或 `permissions` 后串行停止活动调用和托管进程,验证每个根目录、受保护路径、项目 ID 和 Git 配置,再回复 `permissions_applied`。应用失败时 Runner 保持不可调用状态,避免继续使用上一份高权限配置。
|
|
73
|
+
|
|
74
|
+
客户端每次 MCP dispatch 都重新从 Server 解析当前 token family 的永久或临时授权,并动态过滤 `tools/list`。`authorization_changed` 会让 Runner 停止该授权创建的任务;临时授权到期由 Server 定时清理,Runner 也依据调用和任务上的到期时间独立停止。`expectedRevision` 防止 Dashboard 中的旧编辑器覆盖较新的权限修改。
|
|
75
|
+
|
|
76
|
+
## Remote Assist
|
|
77
|
+
|
|
78
|
+
Remote Assist 复用 Server/MCP 与主动 Runner 通道,但使用专用一次性邀请和临时设备,不进入普通永久授权。协议 2 的普通握手保留;旧单项目握手为 `remote-assist-v1`,多项目使用 `remote-assist-multi-v1`、版本化 inspect/claim 和 `assist_multi_welcome`。必须匹配完整项目批准集合、session/localConsentRevision、本机批准和权限应用回执后才激活。多项目 Runner 遇旧 Server 拒绝降级。
|
|
79
|
+
|
|
80
|
+
Runner 持有独立本机范围和单调时长 fence,执行范围为当前客户端、会话与具体项目本机批准的交集;1–16 个项目各自限制 scopes/程序,拒绝重叠根及共享根内的获准程序。Server 不能替换该对象或提供永久 fallback。MCP 先解析准确目标设备,再按该项目派生专属 family grant,不写回 token/refresh 的原始设备快照;Assist 不允许省略 `deviceId`。管理员输出 impersonation、普通权限编辑和其他 family 不能旁路。最终批准后开始计时,停止覆盖全部项目,先封锁准入再有界清理进程,清理状态与会话终态分开。
|
|
81
|
+
|
|
82
|
+
详见[远程协助指南](REMOTE_ASSIST.zh-CN.md)。
|
|
83
|
+
|
|
84
|
+
## 配对与认证
|
|
85
|
+
|
|
86
|
+
配对码为 40 bit 随机值(10 位十六进制),10 分钟过期。Runner 另外持有 256 bit 轮询凭据;管理员仅能批准码,不能从码直接领取设备令牌。领取操作和状态转移使用 SQLite 事务,成功后立即消费。Server 只保存设备令牌的 SHA-256。
|
|
87
|
+
|
|
88
|
+
OAuth 元数据、DCR、授权码、S256 PKCE、token、revoke 路由由官方 SDK 提供;实际授权状态和令牌由本项目实现。浏览器确认客户端、回调地址、设备和 scopes。授权码 2 分钟有效、只使用一次;Access Token 1 小时,Refresh Token 30 天且每次刷新轮换。重用已消费的 Refresh Token 会撤销整个令牌族。Token 的 resource 始终绑定当前 `/mcp`。
|
|
89
|
+
|
|
90
|
+
PAT 有效期 1–365 天,必须指定已配对设备,可指定项目或设备限定的 `projectGrants`。新 OAuth grant 必须选择具体设备与项目,刷新不扩大这个快照;v0.1 的旧 grant 不被静默重写,需撤销并重新授权以收紧项目范围。Token 存 SHA-256 摘要;OAuth 客户端 confidential secret 用 `SESSION_SECRET` 派生密钥做 AES-256-GCM 加密。更换 `SESSION_SECRET` 会使旧 cookie/OAuth 客户端失效。dispatch 再检查当前令牌,族撤销会取消仍在排队的调用;已产生的副作用和已启动的独立任务不自动回滚。
|
|
91
|
+
|
|
92
|
+
## 持久化与任务
|
|
93
|
+
|
|
94
|
+
Server 数据库保存设备、配对、客户端、授权码、令牌、浏览器 session 和审计。审计只有参数摘要,不存参数正文和输出。启动及每小时清理过期授权临时状态和超过保留期的审计。
|
|
95
|
+
|
|
96
|
+
Server 还保存每设备最多 10,000 条 Job 元数据,按审计保留天数过期;上限时只逐出较旧终态记录。在线/终态保留/离线未确认/Runner 未报告是不同的观察状态。查询先按设备、项目和主体过滤后取有界结果,不复制进程输出到 Server 数据库。
|
|
97
|
+
|
|
98
|
+
Runner 的 `jobs.sqlite` 保存主体、项目、开始结束时间、状态、退出码和输出计数;`<job-uuid>.output` 保存合并 stdout/stderr,默认最多 8 MiB。每个任务的输出达上限后继续排空进程管道,丢弃新增输出并标记截断,避免输出阻塞与磁盘无限增长。最多保留配置数量的历史任务,下次启动任务时清理较旧已结束记录。
|
|
99
|
+
|
|
100
|
+
任务不在 Server 断线时重放。HTTP 45 秒超时或断线可能意味着结果未知;文件修改/提交仍需先检查再决定重试。进程启动可用 `idempotencyKey`:48 小时内按主体、项目和参数摘要去重;准入先持久化,崩溃后保留 interrupted/未知结果,不再次 spawn。历史任务清理后仍保留拒绝重放的收据,最多 10,000 个 key;过期后不再保证去重。这不是所有工具 exactly-once,也不是 detached supervisor。
|
|
101
|
+
|
|
102
|
+
Runner 正常退出会停止并等待托管树,再关闭数据库和锁;同一 `stateDir` 的运行/配对互斥,OS 释放崩溃进程的 SQLite 锁,无 PID 锁文件回收猜测。Windows supervisor 用 suspended admission + Job Object 并监视 Runner 死亡,Linux 在 leader 退出时清理原组;Linux Runner 被强制杀死仍需 systemd control-group/容器清理。启动时未结束记录标为 interrupted,不按旧 PID 杀进程、不自动恢复。没有 PTY、跨 Runner 重启存活的 detached 任务、工作流会话、集群或多租户。完整源码差异见 [WEBCODEX_CODE_AUDIT.zh-CN.md](WEBCODEX_CODE_AUDIT.zh-CN.md)。
|