Repository navigation
Conversation
hidb4ai
left a comment
There was a problem hiding this comment.
Reviewed aef8a44 and its merge with master d896b79. The shared-before-legacy lookup and dual-key clearing design are reasonable; no new database tables or Server API contract. Linux validation: 91 path/CLI/import/cross-host tests and 513 host tests passed; the real HTTP Server cross-host test also passed on the merged result. Node suites had one Kimi preparation failure (plus its parent), which did not reproduce in a focused rerun (77 passed). I have not established native Windows/macOS path parity or installed-host acceptance, and all 45 current CI checks are skipped while this remains a draft. Merge-readiness score: 58/100; holding approval pending that validation. Added CLI/interfaces are not the reason for withholding approval.
|
Thanks for the review! Keeping this PR in Draft for now while we run additional local and cross-platform (macOS/Windows) verification on installed hosts. We will mark it Ready for Review once validation is complete. 中文说明感谢评审!本 PR 目前暂时保持 Draft 状态,我们还会继续在本地及跨平台(macOS/Windows)已安装宿主环境补充实测。待全部验证完成后,再转为 Ready for Review 请大家重新评审。 |
|
The affected modules are Core. @hidb4ai, please coordinate follow-up. Core: @hidb4ai @frf12 @Fengzdadi @beatenevo. Please coordinate the review of the affected changes. |
|
@hidb4ai @frf12 @Fengzdadi @beatenevo Additional local multi-host and linked-worktree validation is complete. This PR is now marked Ready for Review at Additional Validation Completed
Please review when convenient! 中文说明@hidb4ai @frf12 @Fengzdadi @beatenevo 本机多宿主与关联 Git worktree 补充验证已完成,现将本 PR 在 补充验证结果
烦请方便时复审! |
frf12
left a comment
There was a problem hiding this comment.
Reviewed aef8a4437. The four inline comments describe reproduced binding/compatibility failures that need correction. Baseline comparisons used merge base 07f419041; the relevant implementation and fixture files are unchanged in current master eb0a35498.
CI also needs reconciliation: run 47307336643 fails the Python 3.11–3.14 unit jobs, with the 3.11 job reporting 100 failures concentrated in Hook request expectations. I independently ran test_hook_keeps_its_characterized_behavior[claude-code:session-start-without-bootstrap]: it passes on the baseline and fails on this head because the expected request omits the new shared key. Please update and review the affected fixtures for the intended behavior, then complete the skipped host and Windows checks.
Verification boundaries are stated in each finding; these reproductions do not establish installed-host or native Windows acceptance.
| if real_workspace_path(str(cwd)) is None: | ||
| raise typer.BadParameter("Workspace directory does not exist.", param_hint="--cwd") # noqa: TRY003 | ||
| shared_root, _host_path = workspace_locations(str(cwd), git_root=True)[0] | ||
| shared_id = workspace_identity(shared_root) |
There was a problem hiding this comment.
[P2] Expand the directory before discovering its Git root
For an existing Git repository ~/pc-review with a src subdirectory, bind an existing Scope with powercontext scope binding set <SCOPE_ID> --cwd '~/pc-review/src', then run powercontext scope resolve --integration codex --cwd "$HOME/pc-review/src" against the same Server. I reproduced a successful bind followed by resolution to the default Scope using the real CLI command and HTTP Server/SQLite; resolving with the literal tilde path instead finds the newly bound Scope.
The existence check expands ~, but workspace_locations receives the unexpanded string, skips Git discovery, and ultimately hashes the subdirectory. Normal absolute-path callers hash the repository root instead. Please normalize supported home-relative input before Git discovery so the accepted binding is readable through the normal host path. Master has no binding set --cwd option; this is a defect in the newly accepted input form, rather than a previously working command.
|
|
||
| export function workspaceBindingKey(cwd: string): ScopeBindingKey { | ||
| export function sharedWorkspaceBindingKey(cwd: string): ScopeBindingKey | undefined { | ||
| if (!sharedKeys.has(cwd)) { |
There was a problem hiding this comment.
[P2] Keep the advertised workspace key consistent with resolution
Start in a non-Git /project/packages/api, resolve the Scope and format its routing metadata, then run git init /project. The next resolution queries the shared key for /project, but this cwd-only cache still advertises the old shared key for packages/api. Saving a binding with that advertised key succeeds, yet subsequent resolution does not query it and continues returning the default Scope.
I reproduced this with real temporary directories/Git and the actual base/head resolver and formatter, using an in-memory binding map for the Server: master reads the advertised binding, while this head misses it. The actual caller refreshes resolution each turn, so the metadata needs to track the keys used by that resolution as well. Please refresh or invalidate the cached key when the effective workspace identity changes. This was a direct integration-code reproduction, not a live DSH session.
| if top is None: | ||
| return [(shared_own, host_own)] |
There was a problem hiding this comment.
[P2] Preserve legacy main-checkout candidates when the shared HOME guard applies
Use a linked worktree as the process's home directory, start in $HOME/sub, and retain only a pre-upgrade host binding for the main checkout. In an isolated real-Git layout, the master helper returns both the worktree and main-checkout paths; this head returns only the worktree path. The result is the same in Python and Node, including the cwd-keyed variants (Worktree/sub, Checkout/sub on master versus only Worktree/sub here).
The HOME guard makes top empty, and this return also drops the legacy fallback, so the existing main-checkout binding is no longer queried and resolution can fall back to Default. Please preserve the previous legacy candidates independently of the guard for shared identities, as the RFC's compatibility contract requires. The equivalent early returns in the TypeScript helper have the same behavior. Verification exercised the real helpers and Git layout, not a live host.
| function realPath(path: string): string { | ||
| try { | ||
| return realpathSync(path) | ||
| return realpathSync.native(path) |
There was a problem hiding this comment.
[P2] Preserve the pre-RFC path spelling for legacy worktree fallbacks
On a case-insensitive macOS filesystem, create a main checkout named Checkout, add a linked Worktree, and save a legacy Pi/DSH/OpenCode binding for Checkout/sub. Rename the main directory to checkout (a temporary intermediate name can make the case-only rename explicit). Git's existing worktree pointer remains valid and still spells Checkout.
I reproduced this with real macOS directories, Git, and the original base/head helpers, without editing Git's internal files: master returns Checkout/sub as the fallback, but this head returns checkout/sub. Those hosts hash the returned spelling, so the legacy binding that master still finds is no longer queried. The Python helper retains the old spelling. Please keep legacy fallback derivation unchanged while applying OS-canonical paths to the new shared identity. The RFC explicitly promises byte-for-byte legacy compatibility; this reproduction covers path/key derivation, not complete host acceptance.
…DSH cache, and refresh hook fixtures
|
@frf12 Thank you for the thorough review and exact reproductions! All four P2 findings and the hook characterization fixtures are fixed in Summary of Fixes (
|
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 辅助下完成实现、审查与验证。