Skip to content

feat(workspaces): open conversation workspaces by sandbox with agent-owned Git - #947

Merged
crispinhu27 merged 23 commits into
mainfrom
feat/workspace-by-sandbox
Nov 16, 2026
Merged

crispinhu27 merged 23 commits into
mainfrom
feat/workspace-by-sandbox

Conversation

@crispinhu27

@crispinhu27 crispinhu27 commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

  • Replaced pre-checked-out conversation workspaces with sandbox-based environments (workbench_workspace_open takes sandboxProfileId), letting agents clone, branch, commit, push, and open/manage PRs with their own git/gh using the turn speaker's scoped credentials (GIT_ASKPASS restricted to https://github.com, GH_TOKEN, and per-host:port ssh-agent with pinned host keys).
  • Removed legacy workspace/GitHub proxy MCP tools (workbench_github_*, workbench_workspace_tree/read/write/command/attach/submit_mr/sop, workbench_attachment_read); retained workbench_platform_mode, workbench_browser_*, and workbench_publish_artifact (including host workspace absolute paths under /<runID>/...).
  • Added external-write approval guardrails (git push, gh writes, curl/wget writes, package/image/infra pushes) with Chatbot NativeApprovalPanel and automatic end-of-turn GitHub PR registration onto requirements.
  • Enabled native sandboxes (bwrap on Linux, seatbelt on macOS with last-match-wins SBPL write protection for approval hooks and parent directories) for conversation workspaces, dropped docker.sock mounting and shims from Docker sandboxes, and forwarded host Docker context endpoints as DOCKER_HOST to isolated-HOME processSandbox commands without sharing registry auths.
  • Updated EnsureSandboxBrowser's unwrapSandbox to unwrap interface{ Unwrap() Sandbox } wrappers (including *engine.runEnvironment) so local SOP agent nodes receive agentflow-browser MCP.

Scope

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

Compatibility

  • Docker conversation workspaces no longer mount host docker.sock; use native (bwrap on Linux, seatbelt on macOS) when container/Docker daemon access is needed from a conversation workspace.
  • No new migration and no schema change in this PR. docs/conversation-workspaces.md refers to migrations/020_conversation_workspaces.sql, which has been on main since feat: sync chat home, conversation workspaces and delivery tracking #65; deployments that already ran it have nothing to run for this PR.

Migration path for removed tools

Removed Replacement after this PR
workbench_github_* (PR/Issue list, view, review, comment, merge) Open a workspace and use gh / the GitHub API with the turn speaker's GH_TOKEN. The system prompt and the scheduled-task prompt (scheduledAssistantPrompt) already say so.
workbench_workspace_tree/read/write/command CLI native file, patch and command tools inside the workspace after handoff (tree stays internal for workspace preparation).
workbench_workspace_submit_mr (incl. mode=direct) The agent runs git push / gh pr create itself; in 「请求批准」 mode they wait for the speaker's approval card. PRs opened in the turn are registered on the requirement when the turn ends.
workbench_workspace_sop runs_pause / runs_cancel the SOP first, then workbench_workspace_open.
workbench_workspace_attach workbench_publish_artifact with a workspace path.
workbench_attachment_read Attachments are listed with native-readable paths; the CLI reads them with its own tools.
issueId / workspaceRunId / new on workbench_workspace_open Only sandboxProfileId; returning to a sandbox the conversation used before reuses that workspace.

Stored prompts written by users (for example a scheduled task that names workbench_github_pr_review) are not rewritten: the CLI no longer sees that tool, and the system prompt points it to the workspace + gh path instead. Whether to ship removal in this PR or split "add new path" / "remove old tools" is a maintainer decision.

Validation

Ran after final commit b46f730:

  • go vet ./... — passed on macOS.
  • macOS targeted runtime tests (go test -v -count=1 ./internal/runtime -run 'TestEnsureSandboxBrowser|TestConfigureProcessConversationSandbox|TestSeatbeltProfile|TestEnsureConversationCLI|TestConversationProcessSeatbelt|TestProcessSandboxResolvesHostDockerContextWhenHomeIsolated|TestScriptViewsPreserveProcessSandboxBoundaries') — passed (including live sandbox-exec + Colima docker ps and docker run --rm alpine true).
  • Privileged Linux container (bubblewrap 0.8.0, AGENTFLOW_SANDBOX_SMOKE=1) targeted tests (internal/runtime smoke/bwrap/docker-context tests, TestRunEnvironmentUnwrapsForEnsureSandboxBrowser, TestMainBotAttachesWorkspaceFilesToReply) — all passed.

Ran prior to final b46f730 commit (on 9648ad1 / 24a3e06):

  • go test -count=1 ./internal/domain ./internal/repo, go test ./internal/httpapi, go test -count=1 -parallel 4 ./internal/engine ./internal/runner — passed on macOS (./internal/runtime full package on macOS has 4 pre-existing Linux/host baseline failures unrelated to this PR).
  • End-to-end live verification on Compose (9648ad1), local macOS seatbelt (24a3e06), and privileged Linux bwrap (24a3e06) with real CodeBuddy, browser MCP, and conversation workspaces — passed.

After merging main (80bc046) and the secret-scan fixture fix (81b1015), on Linux: go build ./..., go vet ./..., go test -p=4 ./... (only internal/runtime Docker-image cases and internal/scriptview capability drop fail, identically on unchanged main in the same container), internal/repo against MySQL 8.4.7, chatbot npm run build + 370 vitest tests, python3 scripts/check-public.py and bash scripts/scan-secrets.sh (no leaks) — all passed. CI on the PR runs the full platform / e2e / validate set.

Not run: local/scripts/validate.sh, local/scripts/smoke-install.sh, local/scripts/e2e.sh.

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.
  • I documented third-party content and licensing changes when applicable.

crispinhu27 and others added 17 commits November 15, 2026 00:44
… git

- workbench_workspace_open only takes sandboxProfileId; the workspace starts
  empty and the agent clones, branches, commits, pushes and opens PRs itself.
  Switching environment resumes the conversation's own workspace there.
- Workspace-mode CLI gets the turn speaker's Git token (askpass limited to
  GitHub and Gongfeng), GH_TOKEN, host-scoped SSH keys and commit identity.
- Conversation workspaces accept native sandboxes (bwrap on Linux) with the
  same HOME/cwd layout and read-only approval hooks; seatbelt is refused.
- Remove the self-built workbench_github_* tools, workspace
  tree/read/write/command/submit_mr/sop and attachment_read; add
  workbench_delivery_register to link PR/MR links to the requirement.
- Update prompts, chatbot activity labels, docs and tests.

Co-Authored-By: Claude Code <noreply@anthropic.com>
- internal/dockerproxy: filtering Docker API proxy per workspace. Labels
  created containers/networks/volumes, scopes lists/events/prune, refuses
  foreign objects and host escapes (privileged, caps, devices, host
  namespaces, masked paths, out-of-workspace binds, foreign volumes).
- Workspace CLIs get DOCKER_HOST pointing at the proxy socket in a short
  per-conversation /tmp dir mounted into Docker and bwrap workspaces; bwrap
  masks host docker/containerd/podman sockets. Running containers are
  stopped when the CLI exits. AGENTFLOW_WORKSPACE_DOCKER=off disables it.
- workbench_workspace_attach leaves the catalog; workbench_publish_artifact
  takes a workspace path (and keeps content publishing in spaces).
- Drop clarification streams/jobs and runs_logs_download from agent catalogs.

Co-Authored-By: Claude Code <noreply@anthropic.com>
- Deleting a workspace directory (run delete, conversation delete, idle
  reclaim) first removes the containers, networks and volumes labelled for
  it; stale /tmp/lf-docker-* socket dirs of deleted conversations are reaped.
- Images built or committed through the proxy carry the workspace label;
  only those may be deleted or have their name overwritten (build -t, tag,
  commit, import). docker load is refused.
- Bind sources are handed to the daemon as resolved real paths.

Co-Authored-By: Claude Code <noreply@anthropic.com>
- Binds below a workspace or HOME root become subpath mounts of a
  proxy-owned local volume bound to that root (Docker 26+ / API 1.45), so a
  directory swapped for a symlink after the check cannot redirect the mount.
  Bind propagation and SELinux options are dropped; unknown options refused.
- buildx's raw /grpc channel is refused for now; workspaces get
  DOCKER_BUILDKIT=0 so docker build goes through the checked /build.
- Checkpointed reclaims keep the workspace's Docker volumes; destroying the
  run removes them, even after the directory is gone.
- Built-in GitHub SSH host keys (github.com, ssh.github.com:443), combined
  with AGENTFLOW_GIT_SSH_KNOWN_HOSTS for other hosts.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The proxy now terminates the /grpc h2c upgrade on both sides and relays
BuildKit calls. Control.Solve gets the classic /build rules (no
entitlements, default/none network only, no cgroup parent, image names
only where -t may write) and the workspace label; daemon-wide calls
(prune, other builds' history) and unknown services are refused.
DOCKER_BUILDKIT=0 is no longer forced in workspaces.

Adds opt-in live tests for real bwrap and Docker-driver conversation
workspaces and for buildx through the proxy.

Co-Authored-By: Claude Code <noreply@anthropic.com>
… queries

ListenBuildHistory without a ref lists every build on the daemon; only
following a build by its (random) ref is relayed. DiskUsage is refused
like system df.

Co-Authored-By: Claude Code <noreply@anthropic.com>
- JSON field names: the daemon matches them case-insensitively (with
  Unicode folding), the checks looked them up exactly, so
  {"hostconfig":{"privileged":true}} passed. Keys that fold to a field the
  proxy reads are renamed to the canonical name before checking; keys
  differing only in case are refused. A test keeps the field list in sync
  with the lookups in proxy.go.
- Form bodies: the daemon's FormValue prefers a urlencoded/multipart body
  over the checked query (tag, build, image create). Refused.
- Links (HostConfig and endpoint) must point at own containers.
- Networks: bridge only, no driver options, custom IPAM/subnets or
  config-from (host interface names, route shadowing).
- Root binds drop propagation options; --mount BindOptions.Propagation too.
- An unknown daemon version refuses subdirectory binds and retries instead
  of falling back to plain binds for the proxy's lifetime.
- Docs: build-time URL fetches on the host network and daemon-wide BuildKit
  cache mounts are deployment-level limits.

Co-Authored-By: Claude Code <noreply@anthropic.com>
docker pull rewrites the local name; pulling "myapp:dev" from a registry
would swap an image another workspace built. Pulls of public names and
own images still pass.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Labels and options are decoded with exact keys, so keys there that differ
only in case are legitimate and are no longer refused.

Co-Authored-By: Claude Code <noreply@anthropic.com>
- Container create: the daemon still reads deprecated HostConfig fields
  at the top level of the body; only container.Config fields plus
  HostConfig/NetworkingConfig are accepted there.
- Form bodies are matched by Content-Type prefix: Go's ParseForm parses a
  body whose media parameters are malformed.
- images/create follows the daemon: fromImage means pull, whatever else
  is set.
- Classic /build outputs: image names get the -t rule.
- An endpoint's explicit NetworkID (preferred by the daemon over the
  name) must be an own network, on create and on connect.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The fake server dropped the TCP connection right after exit-status, which
raced the git client's own channel close and failed the push with "send
disconnect: Broken pipe" under load.

Co-Authored-By: Claude Code <noreply@anthropic.com>
From the third review pass:
- Objects named json/create/prune/search/get were taken for collection
  routes whatever the method, so DELETE /volumes/create removed another
  workspace's volume named "create" (verified on Docker 26). Collection
  routes now require their own method; everything else is an object and
  gets the ownership check.
- After the check, the daemon receives the full ID that was checked (path
  object, commit container, network connect container, container: modes,
  endpoint NetworkID), so a name is not resolved a second time (ID-prefix
  ambiguity, swapping an object between check and action).
- The forwarded path is the cleaned, decoded path that was checked.
- commit --change cannot set the workspace label; container update cannot
  set a cgroup parent.

Co-Authored-By: Claude Code <noreply@anthropic.com>
- Remove Gongfeng from the workspace feature: askpass answers only
  github.com, delivery registration accepts GitHub PR links only
  (domain.IsGitHubPRURL), prompts and docs no longer mention Gongfeng.
  Tokens with an oauth2:/private: prefix are not injected.
- askpass parses the host from the prompt URL and compares it exactly;
  the substring match handed the token to github.com.evil.example.
- Compose: workspace Docker proxy sockets live under /tmp/lf-docker,
  shared with the host at the same path. Sibling workspace containers
  bind the socket directory on the host, so a directory in the platform
  container's own /tmp reached them empty and docker could not connect.
  The base directory must be owned by the platform user, 0700, not a
  symlink.
- bwrap masks only resolved host Docker socket paths: it cannot mount over
  a path with a symlinked parent (/var/run -> /run in Debian images),
  which kept native workspaces from starting.
- Docs: Compose deployments use Docker sandboxes; the native sandbox needs
  namespaces the unprivileged platform container cannot create.
- Stale reminders/comments updated; dead review branch for removed
  workspace tools dropped; assistant_mcp.go back to main.

Verified on a local Compose deployment (colima, Docker 29.5.2): Docker
and native (privileged test override) workspaces, HTTPS/SSH clone and
push, PR creation with GH_TOKEN, delivery registration, proxy denials,
switching environments and back.

Co-authored-by: Cursor <cursoragent@cursor.com>
…istration

- Remove the workspace Docker proxy. Workspaces use the host daemon socket
  directly; the CLI keeps <root>/ws as its cwd so native sessions resume
  across mode switches, and a read-only docker shim rewrites <root>/ws paths
  to the workspace's host path. The conversation HOME's login files put the
  shim back on PATH after login shells reset it.
- Sandbox-internal commands and files run without approval. Commands that
  write to outside systems (git push, gh/GitHub API writes, HTTP writes,
  publishing, image pushes, cluster changes) follow the approval mode:
  confirm shows an approval card, assisted asks the reviewer, auto runs.
  Card input is redacted per JSON string so it stays valid JSON.
- Drop workbench_delivery_register; new GitHub PRs from the workspace are
  detected at the end of each turn and registered, creating an issue when
  needed.
- Each phase may restart once when a native journal cannot be resumed, and
  the restart prompt states the current mode.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Stop mounting the host Docker socket into Docker conversation workspaces; remove conversation_docker.go, the workspace-bin/docker path-rewriting shim, conversation HOME profile PATH injection, and the duplicate host-path workspace mount.
- Keep bwrap conversation workspaces unchanged with natural read-only host filesystem access (no /dev/null socket masking).
- Restore scriptview alias validation (/ws suffix) and protocol v3, compose.yaml, go.mod/go.sum, and workspace artifact path handling; update docs accordingly.

@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.

这个 PR 改了 99 个文件(+2791/−6079),把对话工作区改成“按沙箱打开、Agent 自己管 Git”。审查结论是要求修改,主要问题如下:

  1. 和 main 有冲突(mergeableState=dirty):请先 rebase 到最新 main。打开的 PR 里 #946 也改了 internal/runner/workspace.go,#902(同一作者)也改了 assistant 相关代码,rebase 时请一并处理。
  2. CI 没有真正跑过:本 PR 只有开源扫描一项检查,platform / e2e / validate 都没有触发;描述里也写明没跑 go test -p=2 ./...、python3 scripts/check-public.py、scripts/scan-secrets.sh。这次删了大量代码和测试,又新加了沙箱、凭据注入、审批钩子,至少需要完整 CI 和密钥扫描全绿。
  3. 描述和 diff 不一致:Compatibility 写着 “Includes manual migration migrations/020_conversation_workspaces.sql”,但 99 个改动文件里没有任何 migrations/ 下的文件。请补上迁移,或者删掉这句描述。另外编号 020 看起来早于现有迁移(比如 #894 已经用到 033),请确认编号不会和已有文件冲突。
  4. 删掉了现有能力,需要维护者拍板(属于产品和架构取舍):PR 删除了 workbench_github_*(internal/httpapi/agent_tool_github*.go 约 1340 行和对应测试)、workbench_workspace_submit_mr(包括 mode=direct 直推共享分支)、workbench_workspace_sop(接管 SOP 工作区)、workbench_attachment_read,以及按 issueId / workspaceRunId 切换工作区的语义。平台提示词、定时任务(例如本审查任务就依赖 workbench_github_pr_review)和文档目前都依赖这些工具。请在描述里列出迁移路径(哪些调用方要改、旧提示词怎么办),或者拆成“先加新能力,再在后续 PR 下线旧工具”两步。
  5. 外部写入审批只是护栏:docs/conversation-native-cli.md 自己也写了“这是防误操作的护栏,不是安全边界:脚本自己联网写入不会被识别”。原来由平台代理 GitHub 写操作时可以审计、可以审批,现在把 GH_TOKEN 和 GIT_ASKPASS 直接交给沙箱里的 CLI,权限面变大了。请说明“完全权限 / 帮我批准”以外的模式下,令牌被脚本直接使用的风险是否可以接受,或者把令牌限制到具体仓库或更小的 scope。

说明:diff 中 internal/httpapi/assistant_workspace_open.go、assistant_workspace_mr.go、assistant_native_approval.go、assistant_native_external.go、internal/runtime/sandbox_process.go、command_binding.go、conversation_sandbox.go 等主要文件的 patch 被省略或截断,我没有逐行看到这些实现。上面的意见基于能看到的部分(gitwork/ssh.go、gitwork/checkouts.go、domain、chatbot、文档)和 PR 描述。建议把这个 PR 拆小,方便逐块审查。

crispinhu27 and others added 2 commits November 16, 2026 15:15
…cret scan

core failed at scripts/scan-secrets.sh: gitleaks' curl-auth-header rule
flagged the literal "Authorization: token ghp_secretvalue" in
TestNativeApprovalCardInputStaysValidJSONWhenRedacted. The fixture now
uses "$GH_TOKEN", the form an agent writes in a workspace where GH_TOKEN
is set. The test still proves the same thing: text redaction of the
encoded JSON breaks it, while redactNativeApprovalInput keeps valid JSON
and replaces the header value with [redacted].

Co-Authored-By: Claude Code <noreply@anthropic.com>
@crispinhu27

Copy link
Copy Markdown
Collaborator Author

处理 Yanami-2K 07:07Z 审查意见 + 本地部署验证(head 81b1015)

# 意见 处理
1 与 main 冲突 已由 80bc046 合并最新 main(#810)。我独立合并了一遍,结果树与 80bc046 完全一致:assistant_unfinished.go 的 currentGeneration 保留 main 的 readGeneration(不收割本进程仍在跑的轮次),同时保留本分支删掉的 settleLegacyWorkspaceNativeApprovals;补回分支仍需要的 time import;main 新测试 TestGenerationRecordsTheWorkspaceLeaseItsToolTakes 改用本分支的 workspaceTestEdit(同样占用本轮租约)。#946 还没合入,等它合入后如有冲突再处理。
2 CI 没真正跑过 / 未跑 scan-secrets 合并后 CI 已全量触发。core 唯一失败是 scripts/scan-secrets.sh:gitleaks curl-auth-header 命中测试夹具 Authorization: token ghp_secretvalue。81b1015 把夹具改成 $GH_TOKEN(工作区里 Agent 的实际写法),测试仍然证明「按文本脱敏会破坏 JSON、redactNativeApprovalInput 保持合法 JSON 并替换成 [redacted]」。本地 gitleaks 8.30.1:no leaks;check-public.py 通过。
3 描述说包含迁移 020,但 diff 没有 核实:本 PR 没有任何 schema 变更,migrations/020_conversation_workspaces.sql 自 #65 起就在 main 上,文档引用的是它。已改描述,不再说「包含迁移」。
4 删除旧工具需维护者拍板 已在描述里补「Migration path for removed tools」表,逐个列出替代方式;仓库内提示词、定时任务提示词和文档已无对旧工具的正向依赖(剩下的引用都是断言「不再出现」的测试)。是否在本 PR 下线、还是拆成两步,需要维护者决定。
5 GH_TOKEN / askpass 交给沙箱的风险 属于安全取舍,需要维护者决定。现状:令牌是本轮发言人自己的;askpass 只对 github.com 应答;平台自己的令牌不进沙箱;「请求批准」模式下 git push、gh 写操作、curl 写请求会暂停等批准,但脚本自行联网写入识别不了(文档已注明是护栏)。如果要收窄,可以改用按仓库授权的 fine-grained token,这需要改凭据模型,建议另开 issue。

CI(81b1015)

core、browser、first-run、platform-required、secrets、tcmcp、validate (3.12)、三组 python 3.12 e2e 全部通过。剩下 validate (3.8)、e2e (python 3.8)、e2e-browser、e2e-required 失败,日志是 The version '3.8' ... was not found for Ubuntu 26.04 和 Playwright does not support chromium on ubuntu26.04-x64,和 #902 一样是 runner 镜像问题,修复在 #886。

本地部署验证(Linux,MySQL 8.4.7,agentflow -role all,本 PR 构建)

  • 手动执行 020、032 迁移和 seed 成功;/api/health 200;日志无 panic。
  • CLI 用本地替身。容器不能建命名空间,所以 native 沙箱用一个只做 chdir 的 bwrap 替身,不是隔离验证。
  • 平台模式下网关只给出 workbench_workspace_open 和浏览器工具,workbench_github_* 为 0 个。
  • 审批卡片:往运行中的轮次写入一条待批准的 git push(直接写库模拟,不是 CLI 钩子产生的)。Chrome 里出现「批准外部写入:git push」卡片,点「批准本次操作」后库里 decision=allow,卡片消失,轮次 completed。
  • workbench_workspace_open(sandboxProfileId=native-local) 返回 handoff=true。轮次运行中 assistant_generations.workspace_run_id/workspace_lease 已记录,且与 run_workspace_checkpoints 的租约一致(fix(assistant): keep a live generation through a slow heartbeat #810 合入后的行为)。交接后 CLI 在工作区续接并完成,结束后租约已释放。
  • 工作区内再发一轮:CLI 环境里 GH_TOKEN 是本人配置的令牌(40 位),GIT_ASKPASS 已设置;新租约记录后也在结束时释放。
  • go test -p=4 ./...:只有 internal/runtime 的 5 个 Docker 镜像用例和 internal/scriptview 的 capability 用例失败,在同一容器里未改动的 main 上同样失败(环境限制)。chatbot 370 个测试通过。

截图

审批卡片(批准前):
approval

打开 native 工作区后的轮次与工作区内的后续轮次:
workspace

@crispinhu27

Copy link
Copy Markdown
Collaborator Author

本地部署验证(head 51dc7bb,PR #947,16:00 轮)

环境:MySQL 8.4.7 原生二进制,agentflow PR#947 构建(feat/workspace-by-sandbox),替身 CodeBuddy CLI(Python stub,调用 MCP 工具列表),bwrap 替身(chdir-only,不隔离),Linux 容器。

CI(51dc7bb)

全部通过:browser、core、first-run、platform-required、secrets、tcmcp、validate 3.8、validate 3.12、e2e(4 组)、e2e-browser、e2e-required

功能验证

场景 结果
平台工具列表 55 个工具,含 workbench_workspace_open,workbench_github_* 为 0 个
workbench_workspace_open(sandboxProfileId=native-local) created=true, handoff=true,工作区记录创建,日志 ok=1
工作区内第二轮 GH_TOKEN=set, GIT_ASKPASS=set,工具数降为 9(工作区内工具集)

截图(01 平台工具、02 工作区开启后、03 工作区内轮次):

本地测试

  • go build ./...、go vet ./... 通过
  • go test ./internal/httpapi ./internal/repo ./internal/engine ./cmd/agentflow -count=1 ok(Docker/runtime/browser 用例因容器环境在 main 上同样失败)
  • npm run build + 370 个 vitest 通过
  • scan-secrets.sh 无泄漏,check-public.py 通过
  • /api/health 200,日志无 panic

剩余阻塞

  1. Yanami-2K 需要重新复审(本轮推送后 CI 全绿)
  2. 审查第 4 条(是否在本 PR 下线旧工具)和第 5 条(GH_TOKEN 交给沙箱的风险)仍需维护者拍板

Robert0622
Robert0622 previously approved these changes Nov 16, 2026

@Robert0622 Robert0622 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.

实测结论:Approve(附几条非阻塞建议)

在 head 51dc7bb 上本地构建并部署(agentflow -role all + MySQL 8,e2e/local.sh 起环境),CLI 用真实 CodeBuddy(deepseek-v4.1-flash),Linux 上安装了 bubblewrap 0.4.0 跑真实 native 沙箱。

实测通过的场景

场景 结果
平台模式工具目录 只剩 workbench_workspace_open、浏览器工具和 workbench_tool_schema,workbench_github_* / attachment_read 为 0
旧参数 issueId 调 workspace_open 被 schema 拒绝(additionalProperties)
native(bwrap)工作区:clone → 建分支 → 修 bug → commit → push 正常;「请求批准」模式下只有 git push 一条命令弹审批,批准前远端没有分支,批准后推送成功
拒绝审批 不推送,Agent 不换方式重试,审批不残留
「完全权限」模式 push 不弹审批直接成功
审批等待中停止生成 审批被释放、未推送,无 bwrap/CLI 残留进程
Docker 工作区(node 镜像) 提交身份 <login>@users.noreply.loopforge.invalid 生效;GH_TOKEN 注入、GIT_ASKPASS 指向 /workspace/.agentflow/runtime/git-askpass-hosts;容器内无 /var/run/docker.sock
同一对话 native → Docker → native 切换 切回 native 时复用原工作区,本地未推送的提交还在
Chatbot 审批卡片(Playwright 真浏览器) 卡片显示「批准外部写入:git push」+ 命令,点「批准本次操作」后卡片消失、推送成功
askpass 脚本 只对 https://github.com 应答;github.com.evil.io、github.com@evil.io、evil.io/github.com、http://、带端口等都不给令牌

测试套件

  • go vet ./internal/... 通过;internal/{domain,engine,runner,gitwork} 全过。internal/runtime 的 TestLightweightSandboxSmoke、TestManagedMCPRuntimeInstallsAndLaunchesInAvailableProcessSandbox 失败,在 main 上同样失败(测试 TempDir 在 /tmp,被 bwrap 的 --tmpfs /tmp 盖住);TestMainBotBrowserStartsAndDrivesRunBrowser 并发跑时偶发失败,单独跑通过。
  • chatbot npm run build + vitest 370/370 通过。
  • e2e(真实模型 + Docker):API 176 个,169 过 / 4 跳过 / 1 失败(schedule job「workflow not found」,新库里没有通用 SOP 模板,本 PR 未改相关代码);UI 21 个,20 过,剩余 1 个是重跑时遗留 SOP 导致的选项重复(strict mode)。

非阻塞建议

  1. 「帮我批准」对原生外部写入基本会退化成手动确认。assistant_native_approval.go 里给审查只留了 context.WithTimeout(ctx, 15*time.Second),而 approvalReviewer 自己的预算是 60s。实测审查 15s 到点后显示「自动审批已取消或超时,请手动确认后执行」,然后转成人工卡片。结果是安全的(不会放行),但这个模式名不副实。可以考虑首次轮询时在后台起审查、先返回 pending,后续轮询读结果,这样不受 hook 单次请求 20s 的限制。
  2. bwrap 下 GIT_ASKPASS / GIT_CONFIG_SYSTEM 用的是工作区的宿主路径。工作区根目录在 /tmp 下时(比如 e2e/local.sh),--bind root root 之后的 --tmpfs /tmp 会把它盖住:git 读不到身份(Author identity unknown),askpass 也找不到。默认根目录 ~/.agentflow/workspace 不受影响,改用沙箱内的 <conversation>/ws/.agentflow/runtime/... 路径会更稳。
  3. 默认镜像里没有 gh。IsolatedDockerfile(generic-docker)不带 gh,而 PR 管理现在完全交给工作区内的 gh(定时 PR 审查任务也是),每个新工作区都要先装一遍。建议在默认镜像里加上 gh。
  4. 旧的 Gongfeng HTTPS 推送 / MR 路径没有了(askpass 只认 github.com,轮次结束只登记 GitHub PR)。Gongfeng 在 main 上已经标为 legacy,在 Compatibility 里提一句会更清楚。

删除旧工具和令牌进沙箱这两个取舍,之前的 review 已经提出来交给维护者决定;从实测看,迁移路径可用,审批护栏的行为也和文档一致。

@crispinhu27

crispinhu27 commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

帮我批准 应当只有同意 以及 拒绝,不应该出现人工确认;默认镜像没有gh符合预期,此项交由agent自行处理

@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.

复审 head 51dc7bb。CI 已全绿、与 main 无冲突,上轮第 1、2 条已处理。下列问题仍阻塞合入:

  1. 个人 Token 以明文环境变量进入沙箱(internal/runtime/command_binding.go 的 BindGitWorkspace,文档 docs/conversation-workspaces.md「Git 凭据」)。GIT_ASKPASS 只对 https://github.com 应答的限制是对的,但同一个令牌又以 GH_TOKEN 注入 CLI 进程环境,沙箱内任何子进程(clone 下来的仓库脚本、npm install 的 postinstall、被提示注入的命令)都能读到并外发,askpass 的主机限制因此失效。文档也承认外部写入识别「不是安全边界」。建议:默认不注入 GH_TOKEN,改为由平台侧代理 / 短时效、最小权限的令牌;至少要在沙箱配置中显式开启,并在文档和 UI 里写明风险。这是上轮第 5 条,PR 描述里仍标为待维护者拍板。

  2. 移除旧工具会直接破坏存量用法(删除 internal/httpapi/agent_tool_github.go、agent_tool_github_pr.go、assistant_workspace_sop.go,以及 agent_tool_catalog.go 中的 mainBotGitHubTools / workbench_attachment_read)。已保存的定时任务和角色 prompt(例如调用 workbench_github_pr_review 的自动审查任务)会在升级后无声失效;而且无人值守任务在「请求批准」模式下走 gh pr review 会卡在没人点的审批卡上,9 分钟后被拒绝。建议拆成两步:本 PR 只加新路径,旧工具保留并标记弃用;下线放到后续 PR,并附存量 prompt 的迁移或兼容提示。

  3. 「帮我批准」的行为与作者最新要求不一致。docs/conversation-native-cli.md 写的是「未通过时转为人工批准」,但 08:54 的评论要求「帮我批准应当只有同意以及拒绝,不应该出现人工确认」,当前 head 还没有对应改动。请在 internal/httpapi/assistant_native_approval.go 里把审查未通过(含 15 秒超时)改为直接拒绝并返回原因,同步更新文档和 design.md,并补一条「帮我批准 + 审查拒绝」不产生 native-approvals 卡片的测试。

  4. internal/gitwork/checkouts.go 的 Checkouts 对沙箱用户可控的仓库使用 -c safe.directory=* 执行 git。如果它运行在平台或执行机宿主进程里(RunnerWorkspaceOperationCheckouts),就等于关掉了 git 针对「他人拥有的仓库配置」的保护。建议同时传 -c core.fsmonitor= -c core.hooksPath=/dev/null 并设 GIT_CONFIG_NOSYSTEM=1,或改为直接解析 .git/config 与 refs,并补一条「仓库配置了 fsmonitor 不会被执行」的测试。

  5. 与其他打开的 PR 冲突:#946 修改工作区组合 diff(平台和 runner 两侧),#938 / #941 修改聊天工作区变更面板,与本 PR 重写的 assistant_workspace*.go 和 runner workspace 有重叠。这些小修复已获批且范围小,建议先合入它们,本 PR 再 rebase。

未看全的文件:internal/httpapi/*、internal/repo/*、internal/runner/*、internal/runtime/* 的 patch 均被省略(包括 assistant_native_external.go、assistant_workspace_open.go、assistant_workspace_mr.go、sandbox_process.go、conversation_sandbox.go),chatbot/src/NativeApprovalPanel.jsx、internal/gitwork/ssh.go 和两份 docs 也被截断;以上意见根据可见部分和 PR 描述得出。

@crispinhu27

Copy link
Copy Markdown
Collaborator Author

个人Token问题将在之后的Git处理相关PR进行处理;不考虑存量用法,上个版本为rc版本;帮我批准行为确定存在问题

crispinhu27 and others added 2 commits November 16, 2026 09:28
In assisted mode a native external write (git push, gh pr ...) fell back
to the speaker's approval card whenever the reviewer refused or did not
answer within 15 seconds. The reviewer itself has a 60-second budget and
a CLI cold start rarely fits in 15 seconds, so the mode mostly turned
into a manual confirmation.

The hook now starts the review in the background on its first poll and
answers pending until the verdict is in; each hook request waits at most
10 seconds, below its 20-second request timeout. The same invocation is
reviewed once. An allowed review runs the command; a refused, failed or
timed-out review denies it with the reason and never creates a
native-approvals card. Request-approval mode keeps the card.

Docs, design.md and the approval picker describe the new behavior.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Checkouts runs git with safe.directory=* on the platform or runner host
against repositories the sandbox user controls. Their config could then
make the host run programs (core.fsmonitor, hooks, pager, askpass,
credential helpers).

The scan now pins the repository to <dir>/.git, ignores the system
config, clears the keys git executes, reads only the local config
without includes, and skips a .git file or symlink that could point
outside the workspace. A test configures all of those keys and checks
none of them runs.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@crispinhu27

Copy link
Copy Markdown
Collaborator Author

17:00 轮:按作者 08:54 / 09:07 评论和 Yanami-2K 09:04 复审修复(head 7a98714)

改动

ee32bf4 fix(assistant): 帮我批准只出批准或拒绝(Yanami 第 3 条、Robert0622 建议 1、作者 08:54 评论)

  • 原先审查只给 15 秒(审查器自身预算 60 秒),审查拒绝或超时都会转成「批准外部写入」人工卡片。
  • 现在 hook 第一次轮询时平台在后台启动审查,单次 hook 请求最多等 10 秒(低于 hook 20 秒请求超时),没出结果返回 pending 继续轮询;同一调用只审查一次,换输入复用调用 ID 会被拒绝。
  • 审查通过 → 执行;审查拒绝 / 不可用 / 超时 → 直接拒绝并把原因返回给 Agent(「操作未执行,不要换一种方式重试」),不创建 native-approvals 卡片。「请求批准」模式的卡片不变。
  • 同步更新 docs/conversation-native-cli.md、design.md、审批模式选择器说明文案;状态文本「帮我批准:待确认」改为「未通过 / 审查不可用」。
  • 测试:TestWorkspaceExternalWritesFollowApprovalMode 补上「帮我批准 + 审查拒绝 / 审查不可用 → 拒绝且 0 张卡片」、重复轮询不重复审查、调用 ID 复用不同输入被拒;新增 TestAssistedNativeReviewOutlivesOneHookRequest(审查慢于一次 hook 请求时先 pending、下一次轮询读到结果)。

7a98714 fix(gitwork): 扫描沙箱 checkout 不执行其配置(Yanami 第 4 条)

  • Checkouts 改用 --git-dir=<dir>/.git,并传 -c core.fsmonitor= -c core.hooksPath=/dev/null -c core.pager=cat -c core.askPass= -c credential.helper=、GIT_CONFIG_NOSYSTEM=1;读 remote 用 config --local --no-includes;只认真实的 .git 目录,.git 文件/软链(可指向工作区外仓库)跳过。
  • 新增 TestCheckoutsDoesNotRunRepositoryConfiguredPrograms:仓库配置 fsmonitor/hooksPath/pager/askPass/credential.helper 都指向写标记的脚本,扫描后标记不存在;在旧实现上这条测试失败(会把 .git 文件指向的工作区外仓库扫进来)。

其他复审意见

本地验证

  • go build ./...、go vet ./... 通过;go test -race ./internal/httpapi -run 'Native|ExternalWrites|Approval|WorkspaceNative' 通过;internal/gitwork、internal/repo、internal/engine、cmd/agentflow 全部通过。internal/httpapi 全量里 TestMainBotBrowserStartsAndDrivesRunBrowser、TestBrowserStreamPushesFramesAndRunsCommands 和 internal/runner 的 TestRunnerStartsPanelBrowserInRunSandbox 失败,未改动的 main 在同一容器同样失败(容器里没有可用的 Chromium 沙箱)。
  • chatbot npm run build + vitest 370/370;scan-secrets.sh no leaks。
  • 部署:MySQL 8.4.7 + 本分支 agentflow(role all),/api/health 200,日志无 panic。CLI 用替身 CodeBuddy(真实走平台 MCP 网关、--settings 里的 PreToolUse hook 脚本和审查器调用),审查器替身固定 25 秒出结果(超过旧的 15 秒上限和单次 hook 请求 20 秒);native 沙箱用只做 chdir 的 bwrap 替身(容器不支持用户命名空间),没有验证真实隔离。
场景(Chrome CDP 操作 chatbot) 结果
帮我批准 + 审查 25 秒后批准 hook 等 25.1 秒后 allow,原因「用户明确要求推送该分支」,0 张卡片
帮我批准 + 审查拒绝 deny,原因带审查理由,GET native-approvals 为 []
帮我批准 + 审查不可用(超时) 30.1 秒后 deny「自动审查暂不可用,已拒绝本次外部写入」,0 张卡片
请求批准(回归) 出现「批准外部写入:git push」卡片,点「批准本次操作」后 allow

截图:

审批模式说明 帮我批准:审查通过
picker allow
帮我批准:审查拒绝 请求批准:卡片仍在
deny card

CI(7a98714)

全部通过:browser、core、curl-install、e2e(4 组)、e2e-browser、e2e-required、first-run、platform-required、secrets、tcmcp、validate 3.8、validate 3.12。

仍需

  • Yanami-2K 复审(当前 CHANGES_REQUESTED);Robert0622 的 Approve 在新推送后需要重新确认。

Robert0622
Robert0622 previously approved these changes Nov 16, 2026

@Robert0622 Robert0622 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.

二次复审通过 ✅(head 7a987149)

上轮的问题都已处理:

  • 帮我批准:改为后台审查,结论只有允许或拒绝,不再弹卡;审查不可用或超时一律拒绝。
  • checkout 扫描加固:改用 --git-dir、GIT_CONFIG_NOSYSTEM,禁用可执行的配置项,跳过 .git 软链接和文件。

验证情况:

  • CI 15/15 通过。
  • internal/httpapi、internal/gitwork 相关用例加 -race 通过;chatbot vitest 370/370 通过。
  • 本地部署实测(native bwrap 沙箱 + 本地 git http 远端,模型 deepseek-v4.1-flash):
    • 帮我批准、操作正常:约 10s 自动放行,没有卡片,push 成功。
    • 帮我批准、审查模型不可用:拒绝外部写入,没有卡片,远端没有新分支,agent 如实告知用户原因。
    • 请求批准:照常弹卡,批准后 push 成功。

非阻塞的小问题:审查不可用时,状态栏文案仍是平台草稿那套"请手动确认后执行",和"已拒绝"不太一致,后续可以顺手改一下。

…dbox

# Conflicts:
#	internal/runtime/sandbox_process.go

@Robert0622 Robert0622 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.

合并 main 解决冲突之后复核通过,重新 approve ✅(head 2015e47a)

  • 冲突只出现在 internal/runtime/sandbox_process.go:保留了本 PR 的 conversation guard 规则和 bwrapChdir,按 #953 去掉了 agent 配置屏蔽(maskAgentConfig、discoverProjectAgentPaths),处理得没问题,也没有残留冲突标记。
  • 本地验证:go build ./...、go vet 通过。internal/gitwork 加 -race 通过,internal/httpapi 通过,internal/runtime 不加 -race 通过,chatbot vitest 370/370 通过。
  • internal/runtime 加 -race 时 TestDevServerPipeScriptRelaysHTTP 会报 data race,但 main(c1fa0f7b)上也一样复现,本 PR 没改相关文件,跟本 PR 无关。
  • CI 15/15 通过。

@crispinhu27
crispinhu27 merged commit 777f16a into main Nov 16, 2026
15 checks passed
@crispinhu27
crispinhu27 deleted the feat/workspace-by-sandbox branch November 16, 2026 11:25
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.

3 participants