patchwarden 0.4.0 → 0.6.1
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/PatchWarden.cmd +51 -0
- package/README.en.md +1022 -0
- package/README.md +897 -358
- package/dist/assessments/agentAssessor.d.ts +15 -0
- package/dist/assessments/agentAssessor.js +293 -0
- package/dist/assessments/assessmentStore.d.ts +133 -0
- package/dist/assessments/assessmentStore.js +238 -0
- package/dist/assessments/confirmCli.d.ts +9 -0
- package/dist/assessments/confirmCli.js +26 -0
- package/dist/config.d.ts +22 -1
- package/dist/config.js +156 -3
- package/dist/direct/directAudit.d.ts +23 -0
- package/dist/direct/directAudit.js +309 -0
- package/dist/direct/directGuards.d.ts +20 -0
- package/dist/direct/directGuards.js +137 -0
- package/dist/direct/directPatch.d.ts +17 -0
- package/dist/direct/directPatch.js +113 -0
- package/dist/direct/directSessionStore.d.ts +63 -0
- package/dist/direct/directSessionStore.js +192 -0
- package/dist/direct/directVerification.d.ts +12 -0
- package/dist/direct/directVerification.js +96 -0
- package/dist/doctor.js +73 -5
- package/dist/logging.d.ts +52 -0
- package/dist/logging.js +123 -0
- package/dist/runner/agentInvocation.d.ts +23 -0
- package/dist/runner/agentInvocation.js +106 -0
- package/dist/runner/changeCapture.d.ts +70 -0
- package/dist/runner/changeCapture.js +278 -6
- package/dist/runner/runTask.js +271 -65
- package/dist/runner/simpleProcess.d.ts +21 -0
- package/dist/runner/simpleProcess.js +206 -0
- package/dist/runner/watch.js +17 -2
- package/dist/security/commandGuard.d.ts +2 -1
- package/dist/security/commandGuard.js +25 -3
- package/dist/security/riskEngine.d.ts +27 -0
- package/dist/security/riskEngine.js +118 -0
- package/dist/security/runtimeGuard.d.ts +6 -0
- package/dist/security/runtimeGuard.js +28 -0
- package/dist/smoke-test.js +1353 -7
- package/dist/test/unit/android-doctor.test.d.ts +1 -0
- package/dist/test/unit/android-doctor.test.js +118 -0
- package/dist/test/unit/chinese-path.test.d.ts +1 -0
- package/dist/test/unit/chinese-path.test.js +91 -0
- package/dist/test/unit/command-guard.test.d.ts +1 -0
- package/dist/test/unit/command-guard.test.js +160 -0
- package/dist/test/unit/direct-guards.test.d.ts +1 -0
- package/dist/test/unit/direct-guards.test.js +213 -0
- package/dist/test/unit/logging.test.d.ts +1 -0
- package/dist/test/unit/logging.test.js +275 -0
- package/dist/test/unit/path-guard.test.d.ts +1 -0
- package/dist/test/unit/path-guard.test.js +109 -0
- package/dist/test/unit/safe-status.test.d.ts +1 -0
- package/dist/test/unit/safe-status.test.js +165 -0
- package/dist/test/unit/sensitive-guard.test.d.ts +1 -0
- package/dist/test/unit/sensitive-guard.test.js +104 -0
- package/dist/test/unit/sync-file.test.d.ts +1 -0
- package/dist/test/unit/sync-file.test.js +154 -0
- package/dist/test/unit/watcher-status.test.d.ts +1 -0
- package/dist/test/unit/watcher-status.test.js +169 -0
- package/dist/tools/androidDoctor.d.ts +38 -0
- package/dist/tools/androidDoctor.js +391 -0
- package/dist/tools/applyPatch.d.ts +16 -0
- package/dist/tools/applyPatch.js +41 -0
- package/dist/tools/auditSession.d.ts +5 -0
- package/dist/tools/auditSession.js +12 -0
- package/dist/tools/auditTask.d.ts +7 -0
- package/dist/tools/auditTask.js +105 -7
- package/dist/tools/createDirectSession.d.ts +14 -0
- package/dist/tools/createDirectSession.js +54 -0
- package/dist/tools/createTask.d.ts +48 -1
- package/dist/tools/createTask.js +298 -47
- package/dist/tools/finalizeDirectSession.d.ts +19 -0
- package/dist/tools/finalizeDirectSession.js +84 -0
- package/dist/tools/getTaskSummary.d.ts +50 -0
- package/dist/tools/getTaskSummary.js +79 -2
- package/dist/tools/healthCheck.d.ts +27 -12
- package/dist/tools/healthCheck.js +44 -6
- package/dist/tools/readWorkspaceFile.d.ts +7 -1
- package/dist/tools/readWorkspaceFile.js +48 -2
- package/dist/tools/registry.js +270 -19
- package/dist/tools/runVerification.d.ts +16 -0
- package/dist/tools/runVerification.js +32 -0
- package/dist/tools/safeStatus.d.ts +19 -0
- package/dist/tools/safeStatus.js +72 -0
- package/dist/tools/savePlan.d.ts +1 -0
- package/dist/tools/savePlan.js +38 -7
- package/dist/tools/searchWorkspace.d.ts +19 -0
- package/dist/tools/searchWorkspace.js +205 -0
- package/dist/tools/syncFile.d.ts +18 -0
- package/dist/tools/syncFile.js +65 -0
- package/dist/tools/taskOutputs.d.ts +2 -2
- package/dist/tools/taskTemplates.js +2 -1
- package/dist/tools/toolCatalog.d.ts +4 -3
- package/dist/tools/toolCatalog.js +34 -5
- package/dist/tools/waitForTask.d.ts +2 -2
- package/dist/tools/waitForTask.js +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.js +2 -2
- package/dist/watcherStatus.d.ts +1 -0
- package/dist/watcherStatus.js +96 -4
- package/docs/chatgpt-usage.md +101 -0
- package/docs/performance-notes.md +55 -0
- package/docs/release-checklist.md +14 -0
- package/docs/release-v0.6.0.md +71 -0
- package/docs/release-v0.6.1.md +75 -0
- package/examples/config.example.json +5 -0
- package/examples/openai-tunnel/README.md +11 -4
- package/examples/openai-tunnel/chatgpt-test-prompt.md +18 -14
- package/examples/openai-tunnel/tunnel-client.example.yaml +8 -0
- package/package.json +13 -8
- package/scripts/brand-check.js +58 -12
- package/scripts/control-smoke.js +206 -0
- package/scripts/http-mcp-smoke.js +10 -2
- package/scripts/launchers/Check-PatchWarden-Health.cmd +6 -0
- package/scripts/launchers/Reset-PatchWarden-Tunnel-Key.cmd +6 -0
- package/scripts/launchers/Restart-PatchWarden.cmd +6 -0
- package/scripts/launchers/Start-PatchWarden-Direct-Tunnel.cmd +7 -0
- package/scripts/launchers/Start-PatchWarden-Tunnel.cmd +7 -0
- package/scripts/lifecycle-smoke.js +402 -8
- package/scripts/manage-patchwarden.ps1 +639 -0
- package/scripts/mcp-manifest-check.js +123 -58
- package/scripts/mcp-smoke.js +160 -2
- package/scripts/pack-clean.js +160 -5
- package/scripts/package-manifest-check.js +78 -0
- package/scripts/patchwarden-mcp-direct.cmd +7 -0
- package/scripts/patchwarden-mcp-stdio.cmd +1 -1
- package/scripts/restart-patchwarden.ps1 +5 -4
- package/scripts/start-patchwarden-tunnel.ps1 +261 -30
- package/scripts/tunnel-supervisor-smoke.js +36 -4
- package/scripts/unit-tests.js +36 -0
- package/scripts/watcher-supervisor-smoke.js +10 -6
- package/src/assessments/agentAssessor.ts +324 -0
- package/src/assessments/assessmentStore.ts +426 -0
- package/src/assessments/confirmCli.ts +29 -0
- package/src/config.ts +178 -4
- package/src/direct/directAudit.ts +400 -0
- package/src/direct/directGuards.ts +279 -0
- package/src/direct/directPatch.ts +258 -0
- package/src/direct/directSessionStore.ts +345 -0
- package/src/direct/directVerification.ts +138 -0
- package/src/doctor.ts +103 -7
- package/src/logging.ts +152 -0
- package/src/runner/agentInvocation.ts +125 -0
- package/src/runner/changeCapture.ts +352 -6
- package/src/runner/runTask.ts +279 -63
- package/src/runner/simpleProcess.ts +223 -0
- package/src/runner/watch.ts +18 -2
- package/src/security/commandGuard.ts +46 -4
- package/src/security/riskEngine.ts +160 -0
- package/src/security/runtimeGuard.ts +41 -0
- package/src/smoke-test.ts +1291 -4
- package/src/test/unit/android-doctor.test.ts +158 -0
- package/src/test/unit/chinese-path.test.ts +106 -0
- package/src/test/unit/command-guard.test.ts +221 -0
- package/src/test/unit/direct-guards.test.ts +297 -0
- package/src/test/unit/logging.test.ts +325 -0
- package/src/test/unit/path-guard.test.ts +150 -0
- package/src/test/unit/safe-status.test.ts +187 -0
- package/src/test/unit/sensitive-guard.test.ts +124 -0
- package/src/test/unit/sync-file.test.ts +231 -0
- package/src/test/unit/watcher-status.test.ts +190 -0
- package/src/tools/androidDoctor.ts +424 -0
- package/src/tools/applyPatch.ts +86 -0
- package/src/tools/auditSession.ts +28 -0
- package/src/tools/auditTask.ts +111 -7
- package/src/tools/createDirectSession.ts +113 -0
- package/src/tools/createTask.ts +405 -55
- package/src/tools/finalizeDirectSession.ts +144 -0
- package/src/tools/getTaskSummary.ts +133 -2
- package/src/tools/healthCheck.ts +45 -6
- package/src/tools/readWorkspaceFile.ts +85 -2
- package/src/tools/registry.ts +305 -19
- package/src/tools/runVerification.ts +58 -0
- package/src/tools/safeStatus.ts +96 -0
- package/src/tools/savePlan.ts +57 -7
- package/src/tools/searchWorkspace.ts +275 -0
- package/src/tools/syncFile.ts +122 -0
- package/src/tools/taskTemplates.ts +2 -1
- package/src/tools/toolCatalog.ts +37 -6
- package/src/tools/waitForTask.ts +3 -3
- package/src/version.ts +2 -2
- package/src/watcherStatus.ts +101 -4
- package/tsconfig.json +18 -17
- package/Check-PatchWarden-Health.cmd +0 -6
- package/Reset-PatchWarden-Tunnel-Key.cmd +0 -6
- package/Restart-PatchWarden.cmd +0 -19
- package/Start-PatchWarden-Tunnel.cmd +0 -7
- package/docs/release-v0.3.0.md +0 -43
- package/docs/release-v0.4.0.md +0 -74
package/README.md
CHANGED
|
@@ -1,149 +1,207 @@
|
|
|
1
1
|
# PatchWarden
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
<p align="right">
|
|
4
|
+
<strong>简体中文</strong> · <a href="./README.en.md">English</a>
|
|
5
|
+
</p>
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
> [migration guide](docs/migration-from-safe-bifrost.md).
|
|
7
|
+
[](https://www.npmjs.com/package/patchwarden)
|
|
8
|
+
[](https://nodejs.org/)
|
|
9
|
+
[](LICENSE)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
当前稳定版本:**v0.6.1**。查看
|
|
12
|
+
[发布说明](docs/release-v0.6.1.md)、
|
|
13
|
+
[迁移指南](docs/migration-from-safe-bifrost.md)和
|
|
14
|
+
[GitHub Release](https://github.com/jiezeng2004-design/PatchWarden/releases/tag/v0.6.1)。
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
PatchWarden 是一个面向本地编程 Agent 的安全 MCP 桥接器。上游的
|
|
17
|
+
ChatGPT、Codex、OpenCode 或其他 MCP 客户端负责规划与验收,
|
|
18
|
+
PatchWarden 负责把计划保存成工作区内任务,再由预先配置的本地 Agent
|
|
19
|
+
执行,并返回结果、代码差异和独立测试记录。
|
|
17
20
|
|
|
18
21
|

|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
> [!IMPORTANT]
|
|
24
|
+
> PatchWarden 不是通用远程 Shell。MCP 客户端不能随意执行命令:
|
|
25
|
+
> 文件必须位于配置的工作区内,Agent 必须预先登记,验证命令必须与白名单
|
|
26
|
+
> 完全一致,敏感文件名会被阻止。
|
|
27
|
+
|
|
28
|
+
## 目录
|
|
29
|
+
|
|
30
|
+
- [它解决什么问题](#它解决什么问题)
|
|
31
|
+
- [运行结构](#运行结构)
|
|
32
|
+
- [环境要求](#环境要求)
|
|
33
|
+
- [五分钟快速开始](#五分钟快速开始)
|
|
34
|
+
- [完整配置说明](#完整配置说明)
|
|
35
|
+
- [接入 OpenCode](#接入-opencode)
|
|
36
|
+
- [接入 Codex](#接入-codex)
|
|
37
|
+
- [接入 ChatGPT Connector](#接入-chatgpt-connector)
|
|
38
|
+
- [代理配置:必须先看](#代理配置必须先看)
|
|
39
|
+
- [标准任务工作流](#标准任务工作流)
|
|
40
|
+
- [HTTP MCP 模式](#http-mcp-模式)
|
|
41
|
+
- [诊断与健康检查](#诊断与健康检查)
|
|
42
|
+
- [踩坑记录与故障排查](#踩坑记录与故障排查)
|
|
43
|
+
- [Direct 模式:ChatGPT 直接开发](#direct-模式chatgpt-直接开发)
|
|
44
|
+
- [安全边界与本地数据](#安全边界与本地数据)
|
|
45
|
+
- [升级与旧版本迁移](#升级与旧版本迁移)
|
|
46
|
+
- [开发与发布验证](#开发与发布验证)
|
|
47
|
+
|
|
48
|
+
## 它解决什么问题
|
|
49
|
+
|
|
50
|
+
很多本地编程桥会把完整 Shell 暴露给上游模型。PatchWarden 采用更窄、
|
|
51
|
+
更容易审计的任务通道:
|
|
52
|
+
|
|
53
|
+
- 上游模型只能调用明确的 MCP 工具,不能直接拼接任意 Shell 命令。
|
|
54
|
+
- 每个任务必须指定位于 `workspaceRoot` 内的 `repo_path`。
|
|
55
|
+
- Agent 启动命令来自本地配置,而不是来自模型输入。
|
|
56
|
+
- 测试命令必须精确匹配 `allowedTestCommands`。
|
|
57
|
+
- 任务完成后保存结构化结果、完整差异、文件统计和独立验证记录。
|
|
58
|
+
- 工作区外出现变化时,任务会标记为作用域违规,而不是悄悄接受。
|
|
59
|
+
- `.env`、Token、SSH 密钥、Cookie、凭据文件等敏感路径默认不可读。
|
|
60
|
+
|
|
61
|
+
适合的场景:
|
|
62
|
+
|
|
63
|
+
- 让 ChatGPT 规划任务,让 OpenCode 或 Codex 在本地执行。
|
|
64
|
+
- 给本地 MCP 客户端增加可审计的 plan → task → verify 流程。
|
|
65
|
+
- 在执行后读取 `result.json`、`diff.patch`、`verify.json` 并独立验收。
|
|
66
|
+
- 需要工作区限制、命令白名单和敏感信息防护的自动化任务。
|
|
67
|
+
|
|
68
|
+
不适合的场景:
|
|
69
|
+
|
|
70
|
+
- 希望 MCP 客户端获得无限制 Shell。
|
|
71
|
+
- 直接管理整个磁盘、用户主目录或包含大量私人文件的目录。
|
|
72
|
+
- 无人监督地自动提交、推送、发版或修改线上环境。
|
|
73
|
+
|
|
74
|
+
## 运行结构
|
|
24
75
|
|
|
25
76
|
```text
|
|
26
|
-
ChatGPT
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
loop until the agent reaches a terminal state.
|
|
50
|
-
- `create_task` accepts a saved `plan_id`, an auditable `inline_plan`, or one
|
|
51
|
-
of five guarded task templates.
|
|
52
|
-
- A supervised Windows tunnel launcher retries recoverable disconnects and
|
|
53
|
-
writes local, redacted runtime health state.
|
|
54
|
-
- Structured `result.json`, `verify.json`, `diff.patch`, and
|
|
55
|
-
`get_task_summary` acceptance evidence.
|
|
56
|
-
- Workspace-wide before/after fingerprints that fail a task when changes are
|
|
57
|
-
detected outside its explicit `repo_path`.
|
|
58
|
-
- Before/after file fingerprints for stronger change evidence.
|
|
59
|
-
- File reads contained to one configured `workspaceRoot`.
|
|
60
|
-
- Sensitive file blocking for `.env`, tokens, SSH keys, credentials, cookies,
|
|
61
|
-
and similar paths.
|
|
62
|
-
- Low-risk plan storage: ordinary build/test/release language is accepted;
|
|
63
|
-
explicit credential theft, destructive disk deletion, and backdoor plans are blocked.
|
|
64
|
-
- Task artifacts are returned with secret-like values redacted instead of
|
|
65
|
-
failing the entire read.
|
|
66
|
-
- Pending task artifacts return structured `available: false` evidence with
|
|
67
|
-
task phase, watcher health, pending reason, and the next safe tool call.
|
|
68
|
-
- Structured `result.json`, `verify.json`, and `get_task_summary` values are
|
|
69
|
-
recursively redacted and report `redacted` plus `redaction_categories`.
|
|
70
|
-
- Agent command allowlist through `patchwarden.config.json`.
|
|
71
|
-
- Test command exact-match allowlist.
|
|
72
|
-
- Windows-friendly helper scripts.
|
|
73
|
-
- Read-only `doctor` command for local setup diagnostics.
|
|
74
|
-
|
|
75
|
-
## MCP Tools and Profiles
|
|
76
|
-
|
|
77
|
-
PatchWarden has two deterministic tool profiles. `full` is the default for
|
|
78
|
-
ordinary local development and exposes all tools listed below. The Windows
|
|
79
|
-
tunnel stdio wrapper explicitly uses `chatgpt_core`, a stable 16-tool profile
|
|
80
|
-
ordered for the create/wait/review loop:
|
|
81
|
-
|
|
82
|
-
`health_check`, `list_agents`, `list_workspace`, `read_workspace_file`,
|
|
83
|
-
`save_plan`, `create_task`, `wait_for_task`, `get_task_summary`, `get_diff`,
|
|
84
|
-
`get_result`, `get_result_json`, `get_test_log`, `get_task_status`, `list_tasks`,
|
|
85
|
-
`cancel_task`, `audit_task`.
|
|
86
|
-
|
|
87
|
-
The full profile exposes:
|
|
88
|
-
|
|
89
|
-
- `list_workspace`
|
|
90
|
-
- `read_workspace_file`
|
|
91
|
-
- `save_plan`
|
|
92
|
-
- `get_plan`
|
|
93
|
-
- `health_check`
|
|
94
|
-
- `list_agents`
|
|
95
|
-
- `create_task`
|
|
96
|
-
- `get_task_status`
|
|
97
|
-
- `get_result`
|
|
98
|
-
- `get_result_json`
|
|
99
|
-
- `get_diff`
|
|
100
|
-
- `get_test_log`
|
|
101
|
-
- `list_tasks`
|
|
102
|
-
- `cancel_task`
|
|
103
|
-
- `kill_task`
|
|
104
|
-
- `retry_task`
|
|
105
|
-
- `get_task_progress`
|
|
106
|
-
- `wait_for_task`
|
|
107
|
-
- `get_task_summary`
|
|
108
|
-
- `get_task_stdout_tail`
|
|
109
|
-
- `get_task_log_tail`
|
|
110
|
-
- `audit_task`
|
|
77
|
+
ChatGPT / Codex / OpenCode / 其他 MCP 客户端
|
|
78
|
+
|
|
|
79
|
+
v
|
|
80
|
+
PatchWarden MCP Server
|
|
81
|
+
|
|
|
82
|
+
save_plan / create_task
|
|
83
|
+
|
|
|
84
|
+
v
|
|
85
|
+
.patchwarden/tasks/<task_id>/
|
|
86
|
+
|
|
|
87
|
+
Watcher 发现任务
|
|
88
|
+
|
|
|
89
|
+
v
|
|
90
|
+
本地 Agent(OpenCode / Codex)
|
|
91
|
+
|
|
|
92
|
+
v
|
|
93
|
+
result.json / diff.patch / verify.json / status.json
|
|
94
|
+
|
|
|
95
|
+
v
|
|
96
|
+
MCP 客户端读取、审计、人工验收
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
一次完整运行通常包含三个角色:
|
|
111
100
|
|
|
112
|
-
|
|
101
|
+
1. **MCP Server**:由 Codex、OpenCode 或 Tunnel 启动。
|
|
102
|
+
2. **Watcher**:监听待处理任务并启动本地 Agent。
|
|
103
|
+
3. **本地 Agent**:真正修改代码,必须在配置中预先登记。
|
|
113
104
|
|
|
114
|
-
|
|
105
|
+
> [!WARNING]
|
|
106
|
+
> “MCP 已连接”不等于“任务一定会执行”。如果 Watcher 没有运行,
|
|
107
|
+
> `create_task` 仍能保存任务,但任务会保持 queued,并返回
|
|
108
|
+
> `execution_blocked: true`。
|
|
115
109
|
|
|
116
|
-
|
|
110
|
+
## 环境要求
|
|
111
|
+
|
|
112
|
+
- Node.js 18 或更高版本
|
|
117
113
|
- npm
|
|
118
|
-
- Git
|
|
119
|
-
-
|
|
114
|
+
- Git(可选,但没有 Git 就无法生成可靠的 `git.diff`)
|
|
115
|
+
- 至少一个可用的本地编程 Agent,例如 OpenCode 或 Codex CLI
|
|
116
|
+
- Windows Tunnel 模式还需要 `tunnel-client.exe`、Tunnel ID 和运行时 API Key
|
|
117
|
+
|
|
118
|
+
Windows PowerShell 检查:
|
|
119
|
+
|
|
120
|
+
```powershell
|
|
121
|
+
node -v
|
|
122
|
+
npm.cmd -v
|
|
123
|
+
git --version
|
|
124
|
+
where.exe opencode
|
|
125
|
+
where.exe codex
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
如果 `where.exe codex` 只返回 WindowsApps 下的 Codex Desktop
|
|
129
|
+
应用程序,它不一定是可供 PatchWarden 调用的 Codex CLI。请安装或指定真正的
|
|
130
|
+
CLI,或者先把 OpenCode 配置为执行 Agent。
|
|
131
|
+
|
|
132
|
+
## 五分钟快速开始
|
|
133
|
+
|
|
134
|
+
### 方案 A:从源码运行(推荐)
|
|
135
|
+
|
|
136
|
+
源码方式最适合完整使用 Watcher、Windows 一键启动器和诊断脚本。
|
|
120
137
|
|
|
121
|
-
Windows PowerShell
|
|
138
|
+
Windows PowerShell:
|
|
122
139
|
|
|
123
140
|
```powershell
|
|
124
|
-
|
|
141
|
+
git clone https://github.com/jiezeng2004-design/PatchWarden.git
|
|
142
|
+
cd .\PatchWarden
|
|
125
143
|
npm.cmd ci
|
|
126
144
|
npm.cmd run build
|
|
127
|
-
|
|
145
|
+
Copy-Item .\examples\config.example.json .\patchwarden.config.json
|
|
128
146
|
```
|
|
129
147
|
|
|
130
|
-
|
|
148
|
+
然后编辑 `patchwarden.config.json`,至少修改:
|
|
149
|
+
|
|
150
|
+
- `workspaceRoot`
|
|
151
|
+
- `agents`
|
|
152
|
+
- `allowedTestCommands`
|
|
153
|
+
|
|
154
|
+
运行只读诊断:
|
|
131
155
|
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
npm ci
|
|
135
|
-
npm run build
|
|
136
|
-
npm test
|
|
156
|
+
```powershell
|
|
157
|
+
npm.cmd run doctor
|
|
137
158
|
```
|
|
138
159
|
|
|
139
|
-
|
|
160
|
+
启动 Watcher:
|
|
161
|
+
|
|
162
|
+
```powershell
|
|
163
|
+
$env:PATCHWARDEN_CONFIG = (Resolve-Path .\patchwarden.config.json)
|
|
164
|
+
npm.cmd run watch
|
|
165
|
+
```
|
|
140
166
|
|
|
141
|
-
|
|
142
|
-
|
|
167
|
+
保持该窗口运行,再按照后文配置 OpenCode、Codex 或 ChatGPT Connector。
|
|
168
|
+
|
|
169
|
+
### 方案 B:使用 npm 包
|
|
170
|
+
|
|
171
|
+
npm 包适合让 MCP 客户端通过固定版本启动 PatchWarden。为了执行任务,
|
|
172
|
+
仍然必须另外启动 Watcher。
|
|
173
|
+
|
|
174
|
+
```powershell
|
|
175
|
+
New-Item -ItemType Directory .\patchwarden-runtime
|
|
176
|
+
Set-Location .\patchwarden-runtime
|
|
177
|
+
npm.cmd init -y
|
|
178
|
+
npm.cmd install patchwarden@0.6.0
|
|
179
|
+
Copy-Item .\node_modules\patchwarden\examples\config.example.json .\patchwarden.config.json
|
|
180
|
+
$env:PATCHWARDEN_CONFIG = (Resolve-Path .\patchwarden.config.json)
|
|
181
|
+
node .\node_modules\patchwarden\dist\runner\watch.js
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
MCP 客户端可以使用:
|
|
185
|
+
|
|
186
|
+
```text
|
|
187
|
+
npx.cmd -y patchwarden@0.6.0
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
建议固定版本号,不要在重要环境中无条件使用 `latest`。
|
|
191
|
+
|
|
192
|
+
## 完整配置说明
|
|
193
|
+
|
|
194
|
+
从示例创建本地配置:
|
|
195
|
+
|
|
196
|
+
```powershell
|
|
197
|
+
Copy-Item .\examples\config.example.json .\patchwarden.config.json
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
推荐的 Windows 示例:
|
|
143
201
|
|
|
144
202
|
```json
|
|
145
203
|
{
|
|
146
|
-
"workspaceRoot": "D:/
|
|
204
|
+
"workspaceRoot": "D:/ai_agent/codex_program",
|
|
147
205
|
"plansDir": ".patchwarden/plans",
|
|
148
206
|
"tasksDir": ".patchwarden/tasks",
|
|
149
207
|
"toolProfile": "full",
|
|
@@ -151,14 +209,21 @@ file.
|
|
|
151
209
|
"opencode": {
|
|
152
210
|
"command": "opencode",
|
|
153
211
|
"args": ["run", "{prompt}"]
|
|
212
|
+
},
|
|
213
|
+
"codex": {
|
|
214
|
+
"command": "codex",
|
|
215
|
+
"args": ["exec", "--cd", "{repo}", "{prompt}"]
|
|
154
216
|
}
|
|
155
217
|
},
|
|
156
218
|
"allowedTestCommands": [
|
|
157
219
|
"npm test",
|
|
158
220
|
"npm run build",
|
|
159
|
-
"npm run
|
|
160
|
-
"
|
|
221
|
+
"npm run lint",
|
|
222
|
+
"pytest"
|
|
161
223
|
],
|
|
224
|
+
"repoAllowedTestCommands": {
|
|
225
|
+
"desktop-app": ["npm run release:check"]
|
|
226
|
+
},
|
|
162
227
|
"maxReadFileBytes": 200000,
|
|
163
228
|
"defaultTaskTimeoutSeconds": 900,
|
|
164
229
|
"maxTaskTimeoutSeconds": 3600,
|
|
@@ -167,319 +232,785 @@ file.
|
|
|
167
232
|
}
|
|
168
233
|
```
|
|
169
234
|
|
|
170
|
-
|
|
235
|
+
字段说明:
|
|
236
|
+
|
|
237
|
+
| 字段 | 是否必需 | 说明 |
|
|
238
|
+
| --- | --- | --- |
|
|
239
|
+
| `workspaceRoot` | 是 | PatchWarden 唯一允许访问的工作区根目录。 |
|
|
240
|
+
| `plansDir` | 是 | 计划目录,通常使用 `.patchwarden/plans`。 |
|
|
241
|
+
| `tasksDir` | 是 | 任务和结果目录,通常使用 `.patchwarden/tasks`。 |
|
|
242
|
+
| `toolProfile` | 否 | `full` 或 `chatgpt_core`;本地客户端推荐 `full`。 |
|
|
243
|
+
| `agents` | 是 | 可执行 Agent 白名单;支持 `{repo}` 和 `{prompt}` 占位符。 |
|
|
244
|
+
| `allowedTestCommands` | 是 | 独立验证命令白名单,调用时必须精确匹配。 |
|
|
245
|
+
| `repoAllowedTestCommands` | 否 | 按工作区相对仓库路径增加精确验证命令;不支持通配符。 |
|
|
246
|
+
| `maxReadFileBytes` | 是 | MCP 单次文件读取上限。 |
|
|
247
|
+
| `defaultTaskTimeoutSeconds` | 是 | 默认任务超时。 |
|
|
248
|
+
| `maxTaskTimeoutSeconds` | 是 | 客户端可请求的最大任务超时。 |
|
|
249
|
+
| `watcherStaleSeconds` | 是 | Watcher 心跳超过该时间后视为失联,范围为 5–3600 秒。 |
|
|
250
|
+
| `repoAliases` | 否 | 给工作区内仓库设置简短别名。 |
|
|
251
|
+
| `httpPort` | 否 | 本地 HTTP MCP 端口,默认 7331。 |
|
|
252
|
+
| `http.ownerTokenEnv` | 否 | HTTP 鉴权 Token 所在的环境变量名。 |
|
|
253
|
+
|
|
254
|
+
配置注意事项:
|
|
255
|
+
|
|
256
|
+
- Windows JSON 路径推荐写成 `D:/path/to/project`。
|
|
257
|
+
- 如果使用反斜杠,必须写成 `D:\\path\\to\\project`。
|
|
258
|
+
- 不要把 `workspaceRoot` 设置成磁盘根目录、用户主目录、桌面、下载或文档目录。
|
|
259
|
+
- `plansDir` 和 `tasksDir` 相对于 `workspaceRoot` 解析。
|
|
260
|
+
- `repo_path` 必须位于 `workspaceRoot` 内,不能通过 `..` 跳出。
|
|
261
|
+
- `allowedTestCommands` 是精确匹配,不会把相似命令自动视为已授权。
|
|
262
|
+
- 仓库专属命令只从本机可信配置读取;目标仓库不能通过 `package.json` 自行扩权。
|
|
263
|
+
- 配置文件可能包含私人路径,默认不要提交到 Git。
|
|
264
|
+
|
|
265
|
+
设置配置路径:
|
|
171
266
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
- Do not place secrets inside the workspace.
|
|
176
|
-
- Keep agent commands and test commands narrow.
|
|
267
|
+
```powershell
|
|
268
|
+
$env:PATCHWARDEN_CONFIG = "D:\path\to\patchwarden.config.json"
|
|
269
|
+
```
|
|
177
270
|
|
|
178
|
-
|
|
271
|
+
该环境变量只影响当前 PowerShell 及其子进程。如果从另一个窗口启动 Watcher
|
|
272
|
+
或 MCP Server,需要在那个窗口重新设置。
|
|
179
273
|
|
|
180
|
-
|
|
274
|
+
## 接入 OpenCode
|
|
181
275
|
|
|
182
|
-
|
|
183
|
-
|
|
276
|
+
推荐从本地源码启动,以便版本、Watcher 和配置文件保持一致。
|
|
277
|
+
|
|
278
|
+
编辑 OpenCode 配置:
|
|
279
|
+
|
|
280
|
+
```text
|
|
281
|
+
%USERPROFILE%\.config\opencode\opencode.jsonc
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
示例:
|
|
285
|
+
|
|
286
|
+
```jsonc
|
|
287
|
+
{
|
|
288
|
+
"mcp": {
|
|
289
|
+
"patchwarden": {
|
|
290
|
+
"type": "local",
|
|
291
|
+
"command": [
|
|
292
|
+
"node",
|
|
293
|
+
"D:/path/to/PatchWarden/dist/index.js"
|
|
294
|
+
],
|
|
295
|
+
"environment": {
|
|
296
|
+
"PATCHWARDEN_CONFIG": "D:/path/to/PatchWarden/patchwarden.config.json",
|
|
297
|
+
"PATCHWARDEN_TOOL_PROFILE": "full"
|
|
298
|
+
},
|
|
299
|
+
"enabled": true
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
184
303
|
```
|
|
185
304
|
|
|
186
|
-
|
|
305
|
+
验证:
|
|
187
306
|
|
|
188
307
|
```powershell
|
|
189
|
-
|
|
190
|
-
|
|
308
|
+
opencode mcp list
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
预期看到:
|
|
312
|
+
|
|
313
|
+
```text
|
|
314
|
+
patchwarden connected
|
|
191
315
|
```
|
|
192
316
|
|
|
193
|
-
|
|
317
|
+
然后在 PatchWarden 项目目录的另一个 PowerShell 窗口启动:
|
|
194
318
|
|
|
195
319
|
```powershell
|
|
196
|
-
$env:PATCHWARDEN_CONFIG =
|
|
320
|
+
$env:PATCHWARDEN_CONFIG = (Resolve-Path .\patchwarden.config.json)
|
|
197
321
|
npm.cmd run watch
|
|
198
322
|
```
|
|
199
323
|
|
|
200
|
-
|
|
324
|
+
如果 OpenCode 能看到 MCP 工具,但创建的任务一直 queued,先检查 Watcher,
|
|
325
|
+
不要反复删除并重建 MCP 配置。
|
|
201
326
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
327
|
+
## 接入 Codex
|
|
328
|
+
|
|
329
|
+
编辑:
|
|
330
|
+
|
|
331
|
+
```text
|
|
332
|
+
%USERPROFILE%\.codex\config.toml
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
使用 npm 固定版本:
|
|
336
|
+
|
|
337
|
+
```toml
|
|
338
|
+
[mcp_servers.patchwarden]
|
|
339
|
+
command = "npx.cmd"
|
|
340
|
+
args = ["-y", "patchwarden@0.6.0"]
|
|
341
|
+
|
|
342
|
+
[mcp_servers.patchwarden.env]
|
|
343
|
+
PATCHWARDEN_CONFIG = "D:\\path\\to\\patchwarden.config.json"
|
|
344
|
+
PATCHWARDEN_TOOL_PROFILE = "full"
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
或使用本地源码:
|
|
348
|
+
|
|
349
|
+
```toml
|
|
350
|
+
[mcp_servers.patchwarden]
|
|
351
|
+
command = "node"
|
|
352
|
+
args = ["D:\\path\\to\\PatchWarden\\dist\\index.js"]
|
|
353
|
+
|
|
354
|
+
[mcp_servers.patchwarden.env]
|
|
355
|
+
PATCHWARDEN_CONFIG = "D:\\path\\to\\PatchWarden\\patchwarden.config.json"
|
|
356
|
+
PATCHWARDEN_TOOL_PROFILE = "full"
|
|
205
357
|
```
|
|
206
358
|
|
|
207
|
-
|
|
359
|
+
修改后完全退出并重新打开 Codex Desktop,再新建会话。已经打开的会话可能仍
|
|
360
|
+
保留旧 MCP 工具目录。
|
|
208
361
|
|
|
209
|
-
|
|
362
|
+
同样需要单独运行 Watcher。Codex 作为 **MCP 客户端** 和 Codex CLI 作为
|
|
363
|
+
**任务执行 Agent** 是两个不同角色;前者连接成功不能证明后者命令可用。
|
|
210
364
|
|
|
211
|
-
|
|
365
|
+
## 接入 ChatGPT Connector
|
|
366
|
+
|
|
367
|
+
推荐的 Windows 链路:
|
|
212
368
|
|
|
213
369
|
```text
|
|
214
370
|
ChatGPT Web
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
371
|
+
→ ChatGPT Connector
|
|
372
|
+
→ OpenAI Secure MCP Tunnel
|
|
373
|
+
→ PatchWarden stdio MCP
|
|
374
|
+
→ Watcher
|
|
375
|
+
→ 本地 Agent
|
|
220
376
|
```
|
|
221
377
|
|
|
222
|
-
|
|
378
|
+
### 一键启动
|
|
379
|
+
|
|
380
|
+
准备好以下内容:
|
|
381
|
+
|
|
382
|
+
- 已构建的 PatchWarden 源码目录
|
|
383
|
+
- 有效的 `patchwarden.config.json`
|
|
384
|
+
- `tunnel-client.exe`
|
|
385
|
+
- Tunnel ID
|
|
386
|
+
- Tunnel runtime API Key
|
|
387
|
+
- 可用的 HTTP 代理及受支持的出口区域
|
|
388
|
+
|
|
389
|
+
先按下一节配置代理,然后运行:
|
|
223
390
|
|
|
224
391
|
```text
|
|
225
|
-
|
|
392
|
+
PatchWarden.cmd start core
|
|
226
393
|
```
|
|
227
394
|
|
|
228
|
-
|
|
229
|
-
root, and starts `node dist/index.js`. It prevents tunnel-client from using
|
|
230
|
-
the tunnel-client directory as the MCP workspace.
|
|
395
|
+
启动器会:
|
|
231
396
|
|
|
232
|
-
|
|
397
|
+
- 检查 `dist/index.js`,缺失时自动构建。
|
|
398
|
+
- 校验 `chatgpt_core` 的版本、16 个核心工具和 Schema Manifest。
|
|
399
|
+
- 读取或提示输入 Tunnel ID。
|
|
400
|
+
- 读取或提示输入运行时 API Key。
|
|
401
|
+
- 使用 Windows DPAPI 保存凭据到 `%APPDATA%\patchwarden`。
|
|
402
|
+
- 启动并监督由当前启动器拥有的 Watcher。
|
|
403
|
+
- 运行 `tunnel-client doctor` 和 readiness 检查。
|
|
404
|
+
- 对可恢复断线做限速重试,不会无限快速重启。
|
|
233
405
|
|
|
234
|
-
|
|
406
|
+
运行时状态位于:
|
|
235
407
|
|
|
236
408
|
```text
|
|
237
|
-
|
|
409
|
+
%LOCALAPPDATA%\patchwarden\runtime
|
|
238
410
|
```
|
|
239
411
|
|
|
240
|
-
|
|
412
|
+
这里包含 PID、健康状态和脱敏诊断信息,不应包含 API Key 或 Tunnel ID。
|
|
413
|
+
|
|
414
|
+
ChatGPT Connector 创建时:
|
|
415
|
+
|
|
416
|
+
- 选择 Tunnel 的 **Channel**。
|
|
417
|
+
- 除非自行实现了 OAuth,否则认证选择 **None**。
|
|
418
|
+
- 不要把本地 `127.0.0.1` URL 当成公网 Server URL。
|
|
419
|
+
- 创建或更新 Connector 后,重新连接并新开一个 ChatGPT 对话。
|
|
420
|
+
- Platform 页面异常时,先关闭网页翻译扩展再重试。
|
|
421
|
+
|
|
422
|
+
更完整的 Tunnel 示例见
|
|
423
|
+
[examples/openai-tunnel/README.md](examples/openai-tunnel/README.md)。
|
|
424
|
+
|
|
425
|
+
## 代理配置:必须先看
|
|
426
|
+
|
|
427
|
+
### 一键脚本的默认值
|
|
428
|
+
|
|
429
|
+
`scripts/start-patchwarden-tunnel.ps1` 优先读取当前进程的
|
|
430
|
+
`HTTPS_PROXY`。如果没有设置,它会默认使用:
|
|
431
|
+
|
|
432
|
+
```text
|
|
433
|
+
http://127.0.0.1:7892
|
|
434
|
+
```
|
|
241
435
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
- starts a hidden watcher owned by the launcher when no healthy external watcher exists
|
|
246
|
-
- supervises only its owned watcher and retries stale/exited instances with a
|
|
247
|
-
capped 2/5/10/20/30-second backoff
|
|
248
|
-
- runs machine-readable `tunnel-client doctor` checks
|
|
249
|
-
- performs a real stdio MCP `initialize` plus `tools/list` preflight and stops
|
|
250
|
-
before tunnel startup if the core tools or v0.4.0 schemas are missing
|
|
251
|
-
- supervises `tunnel-client run`, probes readiness, and retries recoverable
|
|
252
|
-
exits with a capped 5/10/20/30-second backoff
|
|
253
|
-
- stops on non-retryable authentication, configuration, region, or control
|
|
254
|
-
plane errors instead of looping blindly
|
|
436
|
+
**7892 不是通用端口。** Clash、Mihomo、V2Ray、sing-box 或其他代理工具
|
|
437
|
+
可能使用 7890、7897、10809 或自定义端口。请在代理软件中确认
|
|
438
|
+
HTTP/Mixed 监听端口,不要照抄示例。
|
|
255
439
|
|
|
256
|
-
|
|
440
|
+
先测试端口:
|
|
257
441
|
|
|
258
442
|
```powershell
|
|
259
|
-
|
|
260
|
-
$env:TUNNEL_CLIENT_EXE = "C:\path\to\tunnel-client.exe"
|
|
261
|
-
$env:OPENCODE_BIN_DIR = "C:\path\to\opencode-ai\bin"
|
|
262
|
-
$env:HTTPS_PROXY = "http://127.0.0.1:7892"
|
|
263
|
-
$env:PATCHWARDEN_CREDENTIAL_PATH = "C:\private\patchwarden-key.dpapi"
|
|
443
|
+
Test-NetConnection 127.0.0.1 -Port 7892
|
|
264
444
|
```
|
|
265
445
|
|
|
266
|
-
|
|
267
|
-
written to the repository or printed to logs. To remove it, run
|
|
268
|
-
`Reset-PatchWarden-Tunnel-Key.cmd`.
|
|
446
|
+
如果 `TcpTestSucceeded` 为 `False`,说明该端口没有代理服务。
|
|
269
447
|
|
|
270
|
-
|
|
271
|
-
private workspace IDs.
|
|
448
|
+
### 推荐设置
|
|
272
449
|
|
|
273
|
-
|
|
450
|
+
以下命令只影响当前 PowerShell 和从它启动的子进程,不修改系统级环境变量:
|
|
451
|
+
|
|
452
|
+
```powershell
|
|
453
|
+
$env:HTTPS_PROXY = "http://127.0.0.1:你的HTTP或Mixed端口"
|
|
454
|
+
$env:HTTP_PROXY = $env:HTTPS_PROXY
|
|
455
|
+
$env:ALL_PROXY = $env:HTTPS_PROXY
|
|
456
|
+
$env:NO_PROXY = "localhost,127.0.0.1,::1"
|
|
457
|
+
.\PatchWarden.cmd start core
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
例如代理软件的 Mixed 端口是 7890:
|
|
461
|
+
|
|
462
|
+
```powershell
|
|
463
|
+
$env:HTTPS_PROXY = "http://127.0.0.1:7890"
|
|
464
|
+
$env:HTTP_PROXY = $env:HTTPS_PROXY
|
|
465
|
+
$env:ALL_PROXY = $env:HTTPS_PROXY
|
|
466
|
+
$env:NO_PROXY = "localhost,127.0.0.1,::1"
|
|
467
|
+
.\PatchWarden.cmd start core
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
这里的 `HTTPS_PROXY=http://...` 并不矛盾:变量名表示 HTTPS 请求通过代理,
|
|
471
|
+
URL 的 `http://` 表示连接到本地 HTTP 代理端口。不要把只支持 SOCKS 的端口
|
|
472
|
+
误填到当前 `--http-proxy` 参数中。
|
|
473
|
+
|
|
474
|
+
### 三条不同的网络路径
|
|
475
|
+
|
|
476
|
+
| 网络路径 | 是否需要代理 | 说明 |
|
|
477
|
+
| --- | --- | --- |
|
|
478
|
+
| Tunnel → OpenAI control plane | 通常需要 | 一键启动器通过 `HTTPS_PROXY` 传给 tunnel-client。 |
|
|
479
|
+
| PatchWarden → `127.0.0.1` | 不需要 | 必须保留 `NO_PROXY=localhost,127.0.0.1,::1`。 |
|
|
480
|
+
| 本地 Agent → 模型提供方 API | 视 Agent 而定 | Watcher/Agent 可能继承当前终端的代理变量。 |
|
|
481
|
+
| npm / GitHub | 视网络而定 | 与 Tunnel 是否健康是两回事,要分别诊断。 |
|
|
482
|
+
|
|
483
|
+
如果手动启动 Watcher,希望它和子 Agent 使用同一代理,要在启动 Watcher
|
|
484
|
+
的那个 PowerShell 窗口设置代理变量。
|
|
485
|
+
|
|
486
|
+
### 地域错误不是代码错误
|
|
487
|
+
|
|
488
|
+
如果日志出现:
|
|
274
489
|
|
|
275
490
|
```text
|
|
276
|
-
|
|
491
|
+
unsupported_country_region_territory
|
|
492
|
+
403 Forbidden
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
说明代理出口区域不被当前 OpenAI control plane 接受。继续重装依赖、
|
|
496
|
+
重建 `dist` 或反复登录通常无效;应先切换到受支持的出口区域,再重新启动
|
|
497
|
+
Tunnel。支持范围可能变化,因此不要在项目里写死国家列表。
|
|
498
|
+
|
|
499
|
+
### 代理配置检查顺序
|
|
500
|
+
|
|
501
|
+
1. 代理软件是否正在运行。
|
|
502
|
+
2. 填写的是 HTTP/Mixed 端口,而不是随手复制的示例端口。
|
|
503
|
+
3. `Test-NetConnection` 是否成功。
|
|
504
|
+
4. `HTTPS_PROXY` 是否在启动 Tunnel 的同一个 PowerShell 中设置。
|
|
505
|
+
5. `NO_PROXY` 是否包含本地地址。
|
|
506
|
+
6. 出口区域是否受支持。
|
|
507
|
+
7. 再运行 `PatchWarden.cmd health` 和 tunnel-client doctor。
|
|
508
|
+
|
|
509
|
+
## 标准任务工作流
|
|
510
|
+
|
|
511
|
+
推荐顺序:
|
|
512
|
+
|
|
513
|
+
1. `health_check`:确认版本、工作区、Watcher 和工具目录。
|
|
514
|
+
2. `list_agents`:确认本地 Agent 命令可用。
|
|
515
|
+
3. `list_workspace`:确定 `repo_path`。
|
|
516
|
+
4. `save_plan`,或在创建任务时提供 `inline_plan`。
|
|
517
|
+
5. `create_task`:明确 Agent、仓库和验证命令。
|
|
518
|
+
6. 短任务使用 `wait_for_task(timeout_seconds: 25)`;长任务使用 `list_tasks` 和 `get_task_status` 轮询。
|
|
519
|
+
7. `get_task_summary(view: "compact")`:先看有界结构化总结。
|
|
520
|
+
8. `get_result_json`、`get_diff`、`get_test_log`:按需查看细节。
|
|
521
|
+
9. `audit_task`:独立核对执行结果。
|
|
522
|
+
10. 人工决定是否接受、提交或发布。
|
|
523
|
+
|
|
524
|
+
`create_task` 示例:
|
|
525
|
+
|
|
526
|
+
```json
|
|
527
|
+
{
|
|
528
|
+
"agent": "opencode",
|
|
529
|
+
"repo_path": "my-project",
|
|
530
|
+
"inline_plan": "修复登录页的表单校验,不改动无关文件,并补充回归测试。",
|
|
531
|
+
"verify_commands": [
|
|
532
|
+
"npm run build",
|
|
533
|
+
"npm test"
|
|
534
|
+
],
|
|
535
|
+
"timeout_seconds": 900
|
|
536
|
+
}
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
要求:
|
|
540
|
+
|
|
541
|
+
- `repo_path` 必须在 `workspaceRoot` 内。
|
|
542
|
+
- `verify_commands` 必须逐字匹配全局或当前仓库的可信命令白名单。
|
|
543
|
+
- `plan_id`、`inline_plan`、`template` 三种计划来源必须且只能选择一种。
|
|
544
|
+
- `wait_for_task` 返回 `continuation_required: true` 时,应继续调用。
|
|
545
|
+
- `terminal: true` 只表示任务进入终态,不代表结果一定正确。
|
|
546
|
+
|
|
547
|
+
内置模板:
|
|
548
|
+
|
|
549
|
+
- `inspect_only`
|
|
550
|
+
- `feature_small`
|
|
551
|
+
- `fix_tests`
|
|
552
|
+
- `release_check`
|
|
553
|
+
- `rollback_scope_violation`
|
|
554
|
+
|
|
555
|
+
ChatGPT 任务应优先选择前三个守护模板:只读诊断使用 `inspect_only`,小范围功能修改使用 `feature_small`,已知测试失败修复使用 `fix_tests`。只有模板无法准确表达目标时,才使用 `inline_plan` 或已保存的长计划。建议先以 `execution_mode: "assess_only"` 评估,再直接调用返回的 `next_tool_call`;执行阶段不要重复发送 goal、plan、仓库或验证参数。
|
|
556
|
+
|
|
557
|
+
`inspect_only` 和回滚审查模板如果修改文件,会以
|
|
558
|
+
`failed_policy_violation` 失败。回滚审查只生成方案,不会自动回滚用户修改。
|
|
559
|
+
|
|
560
|
+
`audit_task` 的 `fail` 检查会列入 `confirmed_failures`;启发式警告会单独列入 `possible_false_positives` 和 `manual_verification_items`。因此 `warn` 不等于已确认错误,仍需按人工核实项检查证据。
|
|
561
|
+
|
|
562
|
+
### 任务产物
|
|
563
|
+
|
|
564
|
+
| 文件 | 用途 |
|
|
565
|
+
| --- | --- |
|
|
566
|
+
| `status.json` | 当前状态、阶段、心跳和错误信息。 |
|
|
567
|
+
| `progress.md` | Agent 写入的进度记录。 |
|
|
568
|
+
| `result.md` | 人类可读的执行报告。 |
|
|
569
|
+
| `result.json` | 结构化结果、路径、变更、警告和后续建议。 |
|
|
570
|
+
| `diff.patch` | 完整任务差异证据。 |
|
|
571
|
+
| `file-stats.json` | 文件级增删统计。 |
|
|
572
|
+
| `verify.json` | 每条独立验证命令的结构化记录。 |
|
|
573
|
+
| `verify.log` | 独立验证的可读日志。 |
|
|
574
|
+
| `test.log` | Agent 执行过程中产生的测试输出。 |
|
|
575
|
+
|
|
576
|
+
本地 Agent 声称“已推送”“已发布”不属于可靠的远程证据。GitHub、npm、
|
|
577
|
+
Tag 和 Release 必须再用对应平台的实时状态核验。
|
|
578
|
+
|
|
579
|
+
## HTTP MCP 模式
|
|
580
|
+
|
|
581
|
+
HTTP Server 只绑定 `127.0.0.1`,默认端口 7331,不会直接监听局域网。
|
|
582
|
+
|
|
583
|
+
终端 1,启动 Watcher:
|
|
584
|
+
|
|
585
|
+
```powershell
|
|
586
|
+
$env:PATCHWARDEN_CONFIG = (Resolve-Path .\patchwarden.config.json)
|
|
587
|
+
npm.cmd run watch
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
终端 2,启动 HTTP MCP:
|
|
591
|
+
|
|
592
|
+
```powershell
|
|
593
|
+
$env:PATCHWARDEN_CONFIG = (Resolve-Path .\patchwarden.config.json)
|
|
594
|
+
npm.cmd run start:http
|
|
277
595
|
```
|
|
278
596
|
|
|
279
|
-
|
|
280
|
-
source, tool profile/count/names/schema hash, workspace/tasks access, watcher
|
|
281
|
-
freshness, configured agents, tunnel readiness, and other detected
|
|
282
|
-
PatchWarden processes. It only warns about mixed versions and never ends a
|
|
283
|
-
process. Runtime status is stored under `%LOCALAPPDATA%\patchwarden\runtime`
|
|
284
|
-
and does not contain the API key or Tunnel ID.
|
|
597
|
+
健康检查:
|
|
285
598
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
without creating a task that depends on the watcher.
|
|
599
|
+
```powershell
|
|
600
|
+
Invoke-RestMethod http://127.0.0.1:7331/healthz
|
|
601
|
+
```
|
|
290
602
|
|
|
291
|
-
|
|
292
|
-
upgrade, or hung process), double-click:
|
|
603
|
+
MCP 地址:
|
|
293
604
|
|
|
294
605
|
```text
|
|
295
|
-
|
|
606
|
+
http://127.0.0.1:7331/mcp
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
可选 Token 配置:
|
|
610
|
+
|
|
611
|
+
```json
|
|
612
|
+
{
|
|
613
|
+
"httpPort": 7331,
|
|
614
|
+
"http": {
|
|
615
|
+
"ownerTokenEnv": "PATCHWARDEN_OWNER_TOKEN"
|
|
616
|
+
}
|
|
617
|
+
}
|
|
296
618
|
```
|
|
297
619
|
|
|
298
|
-
|
|
299
|
-
rebuilds the project, clears stale runtime state, and opens a fresh tunnel
|
|
300
|
-
launcher window. It does not stop unrelated or legacy PatchWarden instances.
|
|
620
|
+
在启动 Server 的当前 PowerShell 中设置:
|
|
301
621
|
|
|
302
|
-
|
|
622
|
+
```powershell
|
|
623
|
+
$env:PATCHWARDEN_OWNER_TOKEN = "请使用随机且仅保存在本机的值"
|
|
624
|
+
```
|
|
303
625
|
|
|
304
|
-
|
|
305
|
-
|
|
626
|
+
客户端可使用 `Authorization: Bearer ...` 或 `x-patchwarden-token`。
|
|
627
|
+
不要把 Token 直接写进配置、README、日志或 Git。
|
|
306
628
|
|
|
307
|
-
|
|
629
|
+
> [!CAUTION]
|
|
630
|
+
> 不要通过路由器端口映射、`0.0.0.0` 转发或普通反向代理直接公开
|
|
631
|
+
> 本地 7331 端口。远程接入应使用经过认证的安全 Tunnel。
|
|
308
632
|
|
|
309
|
-
|
|
633
|
+
## 诊断与健康检查
|
|
310
634
|
|
|
311
|
-
|
|
312
|
-
not receive `PATCHWARDEN_CONFIG` or started from the wrong working directory.
|
|
635
|
+
项目诊断:
|
|
313
636
|
|
|
314
|
-
|
|
315
|
-
|
|
637
|
+
```powershell
|
|
638
|
+
npm.cmd run doctor
|
|
639
|
+
```
|
|
316
640
|
|
|
317
|
-
|
|
641
|
+
它会检查 Node、npm、Git、配置、工作区、路径保护、敏感文件保护、Agent
|
|
642
|
+
命令、工具 Manifest、HTTP 端口、Watcher 目录和构建产物。
|
|
318
643
|
|
|
319
|
-
|
|
644
|
+
### 统一 Windows 控制入口
|
|
645
|
+
|
|
646
|
+
双击 `PatchWarden.cmd` 会打开统一菜单,可分别或同时管理 Core Agent 和
|
|
647
|
+
Direct 两种模式的启动、停止、重启与状态。也可以在 PowerShell 中直接调用:
|
|
648
|
+
|
|
649
|
+
```powershell
|
|
650
|
+
.\PatchWarden.cmd start core
|
|
651
|
+
.\PatchWarden.cmd start direct
|
|
652
|
+
.\PatchWarden.cmd stop all
|
|
653
|
+
.\PatchWarden.cmd restart all
|
|
654
|
+
.\PatchWarden.cmd status all
|
|
655
|
+
.\PatchWarden.cmd kill all
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
旧的单用途入口保留在 `scripts/launchers/` 作为兼容层;个人入口位于
|
|
659
|
+
`.local/launchers/`,并继续被 Git 和发布包排除。`stop` / `restart` 会同时检查
|
|
660
|
+
运行状态、精确的 Tunnel Profile、项目启动器和进程树,因此可以清理同一 Profile
|
|
661
|
+
遗留的 `tunnel-client.exe`,但不会结束无关进程。`kill` 是显式强制清理入口,
|
|
662
|
+
仍受相同的 Profile 和项目路径约束;发现 8080/8081 被无关进程占用时会停止操作并报告 PID。
|
|
663
|
+
|
|
664
|
+
`status` 会交叉检查 runtime JSON、health URL 文件、固定的 `/readyz` / `/healthz`
|
|
665
|
+
端点和真实进程。即使状态文件陈旧,只要 health endpoint 已 ready,也会报告实际运行状态。
|
|
666
|
+
supervisor 的最新输出位于:
|
|
320
667
|
|
|
321
668
|
```text
|
|
322
|
-
|
|
669
|
+
%LOCALAPPDATA%\patchwarden\runtime\tunnel-client.stdout.log
|
|
670
|
+
%LOCALAPPDATA%\patchwarden\runtime\tunnel-client.stderr.log
|
|
671
|
+
%LOCALAPPDATA%\patchwarden\runtime-direct\tunnel-client.stdout.log
|
|
672
|
+
%LOCALAPPDATA%\patchwarden\runtime-direct\tunnel-client.stderr.log
|
|
323
673
|
```
|
|
324
674
|
|
|
325
|
-
|
|
675
|
+
非零退出时,窗口会显示 stderr 最后 30 行;`tunnel-status.json` 同时记录退出码、
|
|
676
|
+
脱敏后的 stdout/stderr tail 和日志路径,不会输出 API Key 值。
|
|
677
|
+
|
|
678
|
+
Windows Tunnel 深度健康检查:
|
|
326
679
|
|
|
327
680
|
```text
|
|
328
|
-
|
|
329
|
-
403 Forbidden
|
|
681
|
+
PatchWarden.cmd health
|
|
330
682
|
```
|
|
331
683
|
|
|
332
|
-
|
|
333
|
-
plane. Change to a supported region and restart tunnel-client.
|
|
684
|
+
它会报告:
|
|
334
685
|
|
|
335
|
-
|
|
686
|
+
- 源码版本和 `dist` 版本
|
|
687
|
+
- 实际 MCP 进程来源
|
|
688
|
+
- 工具 Profile、数量、名称和 Schema Hash
|
|
689
|
+
- 工作区和任务目录访问状态
|
|
690
|
+
- Watcher 心跳
|
|
691
|
+
- Tunnel readiness
|
|
692
|
+
- 是否存在混合版本进程
|
|
336
693
|
|
|
337
|
-
|
|
338
|
-
has ended. Do not rely on a prompt that says only "wait and check later".
|
|
339
|
-
Immediately call `wait_for_task` after `create_task`. If its response contains
|
|
340
|
-
`continuation_required: true`, call it again in the same assistant turn. When
|
|
341
|
-
`terminal: true`, use the included summary and then call `audit_task` for the
|
|
342
|
-
independent review. Each wait is capped at 30 seconds to stay below common
|
|
343
|
-
connector and tunnel request timeouts.
|
|
694
|
+
它只读诊断,不会结束进程。
|
|
344
695
|
|
|
345
|
-
|
|
696
|
+
MCP 内部的扩展诊断:
|
|
697
|
+
|
|
698
|
+
```json
|
|
699
|
+
{
|
|
700
|
+
"detail": "self_diagnostic"
|
|
701
|
+
}
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
可配合 `health_check` 查看 Agent、白名单、最近失败任务和工具目录一致性。
|
|
705
|
+
|
|
706
|
+
配置或版本更新后需要完整重启时,可运行:
|
|
707
|
+
|
|
708
|
+
```text
|
|
709
|
+
PatchWarden.cmd restart all
|
|
710
|
+
```
|
|
346
711
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
confirm `configured_tunnel_manifest.tool_profile` is `chatgpt_core`, its
|
|
350
|
-
`tool_count` is 16, and the next tunnel status reports `core_tools_ready` as
|
|
351
|
-
true. Then refresh or reconnect the Connector and open a
|
|
352
|
-
new ChatGPT conversation. Do not use the old conversation as proof that the
|
|
353
|
-
new schema was loaded. `health_check` exposes `server_version`, `schema_epoch`,
|
|
354
|
-
and `tool_manifest_sha256` so the same tool names with stale schemas can still
|
|
355
|
-
be distinguished.
|
|
712
|
+
该命令只停止当前项目拥有的启动器/Watcher,以及 Profile 精确匹配的
|
|
713
|
+
`tunnel-client.exe`,不会全局结束其他 PatchWarden、OpenCode 或 Codex 实例。
|
|
356
714
|
|
|
357
|
-
|
|
358
|
-
PatchWarden returns `tool_catalog_mismatch` with the current tool manifest and
|
|
359
|
-
refresh instructions instead of a generic unavailable-tool error.
|
|
715
|
+
### Core 与 Direct 并发运行
|
|
360
716
|
|
|
361
|
-
|
|
717
|
+
Core Agent 和 Direct 可以**同时运行**,使用不同的 `tunnel-client` profile:
|
|
362
718
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
watcher process it created; external and legacy instances are never stopped.
|
|
719
|
+
| 模式 | Profile | Tool Profile | 默认 Health 端口 |
|
|
720
|
+
| --- | --- | --- | --- |
|
|
721
|
+
| Core | `patchwarden` | `chatgpt_core` | `127.0.0.1:8080` |
|
|
722
|
+
| Direct | `patchwarden-direct` | `chatgpt_direct` | `127.0.0.1:8081` |
|
|
368
723
|
|
|
369
|
-
|
|
724
|
+
为避免两个 tunnel-client 实例的 health 端口冲突,启动时需要显式指定端口:
|
|
725
|
+
|
|
726
|
+
**Core 启动示例:**
|
|
727
|
+
|
|
728
|
+
```cmd
|
|
729
|
+
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%CD%\scripts\start-patchwarden-tunnel.ps1" -ToolProfile chatgpt_core -Profile patchwarden -HealthListenAddr 127.0.0.1:8080
|
|
730
|
+
```
|
|
731
|
+
|
|
732
|
+
**Direct 启动示例:**
|
|
733
|
+
|
|
734
|
+
```cmd
|
|
735
|
+
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%CD%\scripts\start-patchwarden-tunnel.ps1" -ToolProfile chatgpt_direct -Profile patchwarden-direct -HealthListenAddr 127.0.0.1:8081 -SkipWatcher
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
如果使用 `.local\launchers\` 下的个人启动器,也需要同步追加对应
|
|
739
|
+
`-HealthListenAddr` 参数(`Start-PatchWarden-Tunnel.local.cmd` 加 `-HealthListenAddr 127.0.0.1:8080`,
|
|
740
|
+
`Start-PatchWarden-Direct-Tunnel.local.cmd` 加 `-HealthListenAddr 127.0.0.1:8081`)。
|
|
741
|
+
|
|
742
|
+
如果未传入 `-HealthListenAddr`,脚本会根据 Profile 自动选择:
|
|
743
|
+
`chatgpt_core` / `patchwarden` → `127.0.0.1:8080`,
|
|
744
|
+
`chatgpt_direct` / `patchwarden-direct` → `127.0.0.1:8081`。
|
|
745
|
+
|
|
746
|
+
## 踩坑记录与故障排查
|
|
747
|
+
|
|
748
|
+
### 快速对照表
|
|
749
|
+
|
|
750
|
+
| 现象 | 最可能原因 | 处理方式 |
|
|
751
|
+
| --- | --- | --- |
|
|
752
|
+
| Tunnel 一直连接超时 | 默认 7892 没有代理服务 | 确认实际 HTTP/Mixed 端口,设置 `HTTPS_PROXY` 后从同一窗口启动。 |
|
|
753
|
+
| 日志出现 403 和 `unsupported_country_region_territory` | 代理出口区域不受支持 | 切换出口区域,再重启 Tunnel。 |
|
|
754
|
+
| `list_workspace` 只看到 `tunnel-client.exe` | MCP 从错误目录启动或没收到配置路径 | 使用 `scripts/patchwarden-mcp-stdio.cmd`。 |
|
|
755
|
+
| MCP 显示 connected,但任务不执行 | Watcher 没启动或心跳过期 | 启动 `npm.cmd run watch`,再看 `health_check`。 |
|
|
756
|
+
| `Agent command not found` | Agent 不在 PATH,或 Codex Desktop 被误当成 CLI | 运行 `where.exe`,必要时在 `agents.command` 写真实 CLI 路径。 |
|
|
757
|
+
| 验证命令被拒绝 | 与白名单不是逐字一致 | 把确切命令加入 `allowedTestCommands`,不要扩大成任意 Shell。 |
|
|
758
|
+
| ChatGPT 仍显示旧工具 | Connector 或旧对话缓存了旧 Catalog | 重连 Connector,并新建 ChatGPT 对话。 |
|
|
759
|
+
| ChatGPT 在 `create_task` 后停住 | 没在同一轮继续调用 `wait_for_task` | 按 `continuation_required` 循环等待,直到 `terminal: true`。 |
|
|
760
|
+
| HTTP 启动时报 `EADDRINUSE` | 7331 已被其他进程占用 | 检查已有实例,或修改 `httpPort`。 |
|
|
761
|
+
| DPAPI 凭据无法解密 | 更换了 Windows 用户、电脑或凭据文件损坏 | 运行 `PatchWarden.cmd reset-key` 后重新输入。 |
|
|
762
|
+
| 修改代码后行为没变化 | 仍在运行旧 `dist` 或旧进程 | 重新 build,检查版本/Manifest,再重启受控进程。 |
|
|
763
|
+
| 两个 tunnel 同时启动时第二个立刻退出 | health 端口冲突(两个 profile 都用了 `127.0.0.1:8080`) | 确保 core 用 8080、direct 用 8081;检查 `patchwarden.yaml` 和 `patchwarden-direct.yaml` 的 `health.listen_addr`;重新运行启动器让脚本自动修复。 |
|
|
764
|
+
| supervisor 只看到 exit code 1 | tunnel-client 的真实错误在子进程 stderr | 查看对应 runtime 的 `tunnel-client.stderr.log`,或查看 `tunnel-status.json.stderr_tail`。 |
|
|
765
|
+
| core 错误地从 `opencode-config\tunnel-client` 读取 Profile | 旧启动器把 Watcher 的 `XDG_CONFIG_HOME` 泄漏给 tunnel-client | 升级到 v0.6.0 并执行 `PatchWarden.cmd restart core`;新版本会隔离 Watcher 专用环境。 |
|
|
766
|
+
| npm MCP 握手成功但任务始终 queued | npm 只启动了 MCP Server,没有 Watcher | 在本地安装目录启动 `dist/runner/watch.js`。 |
|
|
767
|
+
| 配置明明存在却提示找不到 | 环境变量只在另一个终端设置,或路径转义错误 | 使用绝对路径,并在启动当前进程的终端设置 `PATCHWARDEN_CONFIG`。 |
|
|
768
|
+
| 旧名称环境变量无效 | v0.4.0 是破坏性改名 | 全部改成 `PATCHWARDEN_*`,旧配置不会自动回退。 |
|
|
769
|
+
|
|
770
|
+
### 坑 1:把“connected”误认为整个链路正常
|
|
771
|
+
|
|
772
|
+
MCP connected 只证明客户端成功启动了 PatchWarden MCP Server。完整链路还要
|
|
773
|
+
验证:
|
|
774
|
+
|
|
775
|
+
1. `health_check` 能看到正确的工作区。
|
|
776
|
+
2. `list_agents` 能找到执行 Agent。
|
|
777
|
+
3. Watcher 心跳新鲜。
|
|
778
|
+
4. `create_task` 后任务能从 queued 进入 running。
|
|
779
|
+
|
|
780
|
+
### 坑 2:代理端口照抄 7892
|
|
781
|
+
|
|
782
|
+
7892 只是当前启动脚本的默认值,不是 Clash 或其他软件的统一标准。
|
|
783
|
+
这是最常见的连接超时来源之一。先看代理软件设置,再运行
|
|
784
|
+
`Test-NetConnection`,不要先重装 Node 或 PatchWarden。
|
|
785
|
+
|
|
786
|
+
### 坑 3:把本地地址也送进代理
|
|
787
|
+
|
|
788
|
+
HTTP MCP、健康页和 tunnel-client 本地 UI 都使用环回地址。如果系统代理或
|
|
789
|
+
全局代理错误拦截了 `localhost`,本地服务可能明明已启动却访问失败。
|
|
790
|
+
保留:
|
|
370
791
|
|
|
371
792
|
```powershell
|
|
372
|
-
$env:
|
|
793
|
+
$env:NO_PROXY = "localhost,127.0.0.1,::1"
|
|
373
794
|
```
|
|
374
795
|
|
|
375
|
-
###
|
|
796
|
+
### 坑 4:旧会话继续使用旧 Schema
|
|
797
|
+
|
|
798
|
+
Connector 和 MCP 客户端可能在会话建立时缓存工具目录。即使代码已更新,
|
|
799
|
+
旧对话仍可能显示旧工具或旧参数。应比较 `server_version`、
|
|
800
|
+
`schema_epoch` 和 `tool_manifest_sha256`,然后重连并新建会话。
|
|
801
|
+
|
|
802
|
+
### 坑 5:Watcher 假死或误杀其他实例
|
|
803
|
+
|
|
804
|
+
PatchWarden 使用心跳判断 Watcher 是否健康。一键启动器只监督自己创建的
|
|
805
|
+
Watcher,重启脚本也只处理记录为当前启动器所有的进程。不要使用模糊的
|
|
806
|
+
`taskkill /IM node.exe`,否则可能结束其他 Node、Codex 或 OpenCode 任务。
|
|
807
|
+
|
|
808
|
+
### 坑 6:配置工作区过大
|
|
809
|
+
|
|
810
|
+
把整个磁盘、用户目录或混合工作区设为 `workspaceRoot`,会增加扫描范围、
|
|
811
|
+
隐私风险和误触无关文件的概率。推荐把它限制到装有若干代码仓库的专用目录,
|
|
812
|
+
任务再通过相对 `repo_path` 指向具体项目。
|
|
813
|
+
|
|
814
|
+
### 坑 7:把执行完成当成验收通过
|
|
815
|
+
|
|
816
|
+
`done` 只表示 Agent 进程结束。仍需检查:
|
|
817
|
+
|
|
818
|
+
- 是否出现 `failed_scope_violation`
|
|
819
|
+
- 独立 `verify.json` 是否全部通过
|
|
820
|
+
- `diff.patch` 是否只包含预期修改
|
|
821
|
+
- `audit_task` 是否发现结果声明与实际不一致
|
|
822
|
+
- npm、GitHub、Tag 等远程状态是否真实存在
|
|
823
|
+
|
|
824
|
+
### 坑 8:重命名后继续读取旧数据
|
|
825
|
+
|
|
826
|
+
PatchWarden v0.4.0 不自动读取旧 CLI、旧环境变量、旧 Header、旧任务目录或
|
|
827
|
+
旧 DPAPI 凭据。旧数据可以保留作备份,但新运行必须使用新名称和新目录。
|
|
828
|
+
|
|
829
|
+
## MCP 工具与 Profile
|
|
830
|
+
|
|
831
|
+
`chatgpt_core` 是固定的 16 工具 Profile,适合 ChatGPT Tunnel:
|
|
832
|
+
|
|
833
|
+
`health_check`、`list_agents`、`list_workspace`、
|
|
834
|
+
`read_workspace_file`、`save_plan`、`create_task`、
|
|
835
|
+
`wait_for_task`、`get_task_summary`、`get_diff`、`get_result`、
|
|
836
|
+
`get_result_json`、`get_test_log`、`get_task_status`、`list_tasks`、
|
|
837
|
+
`cancel_task`、`audit_task`。
|
|
838
|
+
|
|
839
|
+
`get_task_summary` 默认保留兼容的 `standard` 视图;ChatGPT 应优先使用
|
|
840
|
+
`view: "compact"`,终态 `wait_for_task` 也只内嵌 compact 验收证据。
|
|
841
|
+
|
|
842
|
+
`full` 在 `chatgpt_core` 基础上额外提供 6 个管理工具,合计 22 个核心
|
|
843
|
+
工具;启用 Direct 后再追加 6 个 Direct 工具,共 28 个工具(22 + 6):
|
|
844
|
+
|
|
845
|
+
- `get_plan`
|
|
846
|
+
- `kill_task`
|
|
847
|
+
- `retry_task`
|
|
848
|
+
- `get_task_progress`
|
|
849
|
+
- `get_task_stdout_tail`
|
|
850
|
+
- `get_task_log_tail`
|
|
851
|
+
|
|
852
|
+
`chatgpt_direct` 是 v0.6.0 新增的 Direct 直接开发 Profile,包含 9 个工具:
|
|
853
|
+
|
|
854
|
+
`health_check`、`list_workspace`、`create_direct_session`、
|
|
855
|
+
`search_workspace`、`read_workspace_file`、`apply_patch`、
|
|
856
|
+
`run_verification`、`finalize_direct_session`、`audit_session`。
|
|
857
|
+
|
|
858
|
+
`chatgpt_direct` 默认关闭,需要通过 `enableDirectProfile: true` 或
|
|
859
|
+
`PATCHWARDEN_TOOL_PROFILE=chatgpt_direct` 显式启用。`chatgpt_core` 保持
|
|
860
|
+
16 工具不变。
|
|
376
861
|
|
|
377
|
-
|
|
862
|
+
Tunnel 包装脚本会强制使用 `chatgpt_core`;普通本地开发默认使用 `full`。
|
|
378
863
|
|
|
379
|
-
|
|
380
|
-
- the tunnel is associated with the correct ChatGPT workspace
|
|
381
|
-
- the connector uses `Channel`, not `Server URL`
|
|
382
|
-
- authentication is set to `None` unless you have implemented OAuth
|
|
383
|
-
- browser translation extensions are disabled on Platform pages
|
|
864
|
+
## Direct 模式:ChatGPT 直接开发
|
|
384
865
|
|
|
385
|
-
|
|
866
|
+
### Direct 模式用途
|
|
386
867
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
`continuation_required` is true. The legacy `wait_seconds` name remains
|
|
392
|
-
supported; if both aliases are sent, their values must match. Each wait
|
|
393
|
-
defaults to 25 seconds and is capped at 30 seconds.
|
|
394
|
-
Use `cancel_task` for graceful cancellation or `kill_task` for immediate
|
|
395
|
-
termination. Final acceptance starts with `get_task_summary`, followed by
|
|
396
|
-
`audit_task` and any detailed artifacts needed for review.
|
|
868
|
+
Direct 模式让 ChatGPT 通过受控 Direct session 直接读取文件、搜索代码、
|
|
869
|
+
应用 JSON 补丁、运行白名单验证命令,然后通过 finalize 和 audit 完成独立
|
|
870
|
+
审计。该模式不需要本地 Agent 参与,适合在无法或不需要部署 Agent 的场景下
|
|
871
|
+
让 ChatGPT 直接完成代码修改。
|
|
397
872
|
|
|
398
|
-
|
|
399
|
-
truly the intended repository. Prefer a relative subdirectory such as
|
|
400
|
-
`desktop-pet-wangzai`; absolute paths are also accepted when they resolve
|
|
401
|
-
inside `workspaceRoot`.
|
|
873
|
+
### 与 Agent 委托模式的区别
|
|
402
874
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
875
|
+
| 模式 | 流程 |
|
|
876
|
+
| --- | --- |
|
|
877
|
+
| Agent 委托模式 | ChatGPT 编写计划 → 本地 Agent 执行 → PatchWarden 审计 |
|
|
878
|
+
| Direct 模式 | ChatGPT 创建 session → 读取/搜索文件 → 应用 JSON 补丁 → 运行白名单验证 → finalize → audit |
|
|
879
|
+
|
|
880
|
+
Agent 委托模式依赖预先登记的本地 Agent(OpenCode / Codex)执行任务;
|
|
881
|
+
Direct 模式由 ChatGPT 直接通过 MCP 工具完成编辑,所有写操作绑定到
|
|
882
|
+
`session_id`,并通过独立 `audit_session` 审计。
|
|
883
|
+
|
|
884
|
+
### 如何启用
|
|
885
|
+
|
|
886
|
+
在 `patchwarden.config.json` 中:
|
|
406
887
|
|
|
407
888
|
```json
|
|
408
889
|
{
|
|
409
|
-
"
|
|
410
|
-
"
|
|
411
|
-
"inline_plan": "Implement the requested small feature without changing unrelated files.",
|
|
412
|
-
"verify_commands": [
|
|
413
|
-
"npm run build",
|
|
414
|
-
"npm test"
|
|
415
|
-
]
|
|
890
|
+
"enableDirectProfile": true,
|
|
891
|
+
"toolProfile": "chatgpt_direct"
|
|
416
892
|
}
|
|
417
893
|
```
|
|
418
894
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
###
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
-
|
|
455
|
-
|
|
456
|
-
-
|
|
457
|
-
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
-
|
|
462
|
-
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
-
|
|
474
|
-
-
|
|
475
|
-
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
895
|
+
或通过环境变量:
|
|
896
|
+
|
|
897
|
+
```powershell
|
|
898
|
+
$env:PATCHWARDEN_TOOL_PROFILE="chatgpt_direct"
|
|
899
|
+
```
|
|
900
|
+
|
|
901
|
+
### 一键启动 Direct Tunnel
|
|
902
|
+
|
|
903
|
+
Direct 模式使用独立入口,不会替换现有的 Agent 委托模式:
|
|
904
|
+
|
|
905
|
+
```text
|
|
906
|
+
PatchWarden.cmd start direct
|
|
907
|
+
```
|
|
908
|
+
|
|
909
|
+
首次启动时按提示提供 `tunnel-client.exe` 路径和专用于 Direct Connector 的
|
|
910
|
+
Tunnel ID。启动器使用 `patchwarden-direct` Profile、独立的
|
|
911
|
+
`%LOCALAPPDATA%\patchwarden\runtime-direct` 状态目录,并自动跳过 Watcher;
|
|
912
|
+
Tunnel API Key 仍通过现有 Windows DPAPI 缓存处理,不会写入仓库。
|
|
913
|
+
|
|
914
|
+
连接 ChatGPT 后新建对话并先调用 `health_check`。预期
|
|
915
|
+
`tool_profile=chatgpt_direct`、`tool_count=9`、
|
|
916
|
+
`direct_profile_enabled=true`。已有对话可能缓存旧工具清单,需要重新连接
|
|
917
|
+
Connector 后再新建对话。
|
|
918
|
+
|
|
919
|
+
### 标准流程
|
|
920
|
+
|
|
921
|
+
```text
|
|
922
|
+
health_check → create_direct_session → search_workspace / read_workspace_file → apply_patch → run_verification → finalize_direct_session → audit_session
|
|
923
|
+
```
|
|
924
|
+
|
|
925
|
+
### 安全边界
|
|
926
|
+
|
|
927
|
+
Direct 模式在受控 session 内执行,具有以下硬性限制:
|
|
928
|
+
|
|
929
|
+
- 不支持任意 shell
|
|
930
|
+
- 不支持文件删除
|
|
931
|
+
- 不支持文件重命名
|
|
932
|
+
- 不支持 git commit/push
|
|
933
|
+
- 不支持 npm publish
|
|
934
|
+
- 不支持远程部署
|
|
935
|
+
- 禁止读取 `.env`/token/key/credential
|
|
936
|
+
- 禁止修改 `node_modules`
|
|
937
|
+
- 禁止手动修改 release/dist
|
|
938
|
+
- 禁止修改二进制文件
|
|
939
|
+
- 所有操作限制在 `workspaceRoot` 和 session repo 内
|
|
940
|
+
|
|
941
|
+
### 不支持内容
|
|
942
|
+
|
|
943
|
+
Direct 模式不支持:shell、delete、rename、commit、push、publish、deployment。
|
|
944
|
+
|
|
945
|
+
## 安全边界与本地数据
|
|
946
|
+
|
|
947
|
+
PatchWarden 的主要保护:
|
|
948
|
+
|
|
949
|
+
- MCP 工具不提供通用 Shell。
|
|
950
|
+
- Agent 命令和参数模板必须预先配置。
|
|
951
|
+
- 验证命令必须精确匹配白名单。
|
|
952
|
+
- 文件访问被限制在 `workspaceRoot` 内。
|
|
953
|
+
- 敏感文件名和明显的凭据读取计划会被阻止。
|
|
954
|
+
- 任务产物中的疑似密钥值会被脱敏。
|
|
955
|
+
- HTTP Server 只绑定 `127.0.0.1`。
|
|
956
|
+
- Runner 不会自动 commit、push、发布或重置仓库。
|
|
957
|
+
|
|
958
|
+
需要保护的本地路径:
|
|
959
|
+
|
|
960
|
+
| 路径 | 内容 | 是否应提交 |
|
|
961
|
+
| --- | --- | --- |
|
|
962
|
+
| `patchwarden.config.json` | 私人路径、Agent 和命令白名单 | 否 |
|
|
963
|
+
| `.patchwarden/` | 计划、任务、差异和日志 | 否 |
|
|
964
|
+
| `%APPDATA%\patchwarden` | DPAPI 加密的 Tunnel 凭据 | 否 |
|
|
965
|
+
| `%LOCALAPPDATA%\patchwarden` | 运行时状态和隔离配置 | 否 |
|
|
966
|
+
|
|
967
|
+
不要提交 API Key、Token、Tunnel ID、ChatGPT Workspace ID、Cookie、
|
|
968
|
+
`.env`、私人项目路径或真实任务日志。
|
|
969
|
+
|
|
970
|
+
PatchWarden 能降低误操作风险,但不能替代人工审查。第一次使用应选择专用的
|
|
971
|
+
测试工作区和可回滚仓库。
|
|
972
|
+
|
|
973
|
+
## 升级与旧版本迁移
|
|
974
|
+
|
|
975
|
+
升级 npm 固定版本:
|
|
976
|
+
|
|
977
|
+
```powershell
|
|
978
|
+
npm.cmd install patchwarden@0.6.0
|
|
979
|
+
```
|
|
980
|
+
|
|
981
|
+
源码升级:
|
|
982
|
+
|
|
983
|
+
```powershell
|
|
984
|
+
git pull --ff-only
|
|
985
|
+
npm.cmd ci
|
|
986
|
+
npm.cmd run build
|
|
987
|
+
npm.cmd test
|
|
988
|
+
```
|
|
989
|
+
|
|
990
|
+
更新后:
|
|
991
|
+
|
|
992
|
+
1. 运行 `npm.cmd run doctor`。
|
|
993
|
+
2. 运行 `PatchWarden.cmd health`。
|
|
994
|
+
3. 比较版本、Schema Epoch 和 Manifest Hash。
|
|
995
|
+
4. 使用 `PatchWarden.cmd restart all` 重启受控进程。
|
|
996
|
+
5. 重连 MCP 客户端或 Connector。
|
|
997
|
+
6. 新建会话验证,不要复用旧对话作为升级证据。
|
|
998
|
+
|
|
999
|
+
从 Safe-Bifrost 迁移时必须手动完成:
|
|
1000
|
+
|
|
1001
|
+
- npm 包和 CLI 包含 `patchwarden`、`patchwarden-runner`,以及仅用于本地中风险票据确认的 `patchwarden-confirm`
|
|
1002
|
+
- 配置文件改为 `patchwarden.config.json`
|
|
1003
|
+
- 环境变量改为 `PATCHWARDEN_*`
|
|
1004
|
+
- 任务目录改为 `.patchwarden/`
|
|
1005
|
+
- HTTP Header 改为 `x-patchwarden-token`
|
|
1006
|
+
- AppData 目录改为 `patchwarden`
|
|
1007
|
+
|
|
1008
|
+
旧数据不会自动删除,也不会自动回退读取。详见
|
|
1009
|
+
[迁移指南](docs/migration-from-safe-bifrost.md)。
|
|
1010
|
+
|
|
1011
|
+
## 开发与发布验证
|
|
1012
|
+
|
|
1013
|
+
Windows PowerShell:
|
|
483
1014
|
|
|
484
1015
|
```powershell
|
|
485
1016
|
npm.cmd run build
|
|
@@ -488,39 +1019,47 @@ npm.cmd run test:mcp
|
|
|
488
1019
|
npm.cmd run test:http-mcp
|
|
489
1020
|
npm.cmd run doctor
|
|
490
1021
|
npm.cmd run check:tool-manifest
|
|
1022
|
+
npm.cmd run check:brand
|
|
491
1023
|
npm.cmd run test:tunnel-supervisor
|
|
492
1024
|
npm.cmd run test:watcher-supervisor
|
|
493
1025
|
npm.cmd run pack:clean
|
|
494
|
-
```
|
|
495
|
-
|
|
496
|
-
Package checks:
|
|
497
|
-
|
|
498
|
-
```powershell
|
|
499
1026
|
npm.cmd run verify:package
|
|
500
|
-
npm.cmd run pack:clean
|
|
501
1027
|
```
|
|
502
1028
|
|
|
503
|
-
|
|
1029
|
+
打包检查会排除:
|
|
504
1030
|
|
|
505
1031
|
- `node_modules/`
|
|
506
1032
|
- `.patchwarden/`
|
|
507
1033
|
- `*.log`
|
|
508
1034
|
- `.env`
|
|
509
1035
|
- `patchwarden.config.json`
|
|
510
|
-
-
|
|
1036
|
+
- 本地凭据和运行时状态
|
|
1037
|
+
|
|
1038
|
+
发布前不要只相信本地结果,还应分别核验 npm Registry、远程 Tag、GitHub
|
|
1039
|
+
Release 和发布资产校验值。
|
|
1040
|
+
|
|
1041
|
+
## 相关文档
|
|
1042
|
+
|
|
1043
|
+
- [v0.6.0 发布说明](docs/release-v0.6.0.md)
|
|
1044
|
+
- [ChatGPT 调用规范](docs/chatgpt-usage.md)
|
|
1045
|
+
- [旧版本迁移指南](docs/migration-from-safe-bifrost.md)
|
|
1046
|
+
- [ChatGPT Connector 演示](docs/demo.md)
|
|
1047
|
+
- [OpenAI Tunnel 示例](examples/openai-tunnel/README.md)
|
|
1048
|
+
- [ChatGPT 测试提示词](examples/openai-tunnel/chatgpt-test-prompt.md)
|
|
511
1049
|
|
|
512
1050
|
## Roadmap
|
|
513
1051
|
|
|
514
|
-
- [x] stdio MCP
|
|
515
|
-
- [x]
|
|
516
|
-
- [x]
|
|
517
|
-
- [x] HTTP MCP
|
|
518
|
-
- [x] ChatGPT Connector
|
|
519
|
-
- [x]
|
|
520
|
-
- [
|
|
521
|
-
- [ ]
|
|
522
|
-
- [ ]
|
|
1052
|
+
- [x] stdio MCP Server
|
|
1053
|
+
- [x] Plan 和 Task 生命周期
|
|
1054
|
+
- [x] Runner 和 Watcher
|
|
1055
|
+
- [x] HTTP MCP Server
|
|
1056
|
+
- [x] ChatGPT Connector / Tunnel
|
|
1057
|
+
- [x] Doctor 与运行时健康检查
|
|
1058
|
+
- [x] Tool Manifest 与 Schema 漂移检测
|
|
1059
|
+
- [ ] Worktree 隔离
|
|
1060
|
+
- [ ] 多 Agent 任务队列
|
|
1061
|
+
- [ ] 本地 Dashboard
|
|
523
1062
|
|
|
524
1063
|
## License
|
|
525
1064
|
|
|
526
|
-
MIT
|
|
1065
|
+
[MIT](LICENSE)
|