feat: sync ghbot-Nodeloc v1.2.0 capabilities into upstream

Merges all 33 commits from lza6/ghbot-Nodeloc (v1.0.0 through v1.2.0)
while keeping both sides' features in every conflicted file:

- EventRouter dispatch extracted from runReview.ts (7.1), with the
  runtime environment block preserved on the review-start comment
- Unified command ack messages (6.3) combined with the collapsed
  runtime environment block and bot signature on /recheck replies
- Status banner and collapsible unposted findings in review bodies (6.1)
- Centralized runtime directories behind GHBOT_RUNTIME_DIR (D-13);
  webhook knowledge cache now lives under tempRootDirectory()
- Production hardening for merge races, timeouts, webhook ops;
  atomic temp-file rename for R2 cache restores kept from upstream
- Webhook parity retained: triage events gated by WEBHOOK_TRIAGE_ENABLED,
  read-only command guidance, repository knowledge injection,
  runtime environment block on webhook chat replies
- Sanitization/secret redaction centralization, error-aware retry,
  duplicate merge prevention, in-process webhook retries, /metrics
- Infra: eslint/prettier gates with CI verify workflow, docs archives

typecheck, eslint, prettier format:check, and 164 tests all pass.
This commit is contained in:
lezi-fun committed 2026-08-24 11:47:28 +08:00
commit 9e47ab339e
180 files changed
+15130 -1209

No files matched your search

@@ -0,0 +1,29 @@
# Implementation Plan: 001-production-hardening
## Current architecture
ghbot is a GitHub Actions + optional webhook Node service. Review, triage, conflict repair, and @bot chat are orchestrated from `src/actions/runReview.ts`. Config is a single zod schema in `src/config.ts`. Persistence is optional R2 plus local scratch directories.
## Impacted modules
- `src/review/processor.ts` — merge SHA pinning, stale-head discard, approval lookup errors
- `src/review/conflictResolver.ts` — per-PR lock, git timeouts, worktree reset
- `src/ai/apiProxy.ts` / `src/ai/gooseCli.ts` — proxy/process timeouts and bounded output
- `src/webhook/server.ts` — body deadline, request catch, metrics
- `src/config.ts` / workflows / `.env.example` — GHBOT_RUNTIME_DIR, webhook/R2 cross-checks
- docs — webhook secret, docker run, goose aliases
## Implementation strategy
Fix production failure modes first. Keep AUTO_MERGE default false. Prefer additive guards over architecture rewrites. Do not extract the 1700-line processor router in this pass because there is no isolated event-loop test harness; that refactor is deferred with an explicit risk note.
## Verification
- npm run typecheck / lint / format:check / test
- production-build webhook HTTP smoke (healthz, HMAC, duplicate, metrics)
- npm audit --omit=dev against registry.npmjs.org
- independent six-dimension review after gates
## Rollback
Revert the production-hardening commit on the fork. Defaults remain conservative (AUTO_MERGE=false, WEBHOOK_ENABLED=false).
@@ -0,0 +1,71 @@
# Feature Specification: 001-production-hardening(生产硬化总审计)
## 问题陈述
ghbot 已在生产仓库运行(自动审查/分类/合并/冲突修复)。用户要求以"终局闭环总审计"标准,
对全部功能做查漏补缺:功能完整性、前后端衔接(此处为 workflow↔代码↔GitHub API 契约)、
调用体验、部署体验、文档一致性,并补齐指南中剩余未落地项。
## 用户故事
### US-1: 部署者首次接入
作为部署者,我希望按 README 从零配置后一次跑通,无需口口相传的隐性前提。
**验收**:
- [ ] .env.example 覆盖全部 config schema 字段且默认值一致
- [ ] README 步骤与实际命令一一对应
- [ ] 新增配置项有文档说明
### US-2: 事件全链路
作为仓库维护者,任何支持的事件触发后都有确定行为与反馈。
**验收**:
- [ ] workflow 触发的事件类型 ⊆ runReview.ts 处理集合(无静默吞事件)
- [ ] issue_comment 三链路互不阻断
- [ ] 每条失败路径都有可见反馈或日志
### US-3: 审查结果可信
作为 PR 作者,审查评论必须准确、可定位、不误导。
**验收**:
- [ ] finding 的 path/line 经净化后才提交
- [ ] 无法 inline 的 findings 折叠展示不丢失
- [ ] 状态横幅与 disposition 一致
### US-4: webhook 服务可运维
作为运维者,服务健康可探活、指标可观测、异常可恢复。
**验收**:
- [ ] /healthz 与 /metrics 真实可用
- [ ] 队列满/签名错/超大包均有明确响应码
- [ ] 失败投递进程内重试后仍可被 GitHub 重投
### US-5: 剩余指南项落地
指南 7.1 / 6.4 / 8.5 / 4.4 不再是"候选",全部实现或有明确的不适用结论。
**验收**:
- [ ] 每项有代码证据或书面不适用理由
- [ ] 全部门禁通过
## 非功能性需求
- 兼容性:Node >=22 <26;Windows/Linux 双平台测试通过
- 可观测性:关键路径日志含 owner/repo/pullNumber/eventName 四元组
- 安全性:宪法红线零违反
- 可维护性:无重复实现的安全清单;文件 <800 行
## Out of Scope
- 真实付费 LLM 调用的 E2E(预算 0)
- 前端 UI(本项目无前端)
## 成功指标
- 门禁六项全绿
- E2E:webhook 生产构建真实 HTTP 验收通过
- 需求追踪矩阵无"未闭环"项
@@ -0,0 +1,25 @@
# Implementation Tasks: 001-production-hardening
## Phase 1: Spec and audit
- [x] 1.1 Constitution + spec
- [x] 1.2 Parallel contract/security/error/docs audit
## Phase 2: Production guards
- [x] 2.1 Merge SHA recheck + pulls.merge sha
- [x] 2.2 Conflict lock + git command timeout + dirty worktree reset
- [x] 2.3 Webhook body timeout/size and request catch
- [x] 2.4 API proxy abort/timeout/body cap
- [x] 2.5 Goose process output cap and cleanup timeouts
- [x] 2.6 Config cross-field validation and GHBOT_RUNTIME_DIR contract
- [x] 2.7 Issue comment handler isolation with AggregateError
- [x] 2.8 Approval permission lookup no longer swallows retryable errors
- [x] 2.9 Event logger child bindings
## Phase 3: Verify and handoff
- [ ] 3.1 Local gates (typecheck/lint/format/test)
- [ ] 3.2 Webhook HTTP E2E
- [ ] 3.3 Independent review
- [ ] 3.4 HTML change report + skill + docs