Skip to content

feat(cnb): add native CNB (cnb.cool) repository and PR support (#890) - #903

Open
wycocoyu wants to merge 5 commits into
Tencent:mainfrom
wycocoyu:feat/issue-890-cnb-support
Open

wycocoyu wants to merge 5 commits into
Tencent:mainfrom
wycocoyu:feat/issue-890-cnb-support

Conversation

@wycocoyu

Copy link
Copy Markdown
Contributor

Closes #890.

What changed

This PR adds Phase 1 native CNB (https://cnb.cool) support across credentials, Git transport isolation, repository binding, workspace PR submission, tracker state sync/merge, and Web/Chatbot UI:

  1. Host-scoped fail-closed HTTPS credentials (internal/gitwork, internal/runtime, internal/runner):
    • Binds https://cnb.cool with GIT_CONFIG_COUNT and an inline sh credential helper (quit=1, followRedirects=false, AGENTFLOW_SCOPED_GIT_TOKEN_0) so scoped CNB tokens never fall back to global GIT_ASKPASS, AuthConfigArgs, or RewriteRemoteForToken, and GitHub/Gongfeng PATs cannot leak to cnb.cool.
    • Bumps runner protocol gating to 0.10.2 (domain.RunnerVersionCNB): runners < 0.10.2 receive zero CNB credentials; runners >= 0.10.2 receive uncached (Cache-Control: no-store) host-scoped HTTPS credentials per claimed task without runner-side persistence.
  2. CNB OpenAPI client & personal token endpoints (internal/cnb, internal/httpapi, internal/repo):
    • Adds a minimal net/http client against https://api.cnb.cool (redirects disabled, 8 MiB response limit, Bearer token redacted in APIError).
    • Reuses PUT /api/users/:id/credentials (cnbToken / cnbTokenClear, stored in user_configs.cnb_token) and adds GET/POST /api/users/:id/cnb-token/verify (403 on /user accepted as valid when scoped to repo-code:rw + repo-pr:rw).
    • Passes commit_title in MergePull (verified required by live https://api.cnb.cool, even though swagger.json omits it from required).
  3. Multi-segment cnb:<slug> delivery & actor identity split (internal/domain, internal/tracker, internal/engine, internal/httpapi):
    • Extracts internal/tracker.pullHost so GitHub and CNB share MR delivery/sync behind one seam.
    • Parses arbitrarily nested https://cnb.cool/<org>/.../<repo> URLs (stripping /-/... subpaths) into canonical cnb:<slug>, auto-detects defaultBranch via live /-/git/head when omitted, routes SOP pull/push to ResponsibleUserID, workspace submit_mr to requesterID, and tracker merge/sync to Project OwnerID.
  4. Web & embedded Chatbot UI (web/, chatbot/, webtest/, docs/):
    • Adds the CNB 访问令牌 credential card (verify-on-save, redaction, clear) and multi-depth cnb.cool URL parsing/links (/-/pulls/, /-/tree/, /-/compare/) across project setup and workbench.

Commit Breakdown (5 Atomic Commits)

  1. 0bd1d11 refactor(tracker): extract pullHost seam for GitHub MR delivery and sync
  2. 22b33c9 feat(gitwork): add host-scoped HTTPS credential helper and block cross-host token leak
  3. 972ea4e feat(cnb): add CNB OpenAPI client and cnbHandlers for the personal token
  4. bd0e89e feat(delivery): wire cnb:<slug> repository binding, workspace PR submit, and tracker sync
  5. 00184d6 feat(ui): add CNB credential card and multi-segment cnb.cool support in web and chatbot

Visual Verification (Tabbit Browser + Live Local MySQL 8.4 on 00184d6)

Scene / 场景 Tabbit UI Screenshot
Personal Credentials — Expanded CNB 访问令牌 card (verify-on-save, masked state) 01-cnb-credential-card.png
Project Repositories — Multi-segment cnb.cool/tencent/loopforge/demo (cnb:tencent/loopforge/demo) card 02-cnb-project-repository.png
AI Workbench — Native Chatbot / Studio UI rendered with zero console errors or 5xx responses 03-ai-workbench.png

Scope

  • Platform core / API / runner
  • Public adapter / deployment
  • Classic
  • Portable
  • Shared behavior contract
  • Installer / CLI
  • Documentation only

Compatibility

  • Database schema: Adds additive manual migration migrations/033_cnb_credentials.sql (ALTER TABLE user_configs ADD COLUMN cnb_token TEXT NULL;). Existing databases without migration need the column added manually per docs/deployment.md.
  • Runner protocol: Runner build version incremented to 0.10.2 (domain.RunnerVersionCNB). Runners older than 0.10.2 continue executing GitHub/Gongfeng/SSH tasks normally and are blocked from receiving CNB credentials.
  • Backward compatibility: GitHub, Gongfeng, and SSH clone URL normalization, credentials, and MR flows remain unchanged.

Validation

Note: The code, frontend assets, SQL migration, and tests on this branch (00184d6) are byte-for-byte identical to the fork CI verification run (wycocoyu/LoopForge#5 at c934233), which only added .github/workflows/{e2e,validate}.yml from open PR #886 (37d3377) temporarily so Ubuntu 26.04 Python 3.8 / Playwright jobs could run in the fork (15/15 green). Commit c934233 is intentionally omitted here to keep #886 separate.

  • Fork GitHub Actions CI (15/15 passing, 0 failed, 0 skipped on wycocoyu/LoopForge#5):
    • validate (#43794818847): validate (3.8), validate (3.12), secrets, tcmcp, curl-install
    • e2e (#43794818933): e2e (ubuntu-24.04), e2e (ubuntu-latest, 3.8), e2e (ubuntu-latest, 3.12), e2e (macos-latest), e2e-browser (dashboard), e2e-required
    • platform (#43794818827): first-run (2m31s), browser (6m40s), core (15m3s incl. full Linux Go suites, real Chromium Go tests, coverage gate, govulncheck), platform-required (3s)
  • Live https://cnb.cool & https://api.cnb.cool End-to-End Smoke (00184d6):
    • Scoped CNB token (repo-code:rw, repo-pr:rw, no /user scope) passed POST /api/users/:id/cnb-token/verify (200 {"valid": true}) and PUT /api/users/:id/credentials (cnbTokenConfigured: true).
    • Live private repo git ls-remote failed closed (rc=128) without CNB token + GIT_ASKPASS, and git push succeeded (rc=0) via the scoped helper.
    • POST /api/repositories omitting defaultBranch resolved defaultBranch: "main" via live https://api.cnb.cool/-/git/head, and submitCNBPull -> idempotent update -> tracker findPull -> mergePull -> pull confirmed State: "merged" against live CNB (temporary token revoked and disposable repo deleted afterward).
  • Local Verification (macOS host, Exit Code 0):
    python3 scripts/check-public.py                                               # passed
    python3 scripts/collect-go-notices.py                                         # passed (86 modules)
    go vet ./...                                                                  # passed
    (cd local && bash scripts/validate.sh)                                        # Validation passed
    (cd local && bash scripts/test-observability.sh)                              # 131 x 3 OK
    (cd local && bash scripts/e2e.sh)                                             # 34 tests (1 skipped: local playwright absent; covered by e2e-browser)
    bash scripts/build-chatbot.sh                                                 # 55 files, 370 Vitest tests passed
    (cd webtest && npm test)                                                      # 189 passed, 0 failed
    go test -count=1 ./internal/cnb/... ./internal/tracker/... ./internal/domain/... ./web/...
    go test -count=1 ./internal/httpapi/... ./internal/engine/...
    go test -count=1 -skip "$REAL_BROWSER_TESTS" ./internal/runner/...
    go test -count=1 -run 'CNB|HostScoped|HTTPS' ./internal/gitwork/...
    go test -count=1 -run 'TestGitEnvironment|TestControlledBase|TestGitAskPass' ./internal/runtime/...
    go test -count=1 -run 'CNB|User|Runner' ./internal/repo/...                  # 4 MySQL cases skipped locally without AGENTFLOW_TEST_MYSQL_DSN (MySQL 8.4 verified earlier on aeb89c4)
    
  • Local macOS caveats / Not run locally: scripts/scan-secrets.sh downloads a Linux binary (passed remotely via validate/secrets); 4 pre-existing unmodified upstream tests fail on macOS (TestGitDiscoveryStopsBeforeParentRepository, TestLocalWorkspaceGitDiscoveryCannotReachParent, TestProcessSandboxPathsProfilesAndCommands, TestProjectAgentGitIndexLockWaitStopsOnCancel, all passing in Linux CI platform/core). Upstream CI validate/e2e Ubuntu 26.04 legs depend on #886.

Safety

  • I did not include credentials, internal endpoints, production data, or organization-specific infrastructure.
  • I preserved user files and unrelated changes.
  • I updated generated Classic host bundles when applicable. (Not applicable: no Classic host bundles changed.)
  • I documented third-party content and licensing changes when applicable. (Verified via scripts/collect-go-notices.py across 86 modules; no new Go/npm dependencies or third-party logos added.)
中文说明

关联并关闭上游议题 #890。

变更内容

本 PR 实现第一阶段原生 CNB(https://cnb.cool) 全链路支持,涵盖凭证存储、域名作用域 Git 传输隔离、多级仓库绑定、工作区自动提 PR、状态机同步合并与 Web / Chatbot 界面:

  1. 域名作用域且失败熔断的 HTTPS 凭证(internal/gitwork、internal/runtime、internal/runner):
    • 通过 GIT_CONFIG_COUNT 为 https://cnb.cool 注入内联 sh 凭证助手(quit=1、followRedirects=false、AGENTFLOW_SCOPED_GIT_TOKEN_0),阻断 GIT_ASKPASS、AuthConfigArgs 与 RewriteRemoteForToken 跨站回退,防止 GitHub / 工蜂 PAT 泄露给 cnb.cool。
    • Runner 版本门禁升级至 0.10.2(domain.RunnerVersionCNB):低于 0.10.2 的 Runner 不下发 CNB 凭证,达标 Runner 每次领取任务通过 Cache-Control: no-store 实时获取单次凭证,不在 Runner 侧落盘。
  2. CNB OpenAPI 客户端与个人令牌接口(internal/cnb、internal/httpapi、internal/repo):
    • 基于标准库 net/http 对接 https://api.cnb.cool(禁止自动重定向、响应上限 8 MiB、APIError 自动脱敏 Bearer Token)。
    • 复用 PUT /api/users/:id/credentials(cnbToken / cnbTokenClear,持久化于 user_configs.cnb_token),新增 GET/POST /api/users/:id/cnb-token/verify(仅授予 repo-code:rw + repo-pr:rw 时 /user 返回 403 仍判定为有效)。
    • 在 MergePull 请求中显式携带 commit_title(经真实线上接口实测必填,而官网 swagger.json 未标注必填)。
  3. 多级路径 cnb:<slug> 绑定与三端操作者身份隔离(internal/domain、internal/tracker、internal/engine、internal/httpapi):
    • 抽出 internal/tracker.pullHost 抽象层,由 GitHub 与 CNB 共同实现 MR 交付与同步。
    • 支持任意深度 https://cnb.cool/<org>/.../<repo> 解析(自动剔除 /-/... 子页面)为规范标识 cnb:<slug>;未填默认分支时调用 /-/git/head 自动回填;SOP 拉推使用 ResponsibleUserID,工作区 submit_mr 使用 requesterID,状态同步与合并使用项目 OwnerID。
  4. Web 控制台与嵌入式 Chatbot 界面(web/、chatbot/、webtest/、docs/):
    • 新增 CNB 访问令牌 凭证卡片(保存前校验、密文脱敏、清除),并在项目配置与工作台支持多段 cnb.cool 地址及 /-/pulls/、/-/tree/、/-/compare/ 跳转。

提交拆分(5 个原子提交)

  1. 0bd1d11 refactor(tracker): extract pullHost seam for GitHub MR delivery and sync
  2. 22b33c9 feat(gitwork): add host-scoped HTTPS credential helper and block cross-host token leak
  3. 972ea4e feat(cnb): add CNB OpenAPI client and cnbHandlers for the personal token
  4. bd0e89e feat(delivery): wire cnb:<slug> repository binding, workspace PR submit, and tracker sync
  5. 00184d6 feat(ui): add CNB credential card and multi-segment cnb.cool support in web and chatbot

实机界面视觉验证(00184d6 + Tabbit 浏览器 + 本地 MySQL 8.4)

场景 Tabbit 实机截图
个人配置:展开 CNB 访问令牌 卡片(保存前校验、脱敏态) 01-cnb-credential-card.png
项目配置:多段路径 cnb.cool/tencent/loopforge/demo(cnb:tencent/loopforge/demo)仓库卡 02-cnb-project-repository.png
AI 工作台:Native Chatbot / Studio 界面无控制台报错与 5xx 请求 03-ai-workbench.png

影响范围(Scope)

  • Platform core / API / runner
  • Public adapter / deployment
  • Classic
  • Portable
  • Shared behavior contract
  • Installer / CLI
  • Documentation only

兼容性(Compatibility)

  • 数据库迁移:新增增量手动脚本 migrations/033_cnb_credentials.sql(ALTER TABLE user_configs ADD COLUMN cnb_token TEXT NULL;)。存量部署按 docs/deployment.md 手动执行即可。
  • Runner 协议门禁:Runner 构建版本号升至 0.10.2(domain.RunnerVersionCNB)。低于 0.10.2 的旧 Runner 仍可正常执行 GitHub / 工蜂 / SSH 任务,仅禁止领取或接收 CNB 凭证。
  • 向后兼容:现有 GitHub、工蜂与 SSH 仓库解析、凭证保存与 PR/MR 流程保持不变。

验证情况(Validation)

说明:本分支(00184d6)的业务代码、前端构建产物、SQL 与测试与个人 Fork 验证分支(wycocoyu/LoopForge#5 提交 c934233)完全一致;c934233 仅临时叠加了待合并 PR #886(37d3377)的两个工作流修复文件,以在个人 Fork 上跑通 15/15 云端检查。本上游 PR 刻意剔除了 c934233,避免与 #886 重复。

  • 个人 Fork GitHub Actions 云端 CI(wycocoyu/LoopForge#5 15/15 全绿、0 失败、0 跳过):
    • validate(#43794818847):validate (3.8)、validate (3.12)、secrets、tcmcp、curl-install
    • e2e(#43794818933):e2e (ubuntu-24.04)、e2e (ubuntu-latest, 3.8)、e2e (ubuntu-latest, 3.12)、e2e (macos-latest)、e2e-browser (dashboard)、e2e-required
    • platform(#43794818827):first-run(2m31s)、browser(6m40s)、core(15m3s,含 Linux 全量 Go 单测、真浏览器 Go 测试、覆盖率门禁与 govulncheck)、platform-required(3s)
  • 真实 https://cnb.cool 与 https://api.cnb.cool 线上端到端冒烟(00184d6):
    • 最小权限令牌(repo-code:rw + repo-pr:rw,无 /user 权限)通过 POST /api/users/:id/cnb-token/verify(返回 200 {"valid": true})并经 PUT /api/users/:id/credentials 脱敏保存。
    • 真实私有仓在无 CNB Token 且带 GIT_ASKPASS 时 git ls-remote 熔断失败(rc=128),带域控 Helper 后 git push 成功(rc=0)。
    • 免填 defaultBranch 调用 POST /api/repositories 时经实时 https://api.cnb.cool/-/git/head 自动补全 main,完整走通 submitCNBPull 建单 → 幂等更新 → tracker findPull → mergePull → pull 回读 State: "merged"(测试后已吊销临时令牌并删除临时私有仓)。
  • 本机验证(macOS,退出码 0):
    • 合规与静态检查:scripts/check-public.py、scripts/collect-go-notices.py(86 模块)、go vet ./...、local/scripts/validate.sh
    • 本地套件与前端:local/scripts/test-observability.sh(131×3)、local/scripts/e2e.sh(34 项,本机因未装 Playwright 跳过 test_e2e_dashboard_browser,已在云端 e2e-browser 覆盖)、scripts/build-chatbot.sh(55 文件 / 370 Vitest)、webtest(189 项全过)
    • Go 套件:./internal/cnb/...、./internal/tracker/...、./internal/domain/...、./web/...、./internal/httpapi/...、./internal/engine/...、非浏览器 ./internal/runner/...(-skip "$REAL_BROWSER_TESTS")、./internal/gitwork/... 与 ./internal/runtime/... 的 CNB/HTTPS 用例、./internal/repo/... -run 'CNB|User|Runner'(本机未传 AGENTFLOW_TEST_MYSQL_DSN 时跳过 4 项 MySQL 用例;MySQL 8.4 全量已于 aeb89c4 实测通过)
  • 本机限制与说明:scripts/scan-secrets.sh 下载 Linux 二进制未在本机执行(已在云端 validate/secrets 通过);4 项未改动上游单测因 macOS /var/folders 软链及 Seatbelt 差异在本机失败,已在 Linux CI platform/core 全绿通过。上游 validate 与 e2e 在 Ubuntu 26.04 运行环境上依赖 #886 合入。

安全性自检(Safety)

  • 未包含凭证、内部域名、生产数据或组织专有基础设施。
  • 保留用户文件与无关代码改动。
  • Classic 宿主束按需更新。(不适用,本次未改动 Classic 束。)
  • 已核验第三方内容与许可说明。(scripts/collect-go-notices.py 86 模块校验通过,未新增 Go/npm 依赖或第三方图标。)

cocoyu added 5 commits November 15, 2026 10:30
…s-host token leak

Every git command now carries a cnb.cool-scoped credential block that clears
inherited helpers, answers with the user's CNB token or quit=1, and disables
redirects. CNB remotes never get the global Git token, RewriteRemoteForToken
or the global askpass. Runner >= 0.10.2 is required for CNB repositories at
dispatch and claim; older runners get no Git token for such tasks.
Also stores the personal CNB token (user_configs.cnb_token, migration 033).
internal/cnb wraps the swagger-checked pull request, default branch and user
endpoints with Bearer auth, no redirects and bounded bodies. cnbHandlers saves,
clears and verifies the signed-in user's CNB token (401 invalid, 403 valid
without a login name). The user_configs.cnb_token store and migration 033 came
with the credential pipeline in the previous commit.
…it, and tracker sync

Repositories on cnb.cool bind as provider cnb with project cnb:<group>/<repo>
(any depth, sub pages stripped) and read their default branch with the
binder's CNB token. Conversation push and workbench_workspace_submit_mr use the
requester's CNB token, create or update the open pull request and return
https://cnb.cool/<slug>/-/pulls/<n>. The tracker serves cnb: projects through
the pullHost seam with the project owner's token, merging only the repository's
own pull request and failing unless CNB reports merged.
…in web and chatbot

The personal CNB token is saved and cleared with the other credentials
(cnbToken, cnbTokenClear on PUT /api/users/:id/credentials) and verified before
saving; the separate save and clear endpoints are dropped. web and the chatbot
quick-access wizard accept https://cnb.cool/<group>/.../<repo> in any depth,
replace the 'CNB only supports HTTPS + token' notice, leave the default branch
empty for CNB so the server reads it, and link PRs, branches and compares with
/-/pulls/, /-/tree/ and /-/compare/. No third-party logo is used. A checkout
that fails because the CNB token is missing or rejected now says so instead of
blaming the GitHub token.

@Yanami-2K Yanami-2K left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已读前 50 个文件(共 86 个,工具单页上限,internal/gitwork/https_credential.go 等部分 patch 未展开)。安全边界设计清楚:CNB 地址解析拒绝 userinfo/http/伪造域名,cloneRemoteForGit 不再把全局 Git Token 嵌进 cnb.cool 远端,PublicRunnerTask 会清掉 GitHTTPSCredentials,旧 Runner 由 RunnerVersionCNB 拒绝派发,cnb.Client 不跟随重定向,并且都有对应测试。但目前不能合入:

  1. CI 失败(checksState=failure):validate (3.8)、py3.8 e2e、e2e-browser、e2e-required 失败,和同期 #214/#888/#902 一致,是 ubuntu-latest 切到 26.04 导致的(#885,修复在 #886)。请在 #886 合入后 rebase 重跑,确认没有本 PR 自身的失败。
  2. 迁移编号冲突:docs/deployment.md 引用的 migrations/033_cnb_credentials.sql 和 open 的 #894 新增的 033 迁移是同一编号。两者都合入后顺序不确定,手动执行迁移的部署会漏执行或重复执行。请和 #894 协调,后合的一方顺延到 034,并同步文档。
  3. 与 #503 重叠:本 PR 在 internal/gitwork/https_credential.go 新增按主机限定的 HTTPS credential helper,并在 domain.RunnerInvocation 加了 GitHTTPSUserID/GitHTTPSCredentials/RunnerRepository.ScopedHTTPS。#503(GitLab PAT)也在 gitwork 和 Runner 凭据下发里实现了同类机制,先合的一方会让另一方大面积冲突,而且会留下两套并行的“主机限定凭据”实现。建议保留 #503 作为通用的主机限定 HTTPS 凭据底座(它更早提交,评审也更完整),本 PR rebase 上去,把 cnb.cool 作为一个 provider 接入,只保留 internal/cnb 客户端和 PR 生命周期部分。如果维护者决定反过来,也请在两个 PR 里写明合入顺序。
  4. 次要:RunnerVersionCNB = "0.10.2" 请确认和实际发版计划一致,如果其他 PR 也在提升最低 Runner 版本,要统一。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: 腾讯自家的产品,建议加上 cnb

2 participants