patchwarden 0.6.0 → 0.6.4

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.
Files changed (134) hide show
  1. package/PatchWarden-Control-Tray.cmd +11 -0
  2. package/PatchWarden-Control.cmd +6 -0
  3. package/PatchWarden-Desktop.cmd +5 -0
  4. package/PatchWarden.cmd +1 -1
  5. package/README.en.md +106 -18
  6. package/README.md +30 -19
  7. package/Restart-PatchWarden-Control.cmd +6 -0
  8. package/Stop-PatchWarden.cmd +11 -0
  9. package/dist/controlCenter.d.ts +14 -0
  10. package/dist/controlCenter.js +2002 -0
  11. package/dist/doctor.js +4 -4
  12. package/dist/logging.d.ts +52 -0
  13. package/dist/logging.js +123 -0
  14. package/dist/runner/changeCapture.d.ts +41 -0
  15. package/dist/runner/changeCapture.js +171 -1
  16. package/dist/runner/runTask.js +204 -24
  17. package/dist/smoke-test.js +8 -8
  18. package/dist/test/unit/android-doctor.test.d.ts +1 -0
  19. package/dist/test/unit/android-doctor.test.js +118 -0
  20. package/dist/test/unit/chinese-path.test.d.ts +1 -0
  21. package/dist/test/unit/chinese-path.test.js +91 -0
  22. package/dist/test/unit/command-guard.test.d.ts +1 -0
  23. package/dist/test/unit/command-guard.test.js +160 -0
  24. package/dist/test/unit/direct-guards.test.d.ts +1 -0
  25. package/dist/test/unit/direct-guards.test.js +213 -0
  26. package/dist/test/unit/logging.test.d.ts +1 -0
  27. package/dist/test/unit/logging.test.js +275 -0
  28. package/dist/test/unit/path-guard.test.d.ts +1 -0
  29. package/dist/test/unit/path-guard.test.js +109 -0
  30. package/dist/test/unit/safe-status.test.d.ts +1 -0
  31. package/dist/test/unit/safe-status.test.js +165 -0
  32. package/dist/test/unit/sensitive-guard.test.d.ts +1 -0
  33. package/dist/test/unit/sensitive-guard.test.js +104 -0
  34. package/dist/test/unit/sync-file.test.d.ts +1 -0
  35. package/dist/test/unit/sync-file.test.js +154 -0
  36. package/dist/test/unit/watcher-status.test.d.ts +1 -0
  37. package/dist/test/unit/watcher-status.test.js +169 -0
  38. package/dist/tools/androidDoctor.d.ts +38 -0
  39. package/dist/tools/androidDoctor.js +391 -0
  40. package/dist/tools/auditTask.js +11 -5
  41. package/dist/tools/getTaskSummary.d.ts +3 -0
  42. package/dist/tools/getTaskSummary.js +15 -1
  43. package/dist/tools/healthCheck.d.ts +5 -0
  44. package/dist/tools/healthCheck.js +21 -0
  45. package/dist/tools/registry.js +53 -0
  46. package/dist/tools/safeStatus.d.ts +19 -0
  47. package/dist/tools/safeStatus.js +72 -0
  48. package/dist/tools/syncFile.d.ts +18 -0
  49. package/dist/tools/syncFile.js +65 -0
  50. package/dist/tools/taskOutputs.d.ts +2 -2
  51. package/dist/tools/toolCatalog.d.ts +2 -2
  52. package/dist/tools/toolCatalog.js +2 -0
  53. package/dist/version.d.ts +2 -2
  54. package/dist/version.js +2 -2
  55. package/dist/watcherStatus.d.ts +1 -0
  56. package/dist/watcherStatus.js +96 -4
  57. package/docs/control-center/README.md +33 -0
  58. package/docs/control-center/control-center-daily-driver.md +211 -0
  59. package/docs/control-center/control-center-mvp.md +205 -0
  60. package/docs/control-center/control-center-phase2.md +159 -0
  61. package/docs/demo.md +3 -0
  62. package/docs/performance-notes.md +55 -0
  63. package/docs/release-v0.6.1.md +75 -0
  64. package/docs/release-v0.6.4.md +45 -0
  65. package/examples/openai-tunnel/README.md +5 -5
  66. package/examples/openai-tunnel/tunnel-client.example.yaml +3 -3
  67. package/package.json +23 -14
  68. package/scripts/README.md +47 -0
  69. package/scripts/{brand-check.js → checks/brand-check.js} +2 -2
  70. package/scripts/checks/control-center-smoke.js +1098 -0
  71. package/scripts/{control-smoke.js → checks/control-smoke.js} +17 -3
  72. package/scripts/{doctor-smoke.js → checks/doctor-smoke.js} +1 -1
  73. package/scripts/{http-mcp-smoke.js → checks/http-mcp-smoke.js} +12 -4
  74. package/scripts/{lifecycle-smoke.js → checks/lifecycle-smoke.js} +347 -13
  75. package/scripts/{mcp-manifest-check.js → checks/mcp-manifest-check.js} +32 -9
  76. package/scripts/{mcp-smoke.js → checks/mcp-smoke.js} +14 -9
  77. package/scripts/{package-manifest-check.js → checks/package-manifest-check.js} +2 -1
  78. package/scripts/{tunnel-supervisor-smoke.js → checks/tunnel-supervisor-smoke.js} +2 -2
  79. package/scripts/checks/unit-tests.js +36 -0
  80. package/scripts/{watcher-supervisor-smoke.js → checks/watcher-supervisor-smoke.js} +11 -5
  81. package/scripts/control/control-center-tray.ps1 +281 -0
  82. package/scripts/{get-patchwarden-health.ps1 → control/get-patchwarden-health.ps1} +3 -3
  83. package/scripts/{manage-patchwarden.ps1 → control/manage-patchwarden.ps1} +30 -4
  84. package/scripts/control/restart-control-center.ps1 +173 -0
  85. package/scripts/{restart-patchwarden.ps1 → control/restart-patchwarden.ps1} +1 -1
  86. package/scripts/control/start-control-center.ps1 +263 -0
  87. package/scripts/{start-patchwarden-tunnel.ps1 → control/start-patchwarden-tunnel.ps1} +48 -6
  88. package/scripts/control/stop-patchwarden.ps1 +114 -0
  89. package/scripts/launchers/Check-PatchWarden-Health.cmd +1 -1
  90. package/scripts/launchers/Reset-PatchWarden-Tunnel-Key.cmd +1 -1
  91. package/scripts/launchers/Restart-PatchWarden.cmd +1 -1
  92. package/scripts/launchers/Start-PatchWarden-Direct-Tunnel.cmd +1 -1
  93. package/scripts/launchers/Start-PatchWarden-Tunnel.cmd +1 -1
  94. package/scripts/{patchwarden-mcp-direct.cmd → mcp/patchwarden-mcp-direct.cmd} +1 -1
  95. package/scripts/{patchwarden-mcp-stdio.cmd → mcp/patchwarden-mcp-stdio.cmd} +1 -1
  96. package/scripts/release/pack-clean.js +305 -0
  97. package/src/controlCenter.ts +2152 -0
  98. package/src/doctor.ts +5 -5
  99. package/src/logging.ts +152 -0
  100. package/src/runner/changeCapture.ts +212 -1
  101. package/src/runner/runTask.ts +220 -22
  102. package/src/smoke-test.ts +5 -5
  103. package/src/test/unit/android-doctor.test.ts +158 -0
  104. package/src/test/unit/chinese-path.test.ts +106 -0
  105. package/src/test/unit/command-guard.test.ts +221 -0
  106. package/src/test/unit/direct-guards.test.ts +297 -0
  107. package/src/test/unit/logging.test.ts +325 -0
  108. package/src/test/unit/path-guard.test.ts +150 -0
  109. package/src/test/unit/safe-status.test.ts +187 -0
  110. package/src/test/unit/sensitive-guard.test.ts +124 -0
  111. package/src/test/unit/sync-file.test.ts +231 -0
  112. package/src/test/unit/watcher-status.test.ts +190 -0
  113. package/src/tools/androidDoctor.ts +424 -0
  114. package/src/tools/auditTask.ts +11 -5
  115. package/src/tools/getTaskSummary.ts +22 -1
  116. package/src/tools/healthCheck.ts +22 -0
  117. package/src/tools/registry.ts +63 -0
  118. package/src/tools/safeStatus.ts +96 -0
  119. package/src/tools/syncFile.ts +122 -0
  120. package/src/tools/toolCatalog.ts +2 -0
  121. package/src/version.ts +2 -2
  122. package/src/watcherStatus.ts +101 -4
  123. package/ui/colors_and_type.css +141 -0
  124. package/ui/pages/audit.html +743 -0
  125. package/ui/pages/dashboard.html +1154 -0
  126. package/ui/pages/direct-sessions.html +652 -0
  127. package/ui/pages/logs.html +502 -0
  128. package/ui/pages/task-detail.html +1229 -0
  129. package/ui/pages/tasks.html +702 -0
  130. package/ui/pages/workspace.html +947 -0
  131. package/ui/partials/project-shell.html +362 -0
  132. package/ui/vendor/lucide.js +12 -0
  133. package/ui/vendor/tailwindcss-browser.js +947 -0
  134. package/scripts/pack-clean.js +0 -141
@@ -0,0 +1,205 @@
1
+ # PatchWarden Control Center MVP
2
+
3
+ > 本地 Web 控制中心,统一管理 PatchWarden Core 与 PatchWarden Direct 两个 MCP profile。
4
+ > 不合并工具,不发布到 npm,不打 git tag。
5
+
6
+ ## 概述
7
+
8
+ Control Center 是一个绑定 `127.0.0.1:8090` 的本地 HTTP 服务,提供静态 UI 页面和一组容错 JSON API。
9
+ 所有进程生命周期操作(start/stop/restart)均委托 `scripts/control/manage-patchwarden.ps1` 执行,
10
+ Control Center 自身不直接 kill 进程,也不读取任意 PID 文件。
11
+
12
+ - **Core profile**: `chatgpt_core`,17 个工具,HTTP 端口 8080
13
+ - **Direct profile**: `chatgpt_direct`,10 个工具,HTTP 端口 8081
14
+
15
+ ## 新增文件
16
+
17
+ | 文件 | 说明 |
18
+ | --- | --- |
19
+ | `src/controlCenter.ts` | Control Center HTTP 服务主程序(TypeScript 源) |
20
+ | `scripts/checks/control-center-smoke.js` | 测试模式冒烟测试(ESM,仅用 Node 内置模块) |
21
+ | `scripts/control/start-control-center.ps1` | PowerShell 启动脚本(含构建检查、端口轮询、浏览器自动打开;支持 `-NoBrowser`) |
22
+ | `PatchWarden-Control.cmd` | 根目录 CMD 入口,调用上述 PowerShell 脚本 |
23
+ | `ui/pages/dashboard.html` | 总控首页(真实状态,7 个工具栏按钮,两张服务卡) |
24
+ | `ui/pages/tasks.html` | 任务列表页(接 `/api/tasks`) |
25
+ | `ui/pages/task-detail.html` | 任务详情页(接 `/api/tasks/:taskId`) |
26
+ | `ui/pages/workspace.html` | 工作区页(接轻量 `/api/workspace`) |
27
+ | `ui/pages/audit.html` | 审计历史页(接 `/api/audit`) |
28
+ | `ui/partials/project-shell.html` | 页面外壳(CDN 引用已替换为本地 `/vendor/`) |
29
+ | `ui/colors_and_type.css` | 颜色与字体样式 |
30
+ | `ui/vendor/tailwindcss-browser.js` | Tailwind v4.3.1 browser build(本地副本,离线可用) |
31
+ | `ui/vendor/lucide.js` | Lucide v1.8.0 UMD(本地副本,离线可用) |
32
+ | `docs/control-center/control-center-mvp.md` | 本文档 |
33
+
34
+ ## 改动文件
35
+
36
+ | 文件 | 改动 |
37
+ | --- | --- |
38
+ | `package.json` | 新增 `start:control` 脚本(`node dist/controlCenter.js`);`files` 数组新增 `ui/`;`test` 脚本末尾追加 `&& node scripts/checks/control-center-smoke.js` |
39
+ | `.gitignore` | 新增 `/CODE_WIKI.md`、`/PatchWarden-UI.zip`、`/patchwarden-v0.6.1-SHA256SUMS.txt`(避免 brand-check 误报) |
40
+
41
+ ## 启动方式
42
+
43
+ ### 方式一:CMD 入口(推荐用户使用)
44
+
45
+ ```powershell
46
+ .\PatchWarden-Control.cmd
47
+ ```
48
+
49
+ ### 方式二:PowerShell 脚本
50
+
51
+ ```powershell
52
+ # 正常启动(构建检查 + 打开浏览器)
53
+ powershell -ExecutionPolicy Bypass -File scripts\control\start-control-center.ps1
54
+
55
+ # 测试模式(不打开浏览器)
56
+ powershell -ExecutionPolicy Bypass -File scripts\control\start-control-center.ps1 -NoBrowser
57
+ ```
58
+
59
+ ### 方式三:npm 脚本(需先 `npm run build`)
60
+
61
+ ```powershell
62
+ npm.cmd run build
63
+ npm.cmd run start:control
64
+ ```
65
+
66
+ 启动后自动打开 `http://127.0.0.1:8090`。
67
+
68
+ 端口可通过环境变量覆盖(仅用于测试):
69
+
70
+ ```powershell
71
+ $env:PATCHWARDEN_CONTROL_PORT=18090; node dist/controlCenter.js
72
+ ```
73
+
74
+ ## 控制 Token 校验
75
+
76
+ - 服务启动时通过 `crypto.randomUUID()` 生成 token,**仅保存在内存中**,不写入任何文件。
77
+ - 前端通过 `GET /control-token.json` 从内存获取 token,响应头 `Cache-Control: no-store`。
78
+ - **所有 POST 接口**(含 `/api/start-all`、`/api/stop-all`、`/api/restart-all`、`/api/core/*`、`/api/direct/*`、`/api/open-logs-folder`)必须携带 `X-PatchWarden-Control-Token` 请求头。
79
+ - token 缺失或错误时返回 `403`,不执行任何进程控制或本地系统动作。
80
+ - GET 接口(status、tasks、logs 等)不需要 token。
81
+ - `git status --porcelain` 不会出现 `ui/control-token.json`。
82
+
83
+ ## API 清单
84
+
85
+ ### GET 接口(免 token)
86
+
87
+ | 路径 | 说明 |
88
+ | --- | --- |
89
+ | `GET /` | 返回 `ui/pages/dashboard.html` |
90
+ | `GET /control-token.json` | 从内存返回控制 token,`Cache-Control: no-store` |
91
+ | `GET /colors_and_type.css` | 静态 CSS |
92
+ | `GET /pages/*` | 静态 HTML 页面 |
93
+ | `GET /partials/*` | 静态 HTML 片段 |
94
+ | `GET /vendor/*` | 本地化的 Tailwind / Lucide |
95
+ | `GET /api/status` | 聚合状态(容错,永不 500) |
96
+ | `GET /api/tasks` | 任务列表(复用 `listTasks`) |
97
+ | `GET /api/tasks/:taskId` | 任务详情(status/runtime/result/audit/diff_patch/test_log) |
98
+ | `GET /api/logs/core` | Core runtime 日志尾部 100 行(脱敏) |
99
+ | `GET /api/logs/direct` | Direct runtime 日志尾部 100 行(脱敏) |
100
+ | `GET /api/logs/watcher` | Watcher 日志尾部 100 行(脱敏) |
101
+ | `GET /api/workspace` | 轻量工作区信息(workspace_root、directories、agents、config 摘要;**不做 git 扫描**) |
102
+ | `GET /api/audit` | 审计历史(扫描 tasks 目录下含 audit.json 的任务,最多 50 条) |
103
+ | `GET /api/tunnel-ui-url` | 读取 Core/Direct 的 tunnel-health-url.txt |
104
+
105
+ ### POST 接口(必须校验 token)
106
+
107
+ | 路径 | 委托命令 | 说明 |
108
+ | --- | --- | --- |
109
+ | `POST /api/start-all` | `manage-patchwarden.ps1 start all` | 启动全部 |
110
+ | `POST /api/stop-all` | `manage-patchwarden.ps1 stop all` | 停止全部 |
111
+ | `POST /api/restart-all` | `manage-patchwarden.ps1 restart all` | 重启全部 |
112
+ | `POST /api/core/start` | `manage-patchwarden.ps1 start core` | 启动 Core |
113
+ | `POST /api/core/stop` | `manage-patchwarden.ps1 stop core` | 停止 Core |
114
+ | `POST /api/direct/start` | `manage-patchwarden.ps1 start direct` | 启动 Direct |
115
+ | `POST /api/direct/stop` | `manage-patchwarden.ps1 stop direct` | 停止 Direct |
116
+ | `POST /api/open-logs-folder` | 系统命令打开 runtime 目录 | 打开日志文件夹 |
117
+
118
+ ### `/api/status` 返回结构(容错)
119
+
120
+ ```json
121
+ {
122
+ "core": { "available": false, "reason": "...", "healthz": null, "readyz": null },
123
+ "direct": { "available": false, "reason": "...", "healthz": null, "readyz": null },
124
+ "watcher": { "status": "missing|healthy|stale|unreadable", "available": false, "reason": "..." },
125
+ "tunnel": { "core": { "observed": false }, "direct": { "observed": false } },
126
+ "tools": {
127
+ "core": { "tool_profile": null, "tool_count": null, "schema_epoch": null, "tool_manifest_sha256": null, "tool_names": null },
128
+ "direct": { "tool_profile": null, "tool_count": null, "schema_epoch": null, "tool_manifest_sha256": null, "tool_names": null }
129
+ },
130
+ "agents": [],
131
+ "workspace_root": "string | null",
132
+ "tasks": { "tasks": [], "total": 0, "active": 0, "stale": 0, "reason": null }
133
+ }
134
+ ```
135
+
136
+ 容错保证:
137
+ - core/direct health 探测失败 → `{ available: false, reason: "..." }`,接口仍 200
138
+ - runtime 文件(tunnel-status.json、tool-manifest.json)缺失 → 返回 null 或 `{ observed: false }`,接口仍 200
139
+ - 日志文件缺失 → `{ stdout: "", stderr: "", reason: "..." }`,接口仍 200
140
+ - tasks 目录缺失 → `{ tasks: [], total: 0, reason: "..." }`,接口仍 200
141
+ - Core/Direct 未启动时 `/api/status` 仍返回 200 JSON,不报 500
142
+
143
+ ## 进程安全
144
+
145
+ - Control Center **不直接 kill 进程**,所有 start/stop/restart 均委托 `scripts/control/manage-patchwarden.ps1`。
146
+ - `manage-patchwarden.ps1` 的 `Test-TunnelProcessForMode` 在 stop/restart 前校验进程命令行属于 `tunnel-client.exe --profile` 模式,仅停止匹配的进程。
147
+ - **不根据任意 PID 文件 kill 进程**。
148
+ - Control Center 仅在自身服务关闭时退出自己启动的 HTTP server。
149
+
150
+ ## CDN 本地化
151
+
152
+ - 所有 HTML 无 `https://cdn` 或 `https://unpkg` 引用。
153
+ - `ui/vendor/tailwindcss-browser.js`(Tailwind v4.3.1)和 `ui/vendor/lucide.js`(Lucide v1.8.0)为本地副本。
154
+ - 断网后页面样式和图标正常渲染。
155
+
156
+ ## 冒烟测试(测试模式)
157
+
158
+ `scripts/checks/control-center-smoke.js` 严格遵循测试模式:
159
+
160
+ - 不打开浏览器
161
+ - 不真正 start/stop Core 或 Direct
162
+ - 不 kill 任何进程(仅关闭自己 spawn 的 controlCenter 子进程)
163
+ - 使用测试端口 `18090`(通过 `PATCHWARDEN_CONTROL_PORT`),避免 8090 冲突
164
+ - 测试结束关闭 server,释放端口
165
+
166
+ 测试覆盖(10 项):
167
+
168
+ 1. 静态文件服务(`/`、`/vendor/*`、`/colors_and_type.css` 返回 200 + 正确 Content-Type)
169
+ 2. `/api/status` 返回有效 JSON 且容错(core/direct 未启动时仍 200)
170
+ 3. `/api/tasks` 返回有效 JSON
171
+ 4. `/control-token.json` 返回 token + `Cache-Control: no-store`
172
+ 5. POST `/api/start-all` 不带 token → 403
173
+ 6. POST `/api/start-all` 带错误 token → 403
174
+ 7. POST `/api/open-logs-folder` 不带 token → 403
175
+ 8. token 不污染 Git(`git status --porcelain` 不含 `ui/control-token.json`)
176
+ 9. 无 CDN 引用(HTML 文件无 `https://cdn` / `https://unpkg`)
177
+ 10. 其他 GET API 可达(`/api/workspace`、`/api/audit`、`/api/logs/core`、`/api/tunnel-ui-url`)
178
+
179
+ ## 测试结果
180
+
181
+ `npm test` 全量通过(`FINAL_EXIT_CODE: 0`):
182
+
183
+ | 测试链 | 结果 |
184
+ | --- | --- |
185
+ | smoke-test | OK |
186
+ | unit-tests | 139 total(136 pass,0 fail,1 skipped) |
187
+ | lifecycle-smoke | 22 passed, 0 failed |
188
+ | doctor-smoke | OK |
189
+ | tunnel-supervisor-smoke | OK |
190
+ | watcher-supervisor-smoke | OK |
191
+ | control-smoke | OK |
192
+ | mcp-manifest-check | 17 tools, chatgpt_core profile |
193
+ | brand-check | OK: 144 tracked files checked |
194
+ | control-center-smoke | 10 passed, 0 failed |
195
+
196
+ 未发布 npm、未打 git tag、未上传 npm。
197
+
198
+ ## 已知限制
199
+
200
+ 1. **`/api/workspace` 轻量版**:第一版只返回 workspace_root、项目列表(一级子目录)、agents、config 摘要。不做 git 扫描,不返回 repo clean 状态。workspace.html 中 "Repo Clean 状态" 显示为"按需接口待实现"占位。
201
+ 2. **task-detail / workspace / audit 为基础接入**:能加载数据并渲染,但未实现全部高级功能(如 diff 高亮、审计证据深度展示)。diff/test-log 仅做文本预览。
202
+ 3. **进程控制仅支持 Windows**:`manage-patchwarden.ps1` 为 PowerShell 脚本,POST 控制接口在非 Windows 环境下不可用。`/api/open-logs-folder` 在 macOS/Linux 下会尝试 `open`/`xdg-open`。
203
+ 4. **Health 探测端口固定**:Core 探测 `127.0.0.1:8080`,Direct 探测 `127.0.0.1:8081`,暂不支持配置覆盖。
204
+ 5. **Control token 生命周期**:token 在服务进程内存中,服务重启后 token 会变化(前端通过 `/control-token.json` 重新获取)。
205
+ 6. **日志读取**:仅返回各日志文件尾部 100 行,并对敏感内容脱敏(复用 `redactSensitiveContent`)。
@@ -0,0 +1,159 @@
1
+ # PatchWarden Control Center Phase 2
2
+
3
+ > v0.6.3 在 v0.6.2 MVP 基础上增强任务、工作区、Direct session 和日志体验。
4
+ > 不重构架构,不合并 Core/Direct MCP,不改现有 MCP 工具注册逻辑。
5
+ > 不发布 npm,不打 git tag。
6
+
7
+ ## 概述
8
+
9
+ Phase 2 完全在 Control Center HTTP 层增强,未触动 MCP 工具注册、watcher 核心循环或
10
+ Direct session 写入逻辑。新增的 API 全部沿用既有 token 校验、路径围栏和脱敏机制。
11
+
12
+ - **Stale Task 管理**:4 条规则识别僵死任务,reconcile 只标注不删除
13
+ - **task-detail 增强**:变更文件、验证摘要、警告/错误、stale 横幅 + 4 个动作按钮
14
+ - **工作区按需 git 状态**:仅在用户点击时对单个 repo 执行 `git status --short`
15
+ - **Direct Sessions 页面**:浏览 `.patchwarden/direct-sessions` 下的会话产物
16
+ - **Logs 页面**:core/direct/watcher/control-center 四类日志,支持 tail 100/300/1000
17
+
18
+ ## 启动方式
19
+
20
+ 启动方式与 MVP 完全一致,无新增入口:
21
+
22
+ ```powershell
23
+ .\PatchWarden-Control.cmd
24
+ # 或
25
+ npm.cmd run build
26
+ npm.cmd run start:control
27
+ ```
28
+
29
+ 启动后访问 `http://127.0.0.1:8090`,左侧导航新增「Direct 会话」和「日志」两项。
30
+
31
+ ## 改动文件
32
+
33
+ | 文件 | 改动 |
34
+ | --- | --- |
35
+ | `src/version.ts` | `PATCHWARDEN_VERSION` 0.6.2 → 0.6.3 |
36
+ | `package.json` | `version` 0.6.2 → 0.6.3 |
37
+ | `src/controlCenter.ts` | 新增 stale/reconcile/task-detail 增强/workspace repo status/direct sessions/logs 分类等 API |
38
+ | `ui/pages/dashboard.html` | 侧边栏新增 Direct 会话 + 日志导航 |
39
+ | `ui/pages/tasks.html` | 侧边栏新增 Direct 会话 + 日志导航 |
40
+ | `ui/pages/task-detail.html` | 新增变更文件卡、验证摘要卡、警告/错误卡、stale 横幅、Refresh/Copy task_id/Open folder/Run audit/Reconcile 按钮 |
41
+ | `ui/pages/workspace.html` | 每个 repo 新增「检查」按钮,按需调用 `/api/workspace/:repo/status`,渲染 git 状态面板 |
42
+ | `ui/pages/audit.html` | 侧边栏新增 Direct 会话 + 日志导航 |
43
+ | `ui/pages/direct-sessions.html` | 新页面:会话列表 + 会话详情(summary.md / audit.md / audit.json / diff.patch / changed-files.json) |
44
+ | `ui/pages/logs.html` | 新页面:分类选择 + tail 选择 + 自动刷新开关 |
45
+ | `scripts/checks/control-center-smoke.js` | 新增 Test 11–15 覆盖 Phase 2 API |
46
+ | `docs/control-center/control-center-phase2.md` | 本文档 |
47
+
48
+ ## 新增 API
49
+
50
+ ### GET 接口(免 token)
51
+
52
+ | 路径 | 说明 |
53
+ | --- | --- |
54
+ | `GET /api/tasks/stale` | 返回当前判定为 stale 的任务列表(含 stale_reasons) |
55
+ | `GET /api/tasks/:taskId` | 增强详情:新增 `changed_files`、`file_stats`、`verification_summary`、`warnings`、`errors`、`stale`、`reconcile`、`task_dir`、`independent_review`、`verify_log` |
56
+ | `GET /api/workspace/:repo/status` | 对单个 repo 执行 `git status --short`,返回 changed_files_count/untracked_count/modified_count/is_clean/short_status |
57
+ | `GET /api/direct-sessions` | 列出 `.patchwarden/direct-sessions` 下所有会话摘要 |
58
+ | `GET /api/direct-sessions/:sessionId` | 返回会话详情:summary/session/summary_md/diff_patch/audit_json/audit_md/changed_files |
59
+ | `GET /api/logs/:category?tail=<100\|300\|1000>` | 四类日志(core/direct/watcher/control-center),支持 tail 行数 |
60
+
61
+ ### POST 接口(必须校验 token)
62
+
63
+ | 路径 | 说明 |
64
+ | --- | --- |
65
+ | `POST /api/tasks/:taskId/reconcile` | 标注 stale/archived,写入 `reconcile.json`,不删除任务 |
66
+ | `POST /api/tasks/:taskId/audit` | 仅当任务处于终态时委托 `auditTask` 运行独立审计 |
67
+ | `POST /api/tasks/:taskId/open-folder` | 通过系统命令打开任务目录 |
68
+
69
+ ## Stale Task 判定规则
70
+
71
+ `classifyStaleTask` 仅对 `pending` / `running` 状态任务判定(终态任务直接返回非 stale)。
72
+ 判定使用 `config.watcherStaleSeconds` 作为阈值,4 条规则任一命中即标记 stale:
73
+
74
+ | 规则 | 字段值 | 说明 |
75
+ | --- | --- | --- |
76
+ | `heartbeat_stale` | status=running 且 last_heartbeat_at 超过阈值 | 运行中但心跳长时间未更新 |
77
+ | `collecting_artifacts_stale` | phase=collecting_artifacts 且心跳超过阈值 | 卡在产物收集阶段 |
78
+ | `running_no_command_watcher_healthy` | status=running 且 current_command 为空且 watcher healthy | 运行中无命令但 watcher 在工作,疑似僵死 |
79
+ | `heartbeat_far_behind_watcher` | 任务心跳比 watcher 心跳早 2× 阈值以上且 watcher healthy | 任务明显落后于 watcher |
80
+
81
+ `/api/status` 和 `/api/tasks` 返回的任务对象均带 `is_stale: boolean` 和
82
+ `stale_reasons: string[]`。`/api/status.tasks` 还聚合了 `stale` 计数和
83
+ `stale_task_ids` 列表。
84
+
85
+ ## Reconcile 行为
86
+
87
+ `POST /api/tasks/:taskId/reconcile` 的安全契约:
88
+
89
+ - **不删除任务**,不修改 `status` 枚举值
90
+ - 读取 `status.json` / `runtime.json` 重建 `TaskEntry`,重新调用 `classifyStaleTask`
91
+ - 决策(`decision` 字段):
92
+ - `marked_archived`:任务已处于终态 → 标注归档
93
+ - `marked_stale`:stale 且 watcher 未在驱动(无 current_command 或 watcher 非 healthy)→ 标注僵死
94
+ - `no_action`:不满足上述条件 → 仅记录,不标注
95
+ - 写入 `tasks/<taskId>/reconcile.json`(完整决策记录)
96
+ - 仅当 `safe=true` 时,在 `status.json` 追加 `reconcile_state`(`"stale"` 或 `"archived"`)和 `reconciled_at`,**原 status 字段保持不变**
97
+ - 返回 reconcile 记录 JSON
98
+
99
+ ## 路径围栏(workspace repo status)
100
+
101
+ `GET /api/workspace/:repo/status` 的安全约束:
102
+
103
+ - `repo` 参数经 `decodeURIComponent` 后若包含 `..` 或 `\0` → 直接 400
104
+ - 通过 `guardWorkspacePath(repo, workspaceRoot)` 解析为绝对路径,任何逃逸 `workspaceRoot` 的路径 → 400
105
+ - 仅对解析后的目录执行 `git status --short`,超时 8 秒,maxBuffer 1MB
106
+ - 非 git 仓库或 git 不可用时返回 200 + `is_git_repo: false` + error 字段,不返回 500
107
+ - smoke test 用 `encodeURIComponent("../secret")` 验证穿越被拒(400)
108
+
109
+ ## Direct Sessions 数据来源
110
+
111
+ - 会话目录:`getDirectSessionsDir(config)` → `<runtime>/.patchwarden/direct-sessions/`
112
+ - 每个会话子目录读取:`session.json`、`summary.json`、`audit.json`、`summary.md`、`diff.patch`、`audit.md`、`changed-files.json`
113
+ - `DirectSessionSummary` 字段:`session_id`、`repo_path`、`resolved_repo_path`、`created_at`、`expires_at`、`finalized`、`finalized_at`、`audited`、`changed_files_total`、`verification_summary`、`audit_decision`、`audit_checked_at`、`title`
114
+ - 目录不存在时返回 `{ sessions: [], total: 0, reason: null }`,**不返回 500**
115
+ - 会话按 `created_at` 降序排列
116
+
117
+ ## 日志脱敏
118
+
119
+ - 所有 `/api/logs/:category` 响应均经 `redactSensitiveContent` 脱敏
120
+ - tail 行数限制在 `ALLOWED_LOG_TAILS = {100, 300, 1000}`,非法值回退到 100
121
+ - 日志文件缺失时返回 `{ stdout: "", stderr: "", reason: "log file not found" }`
122
+
123
+ ## 冒烟测试
124
+
125
+ `scripts/checks/control-center-smoke.js` 在原 10 项基础上新增 5 项(共 16 项):
126
+
127
+ | # | 测试 |
128
+ | --- | --- |
129
+ | 11 | `GET /api/tasks/stale` 返回有效 JSON(`stale_tasks` 数组、`total` 数字、`stale_threshold_seconds` 数字) |
130
+ | 12 | `GET /api/workspace/<traversal>/status` 被拒绝(400,error 含 "traversal") |
131
+ | 13 | `POST /api/tasks/:taskId/reconcile` 无 token → 403 |
132
+ | 14 | `GET /api/direct-sessions` 目录缺失时返回空列表(200,非 500) |
133
+ | 15 | `GET /api/logs/core?tail=300` 响应包含 `tail: 300` |
134
+
135
+ ## 测试结果
136
+
137
+ ```
138
+ npm.cmd run build # tsc 编译通过
139
+ node scripts/checks/control-center-smoke.js
140
+ # Summary: 16 passed, 0 failed
141
+ ```
142
+
143
+ 全量 `npm test` 链路(security 139 + unit 136 + lifecycle 22 + control-center 16)
144
+ 全部通过,0 失败。
145
+
146
+ > 注:在 TRAE IDE 沙盒内运行 `npm test` 时,control-center-smoke spawn 的子进程退出
147
+ > 后 Windows 会尝试更新 jump list 临时文件,被沙盒拒绝并打印
148
+ > "TRAE Sandbox Error: hit restricted …CustomDestinations…"。该错误与测试逻辑无关,
149
+ > 所有测试用例均报告 PASS。直接运行 `node scripts/checks/control-center-smoke.js` 退出码为 0。
150
+
151
+ ## 已知限制
152
+
153
+ - `/api/workspace/:repo/status` 仅运行 `git status --short`,不返回 diff 或 stash 信息
154
+ - reconcile 不会清理任务文件,需人工后续处理或由 watcher 在下个周期自然覆盖
155
+ - `/api/tasks/:taskId/audit` 仅在任务处于终态(done/failed/failed_verification/
156
+ failed_scope_violation/failed_policy_violation/canceled/timeout)时才执行,否则返回 409
157
+ - Direct Sessions 页面只读,不提供 finalize 或 audit 触发入口(这些操作仍需通过 MCP 工具完成)
158
+ - Logs 页面的自动刷新间隔固定为 5 秒,不读取 watcher 实时事件
159
+ - task-detail 的「Open task folder」按钮通过 `explorer.exe` / `open` / `xdg-open` 打开,需要本地图形环境
package/docs/demo.md CHANGED
@@ -42,7 +42,10 @@ Expected artifacts under the configured workspace:
42
42
  ```text
43
43
  .patchwarden/tasks/<task_id>/status.json
44
44
  .patchwarden/tasks/<task_id>/result.md
45
+ .patchwarden/tasks/<task_id>/result.json
46
+ .patchwarden/tasks/<task_id>/artifact_manifest.json
45
47
  .patchwarden/tasks/<task_id>/git.diff
48
+ .patchwarden/tasks/<task_id>/verify.json
46
49
  .patchwarden/tasks/<task_id>/test.log
47
50
  ```
48
51
 
@@ -0,0 +1,55 @@
1
+ # PatchWarden Performance Notes
2
+
3
+ ## Current State (v0.6.1)
4
+
5
+ ### Identified Optimization Opportunities
6
+
7
+ The following performance optimizations have been identified for future implementation. They are documented here rather than implemented in v0.6.1 to avoid introducing risk to the core task execution path.
8
+
9
+ ### 1. Async Git Operations in changeCapture.ts
10
+
11
+ **Current**: `runGit()` uses `spawnSync()` which blocks the event loop during git operations.
12
+
13
+ **Proposed**: Replace with `execFile()` (async) and use `Promise.all()` for independent git queries in `captureRepoSnapshot()`.
14
+
15
+ **Risk**: Medium — changes the core change capture path. Requires careful testing of all snapshot/diff/scope scenarios.
16
+
17
+ **Expected Benefit**: ~200-500ms improvement per task for repos with many files, as multiple git queries can run concurrently.
18
+
19
+ ### 2. Streaming File Hash
20
+
21
+ **Current**: `computeFileSha256()` reads the entire file into memory with `readFileSync()`.
22
+
23
+ **Proposed**: Use `createReadStream()` + `crypto.createHash()` for streaming hash computation.
24
+
25
+ **Risk**: Low — isolated to hash computation, no semantic change.
26
+
27
+ **Expected Benefit**: Reduces peak memory usage for large files (e.g., release artifacts > 5MB).
28
+
29
+ ### 3. Workspace Snapshot Caching
30
+
31
+ **Current**: `walkWorkspace()` traverses the entire workspace directory tree on every snapshot.
32
+
33
+ **Proposed**: Cache the directory listing and invalidate on file modification events.
34
+
35
+ **Risk**: High — requires file system watchers and cache invalidation logic. Could introduce stale data bugs.
36
+
37
+ **Expected Benefit**: ~100-1000ms improvement for large workspaces with many repos.
38
+
39
+ ### 4. Parallel Task Status Reads
40
+
41
+ **Current**: `listTasks()` reads each task's `status.json` sequentially.
42
+
43
+ **Proposed**: Use `Promise.all()` to read multiple task status files concurrently.
44
+
45
+ **Risk**: Low — read-only operation, no semantic change.
46
+
47
+ **Expected Benefit**: ~50-200ms improvement when listing 10+ tasks.
48
+
49
+ ## Decision for v0.6.1
50
+
51
+ All four optimizations are deferred to a future release. The current synchronous implementation is correct and well-tested. Changing the core paths would require extensive regression testing that is beyond the scope of this stability release.
52
+
53
+ ## Monitoring
54
+
55
+ The structured logging module (`src/logging.ts`) added in v0.6.1 provides the infrastructure to measure tool call durations (`duration_ms` in audit logs). Once deployed, real-world timing data can be collected to prioritize which optimization to implement first.
@@ -0,0 +1,75 @@
1
+ # PatchWarden v0.6.1 Release Notes
2
+
3
+ **Release Date**: 2026-06-25
4
+
5
+ ## Overview
6
+
7
+ PatchWarden v0.6.1 is a stability and observability release. It addresses watcher heartbeat false positives, adds Chinese path reliability, introduces two new tools (`safe_status` and `sync_file`), and adds comprehensive security guard unit tests.
8
+
9
+ ## New Features
10
+
11
+ ### safe_status Tool
12
+
13
+ A minimal task lifecycle status tool that returns task state without exposing diff, log content, or file contents. Useful when upper-layer security policies block content-bearing tools.
14
+
15
+ ```json
16
+ {
17
+ "task_id": "task-001",
18
+ "status": "running",
19
+ "phase": "executing_agent",
20
+ "last_heartbeat_at": "2026-06-24T10:00:12Z",
21
+ "current_command": "codex exec",
22
+ "watcher_state": "healthy"
23
+ }
24
+ ```
25
+
26
+ ### sync_file Tool
27
+
28
+ Copy a file from source to target within a Direct session repo. Both paths must be inside the session's `repo_path`. Supports optional sha256 verification for both source and target.
29
+
30
+ ### Android Build Doctor
31
+
32
+ When a managed project contains an `android_app` directory, the health check now includes Android build environment diagnostics: Java version, JAVA_HOME, ANDROID_HOME, SDK platform, build-tools, Gradle wrapper, and APK output path.
33
+
34
+ ## Bug Fixes
35
+
36
+ - **Watcher stale false positive**: Long-running tasks no longer cause the watcher to be incorrectly reported as stale. The watcher status now falls back to checking running task heartbeats.
37
+ - **Chinese path encoding**: All file I/O operations verified to use UTF-8 encoding. Health check now reports `path_encoding` status.
38
+ - **Tracked external dirty detection**: `captureRepoSnapshot` now correctly identifies tracked-but-modified external files via `dirty_paths` field parsed from `git status --porcelain`. The regex now includes `R` (rename) status, fixing dead code that previously never executed for renamed files.
39
+ - **Release zip path separators**: The packaging script (`pack-clean.js`) now creates zip archives with POSIX `/` path separators instead of Windows backslashes. Linux `unzip` no longer reports `warning: appears to use backslashes as path separators`.
40
+
41
+ ## Security
42
+
43
+ - 136 unit tests covering all security guards (path guard, sensitive guard, command guard, direct guards)
44
+ - Tests use Node's built-in `node:test` — zero new dependencies
45
+
46
+ ## Observability
47
+
48
+ - Structured JSON logging to stderr (never stdout, to avoid polluting MCP JSON-RPC)
49
+ - Tool call audit logs with duration tracking
50
+ - Global `unhandledRejection` and `uncaughtException` handlers
51
+
52
+ ## Tool Profile Changes
53
+
54
+ | Profile | v0.6.0 | v0.6.1 |
55
+ |---------|--------|--------|
56
+ | full | 28 | 30 |
57
+ | chatgpt_core | 16 | 17 |
58
+ | chatgpt_direct | 9 | 10 |
59
+
60
+ ## Migration
61
+
62
+ No breaking changes. All new fields are optional. New tools are additive and do not affect existing tools.
63
+
64
+ ## Verification
65
+
66
+ - TypeScript compilation: PASS
67
+ - Unit tests: 136 pass, 0 fail, 1 skipped (Windows symlink)
68
+ - Smoke tests: 139 pass, 0 fail
69
+ - Lifecycle tests: 22 pass, 0 fail (includes tracked external file rename regression test)
70
+ - Doctor CI: PASS (81 OK, 0 WARN, 0 FAIL on the release check host)
71
+ - Tool manifest check: PASS
72
+ - Package manifest check: PASS (260 files)
73
+ - Brand check: PASS (128 tracked files)
74
+ - MCP HTTP tests: 13 pass, 0 fail
75
+ - Release zip: POSIX path separators verified (261 entries, no backslashes)
@@ -0,0 +1,45 @@
1
+ # PatchWarden v0.6.4 Release Notes
2
+
3
+ **Release Date**: 2026-06-26
4
+
5
+ ## Overview
6
+
7
+ PatchWarden v0.6.4 is a desktop experience release. It keeps the existing CLI and script surface, but makes the normal Windows workflow feel like a lightweight local application: start one desktop entry, control Core/Direct from the tray or Web dashboard, and shut everything down from one stop command.
8
+
9
+ ## Desktop Entry
10
+
11
+ - Added `PatchWarden-Desktop.cmd` as the recommended daily entry point.
12
+ - The desktop entry starts the tray in a hidden PowerShell host and ensures the local Control Center is available.
13
+ - It does not automatically open a browser window. Use **Open Dashboard** from the tray or `PatchWarden-Control.cmd` when you want the full Web console.
14
+ - `PatchWarden-Control-Tray.cmd --foreground` remains available for tray debugging.
15
+
16
+ ## Tray Improvements
17
+
18
+ - Added single-instance protection for the tray process.
19
+ - Replaced the generic system icon path with a small PatchWarden-styled shield icon drawn through WinForms/System.Drawing.
20
+ - Kept the tray as a lightweight switch layer: Open Dashboard, Status, Start All, Stop All, Restart All, Open Logs, and Quit Tray.
21
+ - Added clearer balloon/status feedback for startup and lifecycle actions.
22
+ - Clarified action semantics: **Stop All** stops Core/Direct and leaves tray/dashboard available; **Quit Tray** exits only the tray; `Stop-PatchWarden.cmd` performs full shutdown.
23
+
24
+ ## Background Lifecycle
25
+
26
+ - Control Center now invokes `manage-patchwarden.ps1` with `-Background` and `windowsHide: true` for lifecycle API calls.
27
+ - The manager starts Core/Direct supervisors hidden for desktop/Web flows, while preserving visible launcher windows for explicit CLI/debug usage.
28
+ - Added `-NoTunnelWebUi` to `start-patchwarden-tunnel.ps1` so background starts do not open tunnel-client Web UI tabs.
29
+
30
+ ## Verification
31
+
32
+ - TypeScript build: PASS
33
+ - Control smoke: PASS
34
+ - Control Center smoke: PASS (23 passed, 0 failed)
35
+ - Package manifest check: PASS
36
+ - PowerShell control script parse check: PASS
37
+ - Manual desktop-flow evidence: desktop entry starts only tray + Control Center; Start/Restart uses hidden supervisors; Stop-PatchWarden closes Core/Direct, Control Center, and tray.
38
+
39
+ ## Migration
40
+
41
+ No breaking changes. Existing CLI commands and compatibility launchers remain available. For daily Windows use, prefer:
42
+
43
+ ```powershell
44
+ .\PatchWarden-Desktop.cmd
45
+ ```
@@ -15,7 +15,7 @@ or local private paths.
15
15
 
16
16
  1. Configure `patchwarden.config.json`.
17
17
  2. Run `npm.cmd run build`.
18
- 3. Use `scripts/patchwarden-mcp-stdio.cmd` as the tunnel MCP command.
18
+ 3. Use `scripts/mcp/patchwarden-mcp-stdio.cmd` as the tunnel MCP command.
19
19
  4. Start `npm.cmd run watch` in a separate terminal.
20
20
  5. Start `tunnel-client run` or use `PatchWarden.cmd start core`.
21
21
  6. Create a ChatGPT Connector using the tunnel channel.
@@ -25,10 +25,10 @@ or local private paths.
25
25
 
26
26
  For ChatGPT Direct editing, set `enableDirectProfile: true` in the trusted
27
27
  local config and run `PatchWarden.cmd start direct`. It uses
28
- `scripts/patchwarden-mcp-direct.cmd`, the separate `patchwarden-direct` Tunnel
28
+ `scripts/mcp/patchwarden-mcp-direct.cmd`, the separate `patchwarden-direct` Tunnel
29
29
  Client profile, no Watcher, and an isolated `runtime-direct` status directory.
30
- Use a separate Direct Connector/Tunnel ID so the fixed 16-tool Core catalog and
31
- the 9-tool Direct catalog never overwrite each other's cached schema.
30
+ Use a separate Direct Connector/Tunnel ID so the fixed 17-tool Core catalog and
31
+ the 10-tool Direct catalog never overwrite each other's cached schema.
32
32
 
33
33
  The Windows launcher prompts for the runtime API key once and stores only a
34
34
  Windows DPAPI-encrypted value under `%APPDATA%\patchwarden`. Use
@@ -38,7 +38,7 @@ Before the launcher starts the tunnel it performs a real MCP stdio handshake
38
38
  and requires the exact `chatgpt_core` manifest. Run
39
39
  `PatchWarden.cmd health` to see the version, profile, tool names, schema
40
40
  hash, process sources, and any mixed-version warnings. The check is read-only.
41
- The v0.4.1 core manifest contains 16 tools. A different count or schema hash
41
+ The v0.6.1 core manifest contains 17 tools. A different count or schema hash
42
42
  requires a Connector refresh and validation from a new ChatGPT conversation.
43
43
 
44
44
  ## Architecture
@@ -12,7 +12,7 @@
12
12
  # --sample sample_mcp_stdio_local \
13
13
  # --profile patchwarden \
14
14
  # --tunnel-id tunnel_xxx \
15
- # --mcp-command "C:/path/to/patchwarden/scripts/patchwarden-mcp-stdio.cmd"
15
+ # --mcp-command "C:/path/to/patchwarden/scripts/mcp/patchwarden-mcp-stdio.cmd"
16
16
 
17
17
  # Direct mode uses a separate profile and command:
18
18
  #
@@ -20,12 +20,12 @@
20
20
  # --sample sample_mcp_stdio_local \
21
21
  # --profile patchwarden-direct \
22
22
  # --tunnel-id tunnel_xxx \
23
- # --mcp-command "C:/path/to/patchwarden/scripts/patchwarden-mcp-direct.cmd"
23
+ # --mcp-command "C:/path/to/patchwarden/scripts/mcp/patchwarden-mcp-direct.cmd"
24
24
 
25
25
  mcp:
26
26
  commands:
27
27
  - channel: main
28
- command: "C:/path/to/patchwarden/scripts/patchwarden-mcp-stdio.cmd"
28
+ command: "C:/path/to/patchwarden/scripts/mcp/patchwarden-mcp-stdio.cmd"
29
29
 
30
30
  # Mode B: HTTP
31
31
  #