Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue or RFC does this PR close?
Closes #2879.
Implements RFC
2988-shared-workspace-scope-bindings.Rationale for this change
Today, each workspace-aware host integration binds and resolves workspace Scopes under its own
integrationname (claude-code,codex,opencode,pi,dsh,workbuddy,zcode,kimi-code,hermes,bub), and derives workspace paths using three incompatible rules (git root + realpath,cwd + realpath, andcwd + path.resolve). Binding a repository checkout to a project Scope in one host leaves every other host on the same machine falling back to the Server default Scope (O(repositories × hosts)manual bindings).In line with
RFC 1345(opaque Server-ownedscope_ids, never derived from paths or Git remotes), this PR introduces a canonical cross-host workspace binding under the reserved integration namesharedwith zero Server schema, HTTP API, or persistence table changes.What changes are included in this PR?
This Draft PR is organized in layered commits (bilingual RFC -> shared Python/TS lifecycle + CLI -> host integrations + cross-host E2E -> cross-platform identity, routing cache & CLI refinement) so the RFC can also be reviewed independently if preferred:
docs/{en,zh}/rfcs/2988-shared-workspace-scope-bindings.md) & manifest guard (scripts/integration_manifest.py):sharedinscripts/integration_manifest.pyso host manifests cannot claim it.src/powercontext_integration_lifecycle/,integrations/lifecycle/git-worktree.ts):sha256(utf8(canonical_root))for existing directories from the single existinggit rev-parsecall: aligns Python on macOS (fcntl.F_GETPATH) with Node.jsfs.realpathSync.nativeacross case-insensitive APFS and NFD/NFC paths, strips Windows\\?\/\\?\UNC\prefixes with uppercase drive letters, decodes Git stdout explicitly as UTF-8 (surrogateescape), skips spawninggitwhencwdis missing, and guards against$HOME/%USERPROFILE%(os.path.expanduser("~")/os.homedir()) and filesystem roots (_guarded_git_top/guardedGitTop).HostProfile.legacy_workspace_binding = Falseby default so newly added hosts emit onlyshared:workspace, while explicitly enablinglegacy_workspace_binding = TrueforCLAUDE_CODEandCODEXand preserving byte-for-byte frozen legacy<host>:workspacederivations across existing workspace hosts.diagnose_scope_bindingreportingmatched_key, synced across generated copies viascripts/generate_integration_lifecycle.py.claude-code,codex,workbuddy,hermes,bub,dsh(with per-cwdcached routing metadata and rebuiltintegrations/dsh/plugins/powercontext/lib/),opencode(with rebuiltlib/),pi,kimi-code(preservingunknownstatus on partial multi-key unbind failures), andzcode(same partial-unbindunknownguard): binding writesshared:workspace, resolution queriessession -> shared (own) -> legacy host (own) -> shared (main worktree) -> legacy host (main worktree) -> default, clearing removes bothsharedand the host's legacy key, and host diagnostics (--diagnose,doctor.ts,doctor.mjs) surfacematched_key.powercontext scope resolve(supporting--integration sharedand all 10 workspace hosts), adds--cwdtopowercontext scope binding set(validating existing directories and rejecting non-shared--integration) andclear(requiring an existing directory and clearingsharedby default, orsharedplus<host>when--integration <host>is given), and updatespowercontext import-sessions(session_import.py).docs/{en,zh}/docs/integrations/,tests/):$HOME/%USERPROFILE%guard, and Windows path vectors) intests/test_git_worktree.py, CLI--cwd/--helptests intests/test_cli_scope.py, and real-Server + SQLite 10-host end-to-end tests intests/e2e/test_shared_workspace_scope_binding.py.Are there any user-facing changes?
powercontext scope binding set <SCOPE_ID> --cwd <DIR>writes a canonicalshared:workspacebinding that applies across every workspace-aware host opening the same checkout (including subdirectories, symlinks, and linked Git worktrees without their own override). Active sessions that pin their Scope at startup (such as Codex and OpenCode) keep their current session Scope until a new session starts.<host>:workspacebindings continue resolving without manual migration until superseded by ashared:workspacebinding or cleared via host unbind /powercontext scope binding clear --cwd <DIR> --integration <HOST>(note: on non-UTF-8 Windows code pages such ascp936, Python's Git helper now decodesgit rev-parseoutput as UTF-8 instead of ANSI, so a pre-upgrade binding created from a mojibake non-ASCII Git path requires rebinding once).--diagnosein Claude Code / Codex / WorkBuddy, anddoctorin DSH, Kimi Code, and ZCode) reportmatched_key.How was this change tested?
tychecks (verified locally on macOS arm64; macOSfcntl.F_GETPATHAPFS case and NFD/NFC parity is verified locally on macOS, while automated CI exercises Linux andwindows-latestonce out of Draft):make check(All checks passed!,62 passed)make contract-test(69 passed)make harness-lint(All checks passed!)uv run python -m pytest -n auto tests/test_git_worktree.py tests/test_cli_scope.py tests/test_session_import.py tests/claude_code_plugin tests/codex_plugin tests/workbuddy_plugin tests/integrations tests/test_integration_manifest.py tests/test_cli_zcode.py tests/test_cli_workbuddy.py tests/e2e/test_shared_workspace_scope_binding.py tests/e2e/test_codex_service_chain.py tests/e2e/test_zcode_service_chain.py tests/e2e/test_bub_service_chain.py -q(1197 passed, 11 skipped)pnpm --dir integrations/dsh/plugins/powercontext test(31 files, 1209 passed) andnode --test integrations/dsh/plugins/dsh-pet/tests/adapter.test.mjs integrations/dsh/plugins/dsh-pet/tests/package.test.mjs(5 passed)pnpm --dir integrations/opencode/plugins/powercontext test && pnpm --dir integrations/opencode/plugins/powercontext run typecheck(11 files, 175 passed)pnpm --dir integrations/pi/plugins/powercontext test && pnpm --dir integrations/pi/plugins/powercontext run typecheck(18 files, 232 passed)node --test integrations/zcode/plugins/powercontext/tests/*.test.mjs(116 passed, 1 skipped, 0 failed)node --test --test-name-pattern="workspace|scope|doctor|worktree|binding|unbind" integrations/kimi-code/plugins/powercontext/tests/plugin.test.mjs(8 passed, 0 failed)AI usage statement
Built, reviewed, and verified with assistance from Antigravity (Gemini) and Claude Code.
中文说明
本 PR 关联或关闭哪个 Issue / RFC?
Closes #2879。
实现 RFC
2988-shared-workspace-scope-bindings。变更背景与原因
当前各工作区感知宿主集成在绑定与解析工作区 Scope 时均各自使用独立的
integration名称(claude-code、codex、opencode、pi、dsh、workbuddy、zcode、kimi-code、hermes、bub),且工作区路径派生分成三套互不兼容的规则(Git 根目录 + realpath、cwd + realpath、cwd + path.resolve)。用户在任一宿主中将仓库检出绑定到项目 Scope 后,同一台机器上的其他宿主打开同一目录仍会回退到 Server 默认 Scope(手工维护成本为O(仓库数 × 宿主数))。遵循
RFC 1345(scope_id由 Server 拥有且保持不透明,绝不从路径或 Git 远端地址自动派生),本 PR 在零 Server Schema、零 HTTP API、零持久化表结构改动的前提下,使用保留集成名shared引入跨宿主规范工作区绑定。本 PR 包含哪些变更?
本 Draft PR 采用分层提交组织(中英文双语 RFC -> Python/TS 共享生命周期与 CLI -> 各宿主集成与跨宿主 E2E -> 跨平台路径归一、路由缓存与 CLI 精简收敛),便于按需先独立审阅 RFC:
docs/{en,zh}/rfcs/2988-shared-workspace-scope-bindings.md)与能力清单校验(scripts/integration_manifest.py):scripts/integration_manifest.py中保留shared,防止宿主清单占用该名称。src/powercontext_integration_lifecycle/、integrations/lifecycle/git-worktree.ts):git rev-parse调用对已存在目录计算sha256(utf8(canonical_root)):在 macOS 上通过fcntl.F_GETPATH使 Python 与 Node.jsfs.realpathSync.native在大小写不敏感 APFS 及 NFD/NFC 路径上逐字节一致,在 Windows 上统一剥离\\?\与\\?\UNC\前缀并大写盘符,Git 标准输出显式按 UTF-8(surrogateescape)解码,目录不存在时直接跳过git子进程派生,并按os.path.expanduser("~")/os.homedir()一致拦截$HOME/%USERPROFILE%及文件系统根目录(_guarded_git_top/guardedGitTop)。HostProfile.legacy_workspace_binding默认值设为False,使后续新接入宿主仅发送shared:workspace;仅对CLAUDE_CODE与CODEX显式设为True,并在存量工作区宿主中逐字节冻结原有的<host>:workspace派生逻辑。diagnose_scope_binding输出matched_key,并通过scripts/generate_integration_lifecycle.py同步生成副本。claude-code、codex、workbuddy、hermes、bub、dsh(按cwd缓存共享路由元数据并重编integrations/dsh/plugins/powercontext/lib/)、opencode(含重编lib/)、pi、kimi-code(多键解绑部分失败时保留unknown状态)与zcode(同上保留部分解绑unknown状态):绑定只写shared:workspace,解析按session -> shared(当前检出)-> legacy host(当前检出)-> shared(主检出)-> legacy host(主检出)-> default顺序查询,清除时一并移除shared与当前宿主旧键,且诊断入口(--diagnose、doctor.ts、doctor.mjs)统一展示matched_key。powercontext scope resolve(支持--integration shared及全部 10 个工作区宿主),为powercontext scope binding set(校验目录存在并拒绝非shared的--integration)与clear(校验目录存在,默认清除shared,指定--integration <host>时同时清除shared与<host>)新增--cwd选项,并同步更新powercontext import-sessions(session_import.py)。docs/{en,zh}/docs/integrations/、tests/):tests/test_git_worktree.py新增 Python × Node.js 一致性测试(覆盖 APFS 大小写偏差、NFC/NFD、软链、Windows 目录联接junction、$HOME/%USERPROFILE%守卫与 Windows 路径向量),在tests/test_cli_scope.py新增--cwd/--help测试,并在tests/e2e/test_shared_workspace_scope_binding.py新增覆盖全部 10 个宿主的真实 Server + SQLite 端到端测试。是否存在用户可见变更?
powercontext scope binding set <SCOPE_ID> --cwd <DIR>,均会写入规范shared:workspace绑定,并在打开同一检出目录的所有工作区宿主(含子目录、软链及未单独覆盖绑定的关联 Git Worktree)中自动共享生效。启动时固定会话 Scope 的宿主(如 Codex 与 OpenCode)在已开启会话中保持原会话 Scope,新开会话采用新的工作区绑定。<host>:workspace绑定无需手工迁移即可继续回退生效,直至被新的shared:workspace绑定覆盖,或通过宿主解绑 /powercontext scope binding clear --cwd <DIR> --integration <HOST>清除(注:在非 UTF-8 代码页如cp936的 Windows 上,Python 的 Git 辅助函数现按 UTF-8 而非系统 ANSI 解码git rev-parse输出,此前由非 ASCII 乱码路径建立的旧绑定重新绑定一次即可)。--diagnose,以及 DSH、Kimi Code、ZCode 的doctor)新增展示matched_key。测试与验证情况
ty类型检查(本机 macOS arm64 实测;macOSfcntl.F_GETPATH的 APFS 大小写与 NFD/NFC 一致性已在 macOS 本机验证,CI 在脱离 Draft 后自动覆盖 Linux 与windows-latest):make check(All checks passed!,62 passed)make contract-test(69 passed)make harness-lint(All checks passed!)uv run python -m pytest -n auto tests/test_git_worktree.py tests/test_cli_scope.py tests/test_session_import.py tests/claude_code_plugin tests/codex_plugin tests/workbuddy_plugin tests/integrations tests/test_integration_manifest.py tests/test_cli_zcode.py tests/test_cli_workbuddy.py tests/e2e/test_shared_workspace_scope_binding.py tests/e2e/test_codex_service_chain.py tests/e2e/test_zcode_service_chain.py tests/e2e/test_bub_service_chain.py -q(1197 passed, 11 skipped)pnpm --dir integrations/dsh/plugins/powercontext test(31 files, 1209 passed)及node --test integrations/dsh/plugins/dsh-pet/tests/adapter.test.mjs integrations/dsh/plugins/dsh-pet/tests/package.test.mjs(5 passed)pnpm --dir integrations/opencode/plugins/powercontext test && pnpm --dir integrations/opencode/plugins/powercontext run typecheck(11 files, 175 passed)pnpm --dir integrations/pi/plugins/powercontext test && pnpm --dir integrations/pi/plugins/powercontext run typecheck(18 files, 232 passed)node --test integrations/zcode/plugins/powercontext/tests/*.test.mjs(116 passed, 1 skipped, 0 failed)node --test --test-name-pattern="workspace|scope|doctor|worktree|binding|unbind" integrations/kimi-code/plugins/powercontext/tests/plugin.test.mjs(8 passed, 0 failed)AI 使用声明
本 PR 在 Antigravity(Gemini)与 Claude Code 辅助下完成实现、审查与验证。