homeagent-runner 0.4.18 → 0.4.20

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.
@@ -0,0 +1,316 @@
1
+ # 部署、配对与运维
2
+
3
+ [English](DEPLOYMENT.md) · **简体中文**
4
+
5
+ ## 准备
6
+
7
+ 推荐 Node.js 24.22.1 或更新的 24 LTS 补丁版、Git;最低 Node 24.14。原生 Server 不需要额外数据库。容器方式需要 Docker Engine 和 Compose v2。Runner 建议原生运行在开发机器上,以便使用现有编译器和工具链。
8
+
9
+ 所有公网流量使用 HTTPS/WSS。Server 的 `PUBLIC_URL` 必须是稳定、无子路径的外部 origin,例如 `https://mcp.example.com`。不要用每次重启会变化的临时隧道地址做长期 OAuth issuer。
10
+
11
+ ## 原生部署 Server
12
+
13
+ ### npm 安装
14
+
15
+ Server 和 Runner 使用独立 npm 包,无需源码编译。Server 包包含 Web Dashboard:
16
+
17
+ ```sh
18
+ npm install -g homeagent-server@latest
19
+ mkdir homeagent-server
20
+ cd homeagent-server
21
+ homeagent-server init
22
+ ```
23
+
24
+ 编辑本目录 `.env`,保留生成的密码和会话密钥。本机验证使用默认 `http://localhost:3210`;公网修改 `PUBLIC_URL=https://mcp.example.com`,若只有一层可信反代则设 `TRUST_PROXY_HOPS=1`,由反代连接 `127.0.0.1:3210`。然后运行:
25
+
26
+ ```sh
27
+ homeagent-server
28
+ ```
29
+
30
+ 命令在前台运行,从当前目录读取 `.env`;已有环境变量优先于文件。数据库默认写入当前目录的 `data/server.sqlite`,因此服务管理器必须设置固定工作目录。Linux 和 Windows PowerShell 的安装/启动命令相同。
31
+
32
+ ### 从源码安装
33
+
34
+ ```sh
35
+ git clone https://github.com/jhxxr/HomeAgent.git
36
+ cd HomeAgent
37
+ npm ci
38
+ npm run build
39
+ npm run init
40
+ ```
41
+
42
+ 用编辑器查看 `.env` 中生成的管理员密码,并修改 `PUBLIC_URL`。同机开发时保留 `http://localhost:3210`;对外部署时设为自己的 HTTPS 域名,反向代理连接本地 `127.0.0.1:3210`。非 loopback 的 HTTP `PUBLIC_URL` 会被拒绝。
43
+
44
+ ```sh
45
+ npm run server
46
+ ```
47
+
48
+ 生产由自己的服务管理器运行 `node dist/server/cli.js`,并安全注入 `.env`。npm 脚本使用 Node 的 `--env-file-if-exists=.env`,直接运行 node 则需要显式 `--env-file=/绝对路径/.env` 或服务环境。
49
+
50
+ ### Linux 用户 systemd 服务
51
+
52
+ 以下针对 npm 安装方式,在运行 Server 的专用低权限账户下操作。先确认实际路径:
53
+
54
+ ```sh
55
+ command -v node
56
+ npm root -g
57
+ mkdir -p "$HOME/.config/systemd/user"
58
+ ```
59
+
60
+ 创建 `$HOME/.config/systemd/user/homeagent-server.service`,把下面三个路径替换为自己的实际值:
61
+
62
+ - `WorkingDirectory`:保存 `.env` 的目录,必须允许该账户写入数据库。
63
+ - `ExecStart` 第一个路径:`command -v node` 的输出。
64
+ - `ExecStart` 第二个路径:`npm root -g` 输出目录下的 `homeagent-server/bin/server.mjs`。
65
+
66
+ ```ini
67
+ [Unit]
68
+ Description=HomeAgent MCP relay
69
+ After=network-online.target
70
+
71
+ [Service]
72
+ Type=simple
73
+ WorkingDirectory=/home/homeagent/homeagent-server
74
+ ExecStart=/absolute/path/to/node /absolute/global/node_modules/homeagent-server/bin/server.mjs
75
+ Restart=on-failure
76
+ RestartSec=5
77
+ UMask=0077
78
+ NoNewPrivileges=yes
79
+
80
+ [Install]
81
+ WantedBy=default.target
82
+ ```
83
+
84
+ 路径含空格时,分别使用 systemd 支持的双引号包住 `WorkingDirectory` 和 `ExecStart` 各路径;unit 中不能依赖 shell 的 `~` 或变量展开。
85
+
86
+ ```sh
87
+ systemctl --user daemon-reload
88
+ systemctl --user enable --now homeagent-server
89
+ systemctl --user status homeagent-server
90
+ journalctl --user -u homeagent-server -f
91
+ ```
92
+
93
+ 若需退出登录后继续运行并随系统启动,由管理员为该账户执行 `sudo loginctl enable-linger <运行账户>`。更新 npm 包后执行 `systemctl --user restart homeagent-server`。Windows 长期运行时使用自己的服务/进程管理器,指定相同工作目录;`homeagent service-install` 只安装 Runner 自启动,不安装 Server 服务。
94
+
95
+ ## Docker Compose
96
+
97
+ 先在有 Docker Engine、Compose v2 和 Git 的服务器检出发布源码:
98
+
99
+ ```sh
100
+ git clone --branch v0.4.20 --depth 1 https://github.com/jhxxr/HomeAgent.git
101
+ cd HomeAgent
102
+ ```
103
+
104
+ Linux 主机可通过容器生成 `.env`,无需宿主机 Node.js;按当前 UID/GID 创建文件,避免密钥归 root 所有导致普通账户无法编辑:
105
+
106
+ ```sh
107
+ docker run --rm --user "$(id -u):$(id -g)" \
108
+ -v "$PWD:/work" -w /work \
109
+ node:24.22.1-bookworm-slim node scripts/init.mjs
110
+ ```
111
+
112
+ 如果宿主机已有 Node.js,也可以直接执行 `node scripts/init.mjs`。初始化均不覆盖已有 `.env`。默认本地模式启动:
113
+
114
+ ```sh
115
+ docker compose up -d --build
116
+ docker compose ps
117
+ docker compose logs --tail=100 server
118
+ ```
119
+
120
+ 默认仅将 `127.0.0.1:3210` 映射到容器,不直接向公网暴露明文端口。SQLite 保存在 `server-data` 命名卷。Server 非 root 运行,根文件系统只读,只有数据库卷与临时目录可写,去除所有 Linux capabilities。
121
+
122
+ Docker 镜像包含已经编译的生产依赖、Dashboard 静态文件;运行不需要 npm、第三方 API 或构建服务。镜像构建需要访问软件包和镜像仓库,离线环境可在有网环境构建、导出镜像后导入。
123
+
124
+ ### Caddy 自动 TLS
125
+
126
+ 域名 A/AAAA 指向自己的 Server,放行 80/443。在 `.env` 修改:
127
+
128
+ ```dotenv
129
+ PUBLIC_URL=https://mcp.example.com
130
+ DOMAIN=mcp.example.com
131
+ TRUST_PROXY_HOPS=1
132
+ ```
133
+
134
+ ```sh
135
+ docker compose --profile proxy up -d --build
136
+ ```
137
+
138
+ Caddy 自动申请 TLS 并代理 HTTP 和 WebSocket。服务器与 Runner 都走同一个域名,Runner 指向 `https://mcp.example.com`。客户端 MCP URL 为 `https://mcp.example.com/mcp`。
139
+
140
+ ### 已有 Nginx
141
+
142
+ 参考 [deploy/nginx.conf](../deploy/nginx.conf),证书自行配置。`Host` 必须保持外部域名;必须支持 WebSocket upgrade,关闭代理缓冲。将 `TRUST_PROXY_HOPS=1` 设为真实受信代理数量,不能无条件信任任意 `X-Forwarded-For`。
143
+
144
+ ### 可选 Cloudflare Tunnel
145
+
146
+ 它是可选部署方式,会让流量通过 Cloudflare;完全自控的部署请选择自有服务器和反向代理。
147
+
148
+ 在自己已有的命名 Tunnel 中配置固定 hostname `mcp.example.com`,目标 `http://server:3210`(cloudflared 容器与 server 同网络)。`.env` 设置:
149
+
150
+ ```dotenv
151
+ PUBLIC_URL=https://mcp.example.com
152
+ TRUST_PROXY_HOPS=1
153
+ CLOUDFLARE_TUNNEL_TOKEN=你的命名隧道凭据
154
+ ```
155
+
156
+ ```sh
157
+ docker compose --profile cloudflare up -d --build
158
+ ```
159
+
160
+ 不要同时用 Cloudflare Access 的交互登录拦截 `/mcp`、OAuth 元数据或 `/runner`,除非客户端明确支持额外认证。此项目不依赖隧道,也不保存任何 Cloudflare API 凭据到源码。
161
+
162
+ ## Runner 配置与配对
163
+
164
+ 在开发机执行 `npm install -g homeagent-runner@latest`,之后直接执行 `homeagent`。未登录时进入全屏欢迎页,按 Enter 填写 Server URL 和设备名;等待批准时按 `o` 打开浏览器,项目目录在网页填写并保存在 Server 上。批准后自动连接。已登录时再次执行 `homeagent` 直接进入运行总览,无需记忆登录或启动子命令。新 Runner 本地配置只保存连接和运行设置,`stateDir` 保存凭据与任务记录;没有本地项目基线。
165
+
166
+ 成功登录和启动会记录配置的绝对路径,换工作目录后仍可使用 `homeagent`。指定 `--config` 时以显式路径为准,否则依次检查已记录位置、`~/.homeagent/runner.json`。已记录的文件被移动或删除时,全屏界面保留错误提示,允许用户选择配置,避免静默连接另一台设备。按 `s` 打开设置,可修改设备名、并发数、输出与历史上限,选择配置、重新登录、切换服务、启停自启动和退出登录;按 `a` 查看活动,`o` 打开网页,`p` 暂停/恢复连接。修改运行设置会先确认再断线、停止托管任务并重连。启用自启动前会关闭前台 Runner,由后台实例接管;服务固定使用当前配置路径。
167
+
168
+ 本地配置仅包含连接和运行设置,例如:
169
+
170
+ ```json
171
+ {"server":"https://mcp.example.com","name":"workstation","stateDir":"state"}
172
+ ```
173
+
174
+ 项目目录、Git 权限、命令别名和环境配置全部在网页管理。本地配置不接受项目字段或权限开关,Server 与 Runner 必须同时升级。
175
+
176
+ ### Dashboard 权限管理
177
+
178
+ Runner 首次连接时没有项目权限,收到 Server 配置并验证成功后才开放项目。Dashboard 的设备编辑器可以为每个项目设置:
179
+
180
+ - `filesystemScope=project`:只允许内置文件工具访问项目目录;
181
+ - `filesystemScope=device`:允许使用设备范围的绝对路径,但 Runner 配置、`stateDir` 和受保护路径仍拒绝通过文件工具访问;
182
+ - `commandMode=allowlist`:只允许运行网页配置的 `commands` 或别名;
183
+ - `commandMode=unrestricted`:允许任意可执行文件,实际权限等于 Runner 运行账户;
184
+ - Git 本地写入、网络 fetch/pull 和 push 三个独立开关。
185
+
186
+ 客户端授权编辑器另外控制设备、项目、scope、具体工具,以及直接显示的"允许全部程序"和"允许使用设备范围的绝对路径"开关。设备上限与客户端授权取交集,因此打开设备级能力不会自动让所有客户端获得该能力。修改已有 PAT 或 OAuth 授权不需要重新复制令牌。
187
+
188
+ 要运行电脑上其他 Python/Conda 环境,无需逐个填写"允许的程序":在设备项目的"允许执行的程序"中选择"允许全部程序",并在当前使用的客户端授权中勾选"允许全部程序"(同时开启执行任务权限)。解释器使用绝对路径,例如 `D:\Conda\envs\eeg\python.exe`;执行参数单独传入 `args`。若工作目录 `cwd` 位于项目外,还需在设备项目选择设备范围的绝对路径,并在当前客户端授权中允许同一能力。"全设备"文件范围不会自动开放全部程序。
189
+
190
+ `list_devices` 和 `get_project_context` 返回当前客户端的有效权限;`executionPolicy`、`filesystemPolicy` 同时说明设备配置与客户端授权。若 `limitedBy=authorization`,应修改当前客户端授权;若为 `project`,应修改设备项目设置。Dashboard 的设备编辑器仍显示设备配置上限。保存设备设置后等待页面显示 Runner 已应用,再发起新的调用。
191
+
192
+ 设备和客户端授权都支持临时有效分钟数。到期时 Server 增加 revision、取消在途调用;Runner 会停止该授权启动的托管任务,并恢复上一个永久权限。权限修改使用 `expectedRevision`,浏览器打开过期编辑器时会收到冲突而不会覆盖新设置。保存设备权限会停止此设备的托管任务,已发生的文件修改不会回滚。
193
+
194
+ 设备项目设置只有 Server 一个来源。清空全部项目后收回访问;断线会清空运行中的项目列表并停止托管任务,重连后重新下发。Server 仅接受当前 Runner 协议。
195
+
196
+ 交互式登录流程:
197
+
198
+ 1. 执行 `homeagent`,在全屏欢迎页按 Enter 登录,填写服务地址与设备名;创建私有配置并通过出站 HTTPS 请求创建配对。
199
+ 2. 全屏等待页显示 10 分钟有效的浏览器链接和备用 10 位一次性码,按 `o` 打开浏览器,Esc 取消,Ctrl+C 退出。
200
+ 3. 在已经登录 Server Dashboard 的浏览器打开链接,核对设备名称、填写被控端项目的绝对目录并批准;也可以稍后在 Dashboard 配置项目。备用码流程继续可用。
201
+ 4. Runner 使用自己持有的独立 `pollToken` 领取长期设备凭据。码、`pollToken` 和浏览器批准凭据都不能用来直接取得另一台设备的凭据。
202
+ 5. 凭据保存到 `stateDir/device.json`;Linux 目录 0700、文件 0600,Windows CLI 对目录设置当前账户和 SYSTEM 的受限 ACL。配对与运行使用同一 `stateDir` 互斥锁;先停止正在运行的实例再重新配对。
203
+ 6. 登录完成后自动进入运行总览;Dashboard 应显示在线及注册项目,最近活动中显示当前生效目录。下次仍直接执行 `homeagent`。
204
+
205
+ 配置检查使用 `homeagent check-config`,仅显示本机连接、Runner 版本和运行设置。终端在收到 Server 配置后显示实际应用的目录。
206
+
207
+ 启动或登录时终端会打印 `HomeAgent Runner v<版本> · Node <版本> · <平台>/<架构>`,Server 启动时同样打印自身版本。交互式终端(`homeagent`)使用独立的全屏终端画面,暂时隐藏 Shell 历史,显示应用图标、设备与运行详情、最近活动、连接状态和重连倒计时;窗口缩放时自动调整布局,退出时恢复原终端画面与光标。服务、重定向输出或 `--plain` 仍使用普通日志,`NO_COLOR` 或非真彩色终端降级为单色界面。Dashboard 顶部与页脚显示 Server 版本,"连接与安全 → 版本信息"列出 Server、Runner 协议以及每台设备上报的 Runner 版本,并对与 Server 不一致的 Runner 给出升级提示。`GET /health` 与 `GET /api/state` 也返回版本字段,便于部署脚本核对。`HOMEAGENT_TUI=0`(或 `plain`)关闭交互展示;`HOMEAGENT_TUI=1` 可在 CI 的交互终端中启用,但管道输出和 `TERM=dumb` 始终使用普通日志。
208
+
209
+ 配对超时或领取响应丢失时可在界面中重新开始,旧配对不会返回长期明文凭据。Esc 取消配对会终止轮询并释放状态目录锁。重新登录或切换服务会先确认,取消时保留原有登录;切换服务使用独立凭据目录。退出登录只删除选定配置的本地凭据,不会自动撤销 Server 上的设备记录,可在 Dashboard 撤销旧设备。非交互式 `login` 仍默认拒绝覆盖已有凭据,显式 `homeagent login --force` 才会替换。
210
+
211
+ Server 域名变更后,现有凭据不会静默连接另一个 origin,必须显式重新配对。修改本机连接设置后需重启 Runner;网页项目和命令策略会实时下发,不通过 MCP 工具修改。
212
+
213
+ ### 环境变量
214
+
215
+ `HOMEAGENT_SERVER` 可覆盖连接地址。项目目录不通过环境变量配置;在 Dashboard 保存项目设置后实时下发。
216
+
217
+ `HOMEAGENT_MOUSE=0` 可默认关闭全屏界面的鼠标跟踪。支持 SGR 鼠标的终端默认允许点击菜单、底部按钮、登录入口和输入框,滚轮可浏览长菜单与活动;输入框以外按 `m`,或点击鼠标切换按钮,可临时关闭跟踪以选择、复制文本。键盘与鼠标共用当前布局中的控件位置,窗口缩放和菜单滚动后会重新计算点击区域;退出时关闭鼠标跟踪和括号粘贴模式。
218
+
219
+ ### 自启动
220
+
221
+ 完成配对并停止手动运行的 Runner,再安装服务:
222
+
223
+ ```sh
224
+ homeagent service-install
225
+ homeagent service-uninstall
226
+ ```
227
+
228
+ Linux 创建 `~/.config/systemd/user/homeagent-<配置摘要>.service`,使用 user systemd,无需 root。要在退出登录及开机后持续运行,按安装输出显式执行 `sudo loginctl enable-linger <用户名>`。日志:`journalctl --user -u homeagent-<摘要>.service -f`。
229
+
230
+ Windows 创建当前用户登录触发的计划任务,名称为 `HomeAgent-<配置摘要>`,最低权限运行,无需在系统服务中保存密码。它是"用户登录后启动",不是"无人登录的系统启动"。若必须无人登录运行,应由管理员为专用低权限账户配置服务管理器;本项目不自动提升权限。查看状态:`Get-ScheduledTask -TaskName 'HomeAgent-*'`。升级或重启前先终止同配置的旧进程,避免两个 Runner 互相替换连接。
231
+
232
+ 服务安装会立即启动;不要再同时手动启动同一设备凭据。不要把源码位置移动后保留旧服务路径。
233
+
234
+ 自早期版本起,同一 `stateDir` 的第二个 Runner 就会明确拒绝启动。Windows 卸载先结束计划任务再删除;`CLI --version` 可看版本/Node/平台,`homeagent check-config` 可检查配置而不打印设备令牌。Windows 任务执行依赖系统 PowerShell/.NET Add-Type;组织策略禁止时失败关闭,不自动使用 `ExecutionPolicy Bypass`。
235
+
236
+ Windows 子进程默认显式使用系统 PowerShell 模块目录,避免过滤环境导致模块发现卡住,并排除用户/项目模块加载钩子。源码维护者可执行 `node --import tsx scripts/diagnose-windows.mjs`,使用实际 Runner 环境函数检查监督器启动;需要先安装开发依赖。该检查只输出启动状态与固定测试命令的输出。这是当前 v0.4.18 对 Windows PowerShell 持久 Shell 会话的行为。
237
+
238
+ ### 容器 Runner(Linux 可选)
239
+
240
+ 原生 Runner 更适合已有完整开发环境。需要隔离时也可以构建 runner target:
241
+
242
+ ```sh
243
+ docker build --target runner -t homeagent-runner:local .
244
+ ```
245
+
246
+ 将本机连接设置的 `stateDir` 设为 `/state`,在 Dashboard 将项目 root 设为 `/workspace`,只把实际项目挂载到 `/workspace`,state 持久卷挂载到 `/state`,配置只读挂载 `/config/runner.json`。容器的 UID/GID 必须对挂载目录有相应权限(镜像默认 node 用户,UID 1000),不要挂载 Docker socket 或整个宿主机根目录。
247
+
248
+ ```sh
249
+ docker run --rm -it \
250
+ --mount type=bind,src=/absolute/config/runner.json,dst=/config/runner.json,readonly \
251
+ --mount type=bind,src=/absolute/project,dst=/workspace \
252
+ --mount type=volume,src=homeagent-runner-state,dst=/state \
253
+ homeagent-runner:local login --config /config/runner.json
254
+ ```
255
+
256
+ 配对后用相同挂载、`--init --restart unless-stopped -d` 运行 `run --config /config/runner.json`。运行阶段不需要 `-it`。镜像只有 Node、Git、CA;其他编译器请自行构建派生镜像。
257
+
258
+ ## 配置表
259
+
260
+ | Server 环境变量 | 默认 / 要求 |
261
+ | --- | --- |
262
+ | HOST / PORT | `127.0.0.1` / `3210`;Compose 容器内为 `0.0.0.0:3210` |
263
+ | PUBLIC_URL | 固定 origin,不支持子路径,公网必须 HTTPS |
264
+ | ADMIN_PASSWORD | 管理员密码,至少 16 字符;未启用 XAuth 时必填,与 XAuth 同时配置时支持双登录方式 |
265
+ | XAUTH_ISSUER | 可选,[XAuth](https://github.com/jhxxr/XAuth) OIDC 签发方固定 origin(如 `https://auth.example.com`,无子路径) |
266
+ | XAUTH_CLIENT_ID | 可选,与 `XAUTH_ISSUER` 配合使用的 XAuth 客户端 ID |
267
+ | XAUTH_CLIENT_SECRET | 可选,XAuth 机密客户端(`web`)密钥;公开客户端可留空 |
268
+ | SESSION_SECRET | 必填,至少 32 字符;同时保护会话签名与 OAuth 客户端秘密 |
269
+ | HOMEAGENT_DB | `./data/server.sqlite`;容器内 `/app/data/server.sqlite` |
270
+ | TRUST_PROXY_HOPS | 0;有一层可信反代时设 1 |
271
+ | AUDIT_RETENTION_DAYS | 90,范围 1–3650 |
272
+
273
+ ### XAuth 管理员单点登录(可选)
274
+
275
+ 控制台支持接入自建 [XAuth](https://github.com/jhxxr/XAuth) OIDC 服务进行管理员登录:
276
+
277
+ 1. 在 XAuth 中注册客户端,将回调地址(Redirect URI)设为 `<PUBLIC_URL>/login/xauth/callback`(如 `https://mcp.example.com/login/xauth/callback`)。
278
+ 2. 在 `.env` 中配置 `XAUTH_ISSUER`、`XAUTH_CLIENT_ID`(以及机密客户端的 `XAUTH_CLIENT_SECRET`)。若留空 `ADMIN_PASSWORD`,则仅允许通过 XAuth 登录;若同时保留 `ADMIN_PASSWORD`,登录页同时提供 XAuth 与管理员密码两种方式。
279
+ 3. **单管理员账号绑定**:首个通过 XAuth 成功登录的账号(按 OIDC `sub` 唯一标识)会自动持久化绑定为该工作空间的唯一管理员,后续其他 XAuth 账号尝试登录将被直接拒绝(`403`)。
280
+
281
+ ## 暂停、撤销与备份
282
+
283
+ Dashboard "暂停"设备关闭连接并停止 Runner 的托管任务,后续调用立即拒绝。恢复后 Runner 自动重连。撤销会使长期设备令牌失效并停止重连;重新使用需要配对。撤销客户端令牌会撤销同族令牌;OAuth 客户端撤销还阻止其继续交换授权。
284
+
285
+ 在线备份使用 SQLite backup API,避免直接复制一个正在写入的 WAL 数据库文件:
286
+
287
+ ```sh
288
+ node scripts/backup.mjs ./data/server.sqlite /safe/backups/homeagent.sqlite
289
+ ```
290
+
291
+ Docker 中可直接调用相同 API:
292
+
293
+ ```sh
294
+ docker compose exec server node --input-type=module -e "import {DatabaseSync,backup} from 'node:sqlite'; const db=new DatabaseSync('/app/data/server.sqlite'); await backup(db,'/app/data/backup.sqlite'); db.close();"
295
+ docker compose cp server:/app/data/backup.sqlite ./homeagent-backup.sqlite
296
+ ```
297
+
298
+ Server 数据库备份之外,还要单独安全保存 `.env` 的 `SESSION_SECRET`,以及各 Runner 的 `stateDir` 和原始配置。不要把备份放在暴露项目根里。备份包含持久凭据的哈希和加密 OAuth 客户端信息,仍应视为敏感数据。
299
+
300
+ 恢复前停止 Server,用备份替换数据库;必须同时移除旧的 `server.sqlite-wal` 和 `server.sqlite-shm`(确认服务已停且目标路径正确),再恢复相同所有者和权限。容器方式将备份复制回命名卷的 `/app/data/server.sqlite`,确保 node 用户可读写。不要对旧版本程序直接使用新版本数据库;升级前备份,先在副本验证。
301
+
302
+ 当前 schema 版本为 `PRAGMA user_version=1`,本版本只创建缺失表,没有声明支持任意跨版本迁移。
303
+
304
+ ## 故障排查
305
+
306
+ - `/health` 不通:检查监听端口、容器健康状态、Host 转发及 `PUBLIC_URL`。非默认端口映射时请用 `PUBLIC_URL` 配置的主机名;例如配置 localhost 时不要直接换成 127.0.0.1 外部映射端口,严格 Host 校验可能返回 403。
307
+ - Dashboard API 403:刷新页面取得新 CSRF;确认浏览器访问域名与 `PUBLIC_URL` 一致。
308
+ - MCP 401:确认客户端 Token 未过期/撤销,或重新完成 OAuth;设备令牌不能用作 MCP Token。
309
+ - Runner 401:设备被撤销、凭据不匹配或服务器 origin 已变;不要自动把凭据发送到重定向目标。
310
+ - Runner 暂停:Server 返回 403,Runner 退避重试;恢复设备后应重新上线。
311
+ - Dashboard 任务显示 unconfirmed/missing:表示离线未确认或新快照未报告,不代表成功;不能凭旧 `processId` 在另一实例上读取/停止。
312
+ - v0.1 OAuth 升级:旧 grant 不被静默改写,请撤销并重新授权以启用具体设备/项目范围。升级 Server 后同时升级 Runner,以使用任务快照、幂等键和进程树托管。
313
+ - 多设备调用失败:先 `list_devices`,显式填写 `deviceId` 和 `projectId`。
314
+ - 命令被拒绝:检查项目 `commands` 是否包含完全相同的可执行文件以及客户端 `execute` 权限。
315
+ - Git 写入被拒绝:检查 `git` scope、`allowGitWrite`、独立仓库根、Git identity 和 clean/process filters。
316
+ - `node:sqlite` ExperimentalWarning:Node 24 内置 API 的运行时提示,不代表服务启动失败;生产仍应固定并测试 Node 补丁版。
@@ -1,22 +1,24 @@
1
- # 日常远程开发工作流(v0.3)
1
+ # Daily Remote Development Workflow
2
2
 
3
- 本轮围绕单个 AI/单个操作者完成“接手 → 检索 → 修改 → 验证 → 审查提交 → 断线恢复”,在 v0.2 的权限、配对和任务协议上增加实用工具。客户端继续连接原来的 `/mcp`,同时升级 Server 与 Runner,并刷新客户端工具列表。
3
+ **English** · [简体中文](DEVELOPMENT_WORKFLOW.zh-CN.md)
4
4
 
5
- ## 推荐的工具流程
5
+ This workflow serves a single AI / single-operator cycle of "take over → search → edit → verify → review and commit → recover after disconnect". The v0.3 release added practical tools on top of the v0.2 permission, pairing and job protocol; v0.4.17 later added fuzzy unified diffs, persistent stateful shell sessions and lightweight LSP tools. Clients keep connecting to the same `/mcp`; upgrade Server and Runner together and refresh the client tool list.
6
6
 
7
- 1. `list_devices` 选择准确设备与项目,调用 `get_project_context` 获得 manifest、项目指导、Git 分支/HEAD、可用命令与别名、环境配置名称、最近任务和自己保存的交接记录。
8
- 2. `search_files` 用 include/exclude globs 和 contextLines 找到相关代码;Git 项目默认使用 `git ls-files --cached --others --exclude-standard`,有源限额且不偷偷退回无视限额的全盘搜索。非 Git 项目继续有界遍历,返回 gitIgnoreApplied=false。
9
- 3. `read_files` 在一次请求中读取最多 16 个文件的指定行范围。使用它返回的完整内容 SHA-256 进行后续编辑,不需要计算字节偏移。
10
- 4. `edit_files` 预检全部文件的创建、替换、精确块编辑或删除;也可以 `apply_unified_diff` 应用标准文本 unified diff。已有文件必须提供预期 SHA,新文件必须明确不存在。先 dryRun 可查看摘要。
11
- 5. `run_command` 运行本机允许的程序/别名。短命令一次返回状态与输出;长命令返回同一个任务 ID,继续 `wait_process`,而不是再次启动。重试启动时保留 idempotencyKey。
12
- 6. 用 `git_diff` 审查变更,再以 `git_branches` 返回的准确 HEAD 与选中文件内容 SHA 调用 `git_commit_paths`。它拒绝消费选中文件已有的暂存变更,并保留其他文件的暂存状态。
13
- 7. `save_project_note` 写简短交接说明。下次使用同一客户端身份调用 `get_project_context`,可恢复自己的记录、Git 状态和最近任务。它不是聊天历史、自动调度或上游 Workflow Session。
7
+ ## Recommended Tool Flow
14
8
 
15
- ## 低摩擦命令配置
9
+ 1. Call `list_devices` to pick the exact device and project, then `get_project_context` to obtain the manifest, project instructions, Git branch/HEAD, available commands and aliases, environment profile names, recent jobs and your own saved handoff note.
10
+ 2. Use `search_files` with include/exclude globs and `contextLines` to locate relevant code; Git projects default to `git ls-files --cached --others --exclude-standard`, with bounded sources and no silent fallback to an unbounded full-disk search. Non-Git projects use bounded traversal and return `gitIgnoreApplied=false`. For symbol navigation or diagnostics, use the `lsp_*` tools.
11
+ 3. Use `read_files` to read specified line ranges of up to 16 files in one request. Use the returned full-content SHA-256 for subsequent edits; no byte offsets need to be computed.
12
+ 4. `edit_files` pre-validates creation, replacement, exact-block edits or deletion across all files; alternatively `apply_unified_diff` applies a standard text unified diff. Existing files require the expected SHA and new files must be explicitly absent. A `dryRun` shows a summary first.
13
+ 5. Use `run_command` for an allowed local program/alias. Short commands return status and output in one call; long commands return the same job ID, so continue with `wait_process` instead of starting a second process. Keep `idempotencyKey` when retrying a launch. For stateful multi-command work, use `start_shell` / `run_shell`.
14
+ 6. Review changes with `git_diff`, then call `git_commit_paths` with the exact HEAD from `git_branches` and the selected files' content SHAs. It refuses to consume pre-existing staged changes of selected files and preserves the staging state of other files.
15
+ 7. `save_project_note` writes a short handoff note. Calling `get_project_context` later with the same client identity restores your own note, Git status and recent jobs. It is not chat history, automatic scheduling or an upstream Workflow Session.
16
16
 
17
- 在 Dashboard 的项目权限中配置 commandAliases 与 environmentProfiles,避免每次在提示中拼接平台包装脚本或传递环境变量。下面路径必须改为自己机器的真实值:
17
+ ## Low-Friction Command Configuration
18
18
 
19
- 在设备权限的“命令别名与环境配置”中编辑对应 JSON。以下为 Server 上的项目设置示例,不写入本机 Runner 连接文件。Server 保存这些参数,Runner 收到配置后才开放对应能力。
19
+ Configure `commandAliases` and `environmentProfiles` in the Dashboard's project permissions so you do not have to concatenate platform wrapper scripts or pass environment variables in every prompt. Replace the paths below with real values from your machine:
20
+
21
+ Edit the corresponding JSON in "Command Aliases and Environment Profiles" of the device permissions. The following is a Server-side project settings example, not a local Runner connection file. The Server stores these parameters and the Runner opens the capability only after receiving the configuration.
20
22
 
21
23
  ```json
22
24
  {
@@ -48,29 +50,29 @@
48
50
  }
49
51
  ```
50
52
 
51
- Windows 的 npm 别名可指向 `C:/Program Files/nodejs/node.exe`,prefix args 指向对应安装目录的 `node_modules/npm/bin/npm-cli.js`。Runner 仍不隐式执行 .cmd/.bat,也不把字符串拼成 shell 命令。别名只由管理员在网页设备权限中授予,客户端不能临时指定任意环境变量或修改别名。
53
+ On Windows the npm alias can point to `C:/Program Files/nodejs/node.exe`, with prefix args pointing to `node_modules/npm/bin/npm-cli.js` in the matching installation directory. The Runner still never executes `.cmd`/`.bat` implicitly and never concatenates strings into a shell command. Aliases are granted only by an administrator in the web device permissions; clients cannot temporarily specify arbitrary environment variables or modify aliases.
52
54
 
53
55
  ```json
54
56
  {
55
57
  "name": "run_command",
56
58
  "arguments": {
57
- "deviceId": "实际设备 UUID",
59
+ "deviceId": "actual-device-uuid",
58
60
  "projectId": "app",
59
61
  "executable": "npm",
60
62
  "args": ["test", "--", "--runInBand"],
61
63
  "environment": "development",
62
64
  "waitMs": 1500,
63
65
  "timeoutMs": 3600000,
64
- "idempotencyKey": "同一次启动重试保持不变的唯一键"
66
+ "idempotencyKey": "a-unique-key-kept-unchanged-for-retries-of-this-launch"
65
67
  }
66
68
  }
67
69
  ```
68
70
 
69
- 别名本身授予其目标程序执行权限,即使目标没有另外写入 commands;这是明确的管理员配置授权。Dashboard 和 list_devices 会显示别名/环境名称(各最多 64 个),使操作者能看到额外执行入口。启用 node/python/shell 等仍意味着允许该程序使用账户权限。environmentProfiles 的值不通过上下文或 hello 返回;但已授权的程序能够读取自己的环境,不能把它当作对执行者保密的 Vault。请用专用低权限账户或只挂载所需项目的容器。
71
+ Granting an alias grants execution of its target program even if the target is not separately listed in `commands`; this is an explicit administrator configuration grant. The Dashboard and `list_devices` show alias/environment names (up to 64 each) so the operator can see the extra execution entry points. Enabling node/python/shell still means allowing that program to use the account privileges. `environmentProfiles` values are not returned through context or hello; an authorized program can read its own environment, so do not treat this as a Vault secret from the executor. Use a dedicated low-privilege account or a container mounting only the required projects.
70
72
 
71
- get_project_context 的环境检查只查配置程序在基础 PATH 的可达性,不执行 manifest 中发现的脚本,不猜测哪些 npm scripts 安全。Server 下发的 profile 中改变 PATH 后的实际可用性以命令执行结果为准。终端只输出实际应用的项目目录,不输出环境值。
73
+ The environment check in `get_project_context` only checks reachability of configured programs on the base PATH; it does not execute scripts found in a manifest or guess which npm scripts are safe. Actual availability after a delivered profile changes PATH is determined by the command execution result. The terminal prints only the applied project directories, never environment values.
72
74
 
73
- ## 批量读取与编辑
75
+ ## Batch Reads and Edits
74
76
 
75
77
  ```json
76
78
  {
@@ -86,41 +88,41 @@ get_project_context 的环境检查只查配置程序在基础 PATH 的可达性
86
88
  }
87
89
  ```
88
90
 
89
- 每文件最多读取 8 MiB 源,单项最多 1000 行,默认约 200 行,总返回文本最多 256 KiB。缺失、权限或版本错误在单文件结果中体现;预算不足时明确返回续读信息。单行比预算还长时不产生“已经前进”的假游标。返回全文 SHA,用于编辑前置条件。
91
+ Each file reads at most 8 MiB of source, each item at most 1000 lines (about 200 by default), and total returned text at most 256 KiB. Missing, permission or version errors appear in the per-file result; a tight budget explicitly returns continuation information. A single line longer than the budget does not produce a fake "already advanced" cursor. A full-text SHA is returned for edit preconditions.
90
92
 
91
- edit_files 最多 32 个唯一文件,单文件结果最多 1 MiB,所有 before/after image 合计不超过 8 MiB;创建文件要求父目录已存在。已有文件使用 expectedSha256,创建只接受不存在的路径;同一路径不能在同一批次重复出现。精确编辑逐项要求唯一匹配。
93
+ `edit_files` handles at most 32 unique files, up to 1 MiB per file result, with all before/after images totaling no more than 8 MiB; creating a file requires its parent directory to exist. Existing files use `expectedSha256`, creation accepts only non-existent paths, and the same path cannot appear twice in one batch. Exact edits require a unique match per item.
92
94
 
93
- apply_unified_diff 只接受 `--- / +++ / @@` 的标准文本 diff,不做模糊匹配,支持文本创建/删除、CRLF 和 no-newline marker。它拒绝重命名、二进制、仅 mode 变更、重叠/错位 hunks、缺失或过期版本;不支持 Codex 的 `*** Begin Patch` 语法。
95
+ `apply_unified_diff` accepts only standard text diffs with `--- / +++ / @@`, supporting text creation/deletion, CRLF and no-newline markers. It refuses renames, binary content, mode-only changes, overlapping/misplaced hunks, and missing or stale versions; Codex's `*** Begin Patch` syntax is not supported. It also supports bounded fuzzy hunk relocation: `fuzz` (0–200 lines) relocates hunks whose `@@` line numbers are slightly off, `ignoreWhitespace` tolerates leading/trailing horizontal whitespace differences in context, ambiguous matches inside the fuzzy window are rejected with `ambiguous_patch`, and `relocatedHunks` reports the applied offsets. Strict exact-line-number mode is still available with `fuzz: 0`.
94
96
 
95
- 编辑计划、原内容和状态日志保存在私有 stateDir/edits。全部预检通过后才修改项目;失败按 after-image 校验回滚。重启会恢复未完成事务。若外部进程同时改了文件,保留该内容,返回 recovery_conflict 并阻止项目继续自动修改。用 get_edit_transactions 查看自己的事务;解决冲突后 recover_edit_transaction 会再次检查摘要,仍不会强制覆盖外部改动。
97
+ The edit plan, original content and status journal live in the private `stateDir/edits`. Files are modified only after all pre-checks pass; on failure a rollback is performed against the after-image validation. Unfinished transactions are recovered after a restart. If an external process changed a file concurrently, that content is preserved, `recovery_conflict` is returned and further automatic project modification is blocked. Use `get_edit_transactions` to inspect your own transactions; after resolving a conflict, `recover_edit_transaction` re-checks digests and still never force-overwrites external changes.
96
98
 
97
- 这是一组有恢复日志的逐文件操作,不是文件系统快照隔离;外部编辑器仍可看到中间状态。正常成功/回滚后删除内容备份,仅保留最多约 200 个摘要收据。积累大量未解决或未完成的私有目录时会拒绝新事务,由操作者检查,不自动删除未知恢复数据。进程崩溃恢复已测试,不宣称断电后的文件系统事务保证。
99
+ This is a set of per-file operations with a recovery journal, not filesystem snapshot isolation; an external editor can still see intermediate states. Content backups are deleted after normal success/rollback, keeping only up to roughly 200 digest receipts. When many unresolved or unfinished private directories accumulate, new transactions are refused for operator inspection; unknown recovery data is never deleted automatically. Crash recovery after a process crash has been tested; no filesystem transaction guarantee after power loss is claimed.
98
100
 
99
- ## 短命令、等待与日志尾部
101
+ ## Short Commands, Waits, and Output Tails
100
102
 
101
- run_command 默认等待 1500 ms,最长一次等待 20 秒;执行任务本身的 timeoutMs 仍独立。超出等待窗口继续同一任务。wait_process 可以等到完成或新输出,最长 20 秒;取消等待不终止任务,停止任务使用 stop_process。
103
+ `run_command` waits 1500 ms by default, at most 20 seconds in one call; the job's own `timeoutMs` remains independent. Beyond the wait window the same job continues. `wait_process` can wait for completion or new output, at most 20 seconds; cancelling a wait does not terminate the job — use `stop_process` for that.
102
104
 
103
- v0.3 保留两种有界输出:
105
+ The current version keeps two bounded output views:
104
106
 
105
- - 原 read_process_output 读取最初的 maxOutputBytes,兼容旧字节游标。
106
- - tail_process_output 读取另外固定的 64 KiB 环形尾部,保留超出前段上限后产生的末尾报错。返回总输出字节数、绝对 nextCursor、oldestCursor 和 skippedBytes,轮转不会冒充完整日志。
107
+ - The original `read_process_output` reads the first `maxOutputBytes`, compatible with the legacy byte cursor.
108
+ - `tail_process_output` reads a separate fixed 64 KiB rolling tail, retaining the trailing error produced after the prefix cap. It returns total output bytes, absolute `nextCursor`, `oldestCursor` and `skippedBytes`; rotation is never presented as a complete log.
107
109
 
108
- 每任务磁盘上限为 maxOutputBytes + 64 KiB,超限的中段会丢弃,不提供“完整日志”下载承诺。旧 v0.2 任务没有环形尾部;Runner 异常中断后未完成任务也不推断未知环形写入位置,均继续使用 prefix API。正常结束的任务尾部可以在 Runner 重启后继续读取。Dashboard 对有有效尾部的位置默认读取最新内容,显示总字节数和轮转提示。
110
+ Per-job disk usage is capped at `maxOutputBytes + 64 KiB`; the middle is discarded on overflow, with no promise of a "full log" download. Legacy v0.2 jobs have no rolling tail, and jobs left unfinished after an abnormal Runner exit do not infer an unknown rolling write position — both continue to use the prefix API. The tail of a normally finished job can still be read after a Runner restart. The Dashboard defaults to the newest content for positions with a valid tail, showing total bytes and a rotation notice.
109
111
 
110
- ## 安全提交与 Git 工作树
112
+ ## Safe Commits and Git Worktrees
111
113
 
112
- git_commit_paths 接受具体普通文件或明确的已删除文件,要求 expectedHead 和每文件 expectedSha256(删除为 null)。它对真实 index 持锁,用临时 index 构造提交并 CAS 更新 ref,再写入保留其他暂存条目的 index。HEAD、文件版本变化或选中文件已经有暂存变更都会拒绝;用户无关的暂存内容不会一起提交。
114
+ `git_commit_paths` accepts concrete ordinary files or explicit deleted files and requires `expectedHead` and per-file `expectedSha256` (`null` for deletions). It locks the real index, builds the commit with a temporary index and CAS-updates the ref, then writes an index that preserves other staged entries. A changed HEAD or file version, or pre-existing staged changes on selected files, is rejected; unrelated staged content of the user is never swept into the commit.
113
115
 
114
- 这不证明文件中每行均由当前 AI 编写;调用前必须审查选中文件。提交后若崩溃/出错发生在 ref 与 index 最终化之间,保留 index.lock 并报告需人工核对,不删除锁后盲目重试。无法把 Git ref 和 index 的两个更新变成一个跨文件原子事务。
116
+ This does not prove every line of a file was written by the current AI; review the selected files before calling. If a crash/error occurs between the ref and index finalization, `index.lock` is retained and reported for manual inspection instead of deleting the lock and blindly retrying. The two updates to a Git ref and index cannot be made into one cross-file atomic transaction.
115
117
 
116
- git_switch_branch 只在工作区和暂存区都干净时创建/切换本地分支,不强制覆盖、不 push。git_branches 返回准确 HEAD、当前分支、最多 100 个本地分支和状态。
118
+ `git_switch_branch` creates/switches local branches only when both worktree and staging area are clean; it never force-overwrites or pushes. `git_branches` returns the exact HEAD, current branch, up to 100 local branches and status.
117
119
 
118
- 已有 linked worktree 可把项目的 gitCommonDir 显式设置为所属仓库的 canonical `.git` 目录。Runner 校验 gitdir 必须位于它的 worktrees 子目录、commondir 和双向 backlink 一致;默认仍拒绝指向未授权 Git 元数据的 `.git` 文件。新建 worktree、注册派生项目并授予客户端权限的完整自动流程尚未实现,请由操作者注册。
120
+ An existing linked worktree can explicitly set the project's `gitCommonDir` to the canonical `.git` directory of its owning repository. The Runner validates that gitdir is under its `worktrees` subdirectory and that `commondir` and the bidirectional backlink agree; by default a `.git` file pointing to unauthorized Git metadata is still refused. The fully automatic flow of creating a worktree, registering a derived project and granting client permissions is not implemented; the operator registers it manually.
119
121
 
120
- git_diff 对目录参数也逐文件过滤本机排除规则;git_add 收紧为显式文件,防止把目录内排除文件隐式 stage。Git 日志/状态仍是授权项目仓库范围的元数据。
122
+ `git_diff` filters directory arguments per file against local exclusion rules; `git_add` was tightened to explicit files so excluded files inside a directory are not staged implicitly. Git log/status remain metadata within the authorized project repository.
121
123
 
122
- ## 验收与剩余范围
124
+ ## Acceptance and Remaining Scope
123
125
 
124
- 自动化测试包含真正运行的 Node 测试和 Python unittest,以及官方 MCP 2026 Client 的完整串联:失败测试 → 批量读取 → 多文件 Diff → 复测通过 → 审查 → 只提交选中文件 → 保存交接 → Server 重启后恢复。这个串联是可复现的 SDK 场景测试,**没有宣称已登录真实 AI 客户端或证明模型自主完成率**。
126
+ Automated tests include genuinely running Node tests and Python unittest, plus a full chain with the official MCP 2026 Client: failing test → batch read → multi-file diff → re-test passing → review → commit only selected files → save handoff → recover after Server restart. This chain is a reproducible SDK scenario test; **it does not claim a real AI client was signed in or prove a model's autonomous completion rate**. Later v0.4.17 additions (fuzzy diffs, persistent stateful shell sessions and lightweight LSP tools) extend the toolchain beyond that original scenario.
125
127
 
126
- 本轮没有实现交互 PTY/持久 shell、跨 Runner 重启继续运行的 detached supervisor、端口预览与浏览器验收、制品通道、自动 worktree 注册、完整 Workflow Session。现有 profiles/aliases 提供常见非交互工具链的稳定入口。真实 AI 客户端验收还需选定客户端和可修改的实际项目;不需要提供模型密钥到仓库。
128
+ Still not implemented: interactive PTY, a detached supervisor that keeps running across a Runner restart, port preview and browser acceptance, an artifact channel, automatic worktree registration and a full Workflow Session. Persistent stateful shell sessions added in v0.4.17 are bounded, supervised sessions — **not** an interactive PTY or a detached supervisor. The existing profiles/aliases provide a stable entry point for common non-interactive toolchains. Real AI client acceptance still requires choosing a client and a modifiable real project; no model keys need to be provided to the repository.
@@ -0,0 +1,128 @@
1
+ # 日常远程开发工作流
2
+
3
+ [English](DEVELOPMENT_WORKFLOW.md) · **简体中文**
4
+
5
+ 本流程服务于单个 AI / 单个操作者完成"接手 → 检索 → 修改 → 验证 → 审查提交 → 断线恢复"。v0.3 在 v0.2 的权限、配对和任务协议上增加实用工具;v0.4.17 又补入统一 diff 模糊重定位、持久状态化 Shell 会话与轻量 LSP 工具。客户端继续连接原来的 `/mcp`,同时升级 Server 与 Runner,并刷新客户端工具列表。
6
+
7
+ ## 推荐的工具流程
8
+
9
+ 1. `list_devices` 选择准确设备与项目,调用 `get_project_context` 获得 manifest、项目指导、Git 分支/HEAD、可用命令与别名、环境配置名称、最近任务和自己保存的交接记录。
10
+ 2. `search_files` 用 include/exclude globs 和 `contextLines` 找到相关代码;Git 项目默认使用 `git ls-files --cached --others --exclude-standard`,有源限额且不偷偷退回无视限额的全盘搜索。非 Git 项目继续有界遍历,返回 `gitIgnoreApplied=false`。需要符号跳转或诊断时使用 `lsp_*` 工具。
11
+ 3. `read_files` 在一次请求中读取最多 16 个文件的指定行范围。使用它返回的完整内容 SHA-256 进行后续编辑,不需要计算字节偏移。
12
+ 4. `edit_files` 预检全部文件的创建、替换、精确块编辑或删除;也可以 `apply_unified_diff` 应用标准文本 unified diff。已有文件必须提供预期 SHA,新文件必须明确不存在。先 `dryRun` 可查看摘要。
13
+ 5. `run_command` 运行本机允许的程序/别名。短命令一次返回状态与输出;长命令返回同一个任务 ID,继续 `wait_process`,而不是再次启动。重试启动时保留 `idempotencyKey`。需要跨命令保持状态时,使用 `start_shell` / `run_shell`。
14
+ 6. 用 `git_diff` 审查变更,再以 `git_branches` 返回的准确 HEAD 与选中文件内容 SHA 调用 `git_commit_paths`。它拒绝消费选中文件已有的暂存变更,并保留其他文件的暂存状态。
15
+ 7. `save_project_note` 写简短交接说明。下次使用同一客户端身份调用 `get_project_context`,可恢复自己的记录、Git 状态和最近任务。它不是聊天历史、自动调度或上游 Workflow Session。
16
+
17
+ ## 低摩擦命令配置
18
+
19
+ 在 Dashboard 的项目权限中配置 `commandAliases` 与 `environmentProfiles`,避免每次在提示中拼接平台包装脚本或传递环境变量。下面路径必须改为自己机器的真实值:
20
+
21
+ 在设备权限的"命令别名与环境配置"中编辑对应 JSON。以下为 Server 上的项目设置示例,不写入本机 Runner 连接文件。Server 保存这些参数,Runner 收到配置后才开放对应能力。
22
+
23
+ ```json
24
+ {
25
+ "id": "app",
26
+ "name": "My application",
27
+ "root": "/home/me/projects/app",
28
+ "commands": ["/usr/bin/node", "/usr/bin/python3"],
29
+ "commandAliases": {
30
+ "test": {
31
+ "executable": "/usr/bin/node",
32
+ "args": ["--test"]
33
+ },
34
+ "npm": {
35
+ "executable": "/usr/bin/node",
36
+ "args": ["/usr/lib/node_modules/npm/bin/npm-cli.js"]
37
+ },
38
+ "python": {
39
+ "executable": "/home/me/projects/app/.venv/bin/python",
40
+ "args": []
41
+ }
42
+ },
43
+ "environmentProfiles": {
44
+ "development": {
45
+ "env": {"NODE_ENV": "development"},
46
+ "inherit": ["HTTPS_PROXY", "HTTP_PROXY", "NO_PROXY"]
47
+ }
48
+ },
49
+ "allowGitWrite": true
50
+ }
51
+ ```
52
+
53
+ Windows 的 npm 别名可指向 `C:/Program Files/nodejs/node.exe`,prefix args 指向对应安装目录的 `node_modules/npm/bin/npm-cli.js`。Runner 仍不隐式执行 .cmd/.bat,也不把字符串拼成 shell 命令。别名只由管理员在网页设备权限中授予,客户端不能临时指定任意环境变量或修改别名。
54
+
55
+ ```json
56
+ {
57
+ "name": "run_command",
58
+ "arguments": {
59
+ "deviceId": "实际设备 UUID",
60
+ "projectId": "app",
61
+ "executable": "npm",
62
+ "args": ["test", "--", "--runInBand"],
63
+ "environment": "development",
64
+ "waitMs": 1500,
65
+ "timeoutMs": 3600000,
66
+ "idempotencyKey": "同一次启动重试保持不变的唯一键"
67
+ }
68
+ }
69
+ ```
70
+
71
+ 别名本身授予其目标程序执行权限,即使目标没有另外写入 `commands`;这是明确的管理员配置授权。Dashboard 和 `list_devices` 会显示别名/环境名称(各最多 64 个),使操作者能看到额外执行入口。启用 node/python/shell 等仍意味着允许该程序使用账户权限。`environmentProfiles` 的值不通过上下文或 hello 返回;但已授权的程序能够读取自己的环境,不能把它当作对执行者保密的 Vault。请用专用低权限账户或只挂载所需项目的容器。
72
+
73
+ `get_project_context` 的环境检查只查配置程序在基础 PATH 的可达性,不执行 manifest 中发现的脚本,不猜测哪些 npm scripts 安全。Server 下发的 profile 中改变 PATH 后的实际可用性以命令执行结果为准。终端只输出实际应用的项目目录,不输出环境值。
74
+
75
+ ## 批量读取与编辑
76
+
77
+ ```json
78
+ {
79
+ "name": "read_files",
80
+ "arguments": {
81
+ "projectId": "app",
82
+ "files": [
83
+ {"path": "src/service.py", "startLine": 20, "endLine": 100},
84
+ {"path": "tests/test_service.py", "startLine": 1, "endLine": 120}
85
+ ],
86
+ "maxBytes": 131072
87
+ }
88
+ }
89
+ ```
90
+
91
+ 每文件最多读取 8 MiB 源,单项最多 1000 行,默认约 200 行,总返回文本最多 256 KiB。缺失、权限或版本错误在单文件结果中体现;预算不足时明确返回续读信息。单行比预算还长时不产生"已经前进"的假游标。返回全文 SHA,用于编辑前置条件。
92
+
93
+ `edit_files` 最多 32 个唯一文件,单文件结果最多 1 MiB,所有 before/after image 合计不超过 8 MiB;创建文件要求父目录已存在。已有文件使用 `expectedSha256`,创建只接受不存在的路径;同一路径不能在同一批次重复出现。精确编辑逐项要求唯一匹配。
94
+
95
+ `apply_unified_diff` 只接受 `--- / +++ / @@` 的标准文本 diff,支持文本创建/删除、CRLF 和 no-newline marker。它拒绝重命名、二进制、仅 mode 变更、重叠/错位 hunks、缺失或过期版本;不支持 Codex 的 `*** Begin Patch` 语法。同时支持有界模糊 hunk 重定位:`fuzz`(0–200 行)可重定位 `@@` 行号略有偏差的 hunks,`ignoreWhitespace` 容许上下文行首尾水平空白差异,模糊窗口内出现多处匹配时以 `ambiguous_patch` 拒绝,`relocatedHunks` 报告实际偏移。使用 `fuzz: 0` 仍保持严格精确行号模式。
96
+
97
+ 编辑计划、原内容和状态日志保存在私有 `stateDir/edits`。全部预检通过后才修改项目;失败按 after-image 校验回滚。重启会恢复未完成事务。若外部进程同时改了文件,保留该内容,返回 `recovery_conflict` 并阻止项目继续自动修改。用 `get_edit_transactions` 查看自己的事务;解决冲突后 `recover_edit_transaction` 会再次检查摘要,仍不会强制覆盖外部改动。
98
+
99
+ 这是一组有恢复日志的逐文件操作,不是文件系统快照隔离;外部编辑器仍可看到中间状态。正常成功/回滚后删除内容备份,仅保留最多约 200 个摘要收据。积累大量未解决或未完成的私有目录时会拒绝新事务,由操作者检查,不自动删除未知恢复数据。进程崩溃恢复已测试,不宣称断电后的文件系统事务保证。
100
+
101
+ ## 短命令、等待与日志尾部
102
+
103
+ `run_command` 默认等待 1500 ms,最长一次等待 20 秒;执行任务本身的 `timeoutMs` 仍独立。超出等待窗口继续同一任务。`wait_process` 可以等到完成或新输出,最长 20 秒;取消等待不终止任务,停止任务使用 `stop_process`。
104
+
105
+ 当前保留两种有界输出:
106
+
107
+ - 原 `read_process_output` 读取最初的 `maxOutputBytes`,兼容旧字节游标。
108
+ - `tail_process_output` 读取另外固定的 64 KiB 环形尾部,保留超出前段上限后产生的末尾报错。返回总输出字节数、绝对 `nextCursor`、`oldestCursor` 和 `skippedBytes`,轮转不会冒充完整日志。
109
+
110
+ 每任务磁盘上限为 `maxOutputBytes + 64 KiB`,超限的中段会丢弃,不提供"完整日志"下载承诺。旧 v0.2 任务没有环形尾部;Runner 异常中断后未完成任务也不推断未知环形写入位置,均继续使用 prefix API。正常结束的任务尾部可以在 Runner 重启后继续读取。Dashboard 对有有效尾部的位置默认读取最新内容,显示总字节数和轮转提示。
111
+
112
+ ## 安全提交与 Git 工作树
113
+
114
+ `git_commit_paths` 接受具体普通文件或明确的已删除文件,要求 `expectedHead` 和每文件 `expectedSha256`(删除为 null)。它对真实 index 持锁,用临时 index 构造提交并 CAS 更新 ref,再写入保留其他暂存条目的 index。HEAD、文件版本变化或选中文件已经有暂存变更都会拒绝;用户无关的暂存内容不会一起提交。
115
+
116
+ 这不证明文件中每行均由当前 AI 编写;调用前必须审查选中文件。提交后若崩溃/出错发生在 ref 与 index 最终化之间,保留 `index.lock` 并报告需人工核对,不删除锁后盲目重试。无法把 Git ref 和 index 的两个更新变成一个跨文件原子事务。
117
+
118
+ `git_switch_branch` 只在工作区和暂存区都干净时创建/切换本地分支,不强制覆盖、不 push。`git_branches` 返回准确 HEAD、当前分支、最多 100 个本地分支和状态。
119
+
120
+ 已有 linked worktree 可把项目的 `gitCommonDir` 显式设置为所属仓库的 canonical `.git` 目录。Runner 校验 gitdir 必须位于它的 worktrees 子目录、`commondir` 和双向 backlink 一致;默认仍拒绝指向未授权 Git 元数据的 `.git` 文件。新建 worktree、注册派生项目并授予客户端权限的完整自动流程尚未实现,请由操作者注册。
121
+
122
+ `git_diff` 对目录参数也逐文件过滤本机排除规则;`git_add` 收紧为显式文件,防止把目录内排除文件隐式 stage。Git 日志/状态仍是授权项目仓库范围的元数据。
123
+
124
+ ## 验收与剩余范围
125
+
126
+ 自动化测试包含真正运行的 Node 测试和 Python unittest,以及官方 MCP 2026 Client 的完整串联:失败测试 → 批量读取 → 多文件 Diff → 复测通过 → 审查 → 只提交选中文件 → 保存交接 → Server 重启后恢复。这个串联是可复现的 SDK 场景测试,**没有宣称已登录真实 AI 客户端或证明模型自主完成率**。后续 v0.4.17 增加的模糊 diff、持久状态化 Shell 会话与轻量 LSP 工具,是在该原始场景之上的扩展。
127
+
128
+ 仍未实现:交互 PTY、跨 Runner 重启继续运行的 detached supervisor、端口预览与浏览器验收、制品通道、自动 worktree 注册,以及完整 Workflow Session。v0.4.17 增加的持久状态化 Shell 会话是有界、受监管的会话,**不是**交互 PTY,也不是 detached supervisor。现有 profiles/aliases 提供常见非交互工具链的稳定入口。真实 AI 客户端验收还需选定客户端和可修改的实际项目;不需要提供模型密钥到仓库。