feat(integrations): use host-independent workspace Scope binding keys across hosts #2879
Description
Feature description
Allow a single workspace-to-Scope binding to apply across all PowerContext host integrations (Claude Code, Codex, OpenCode, Pi, DSH, WorkBuddy, Kimi Code, ZCode, Hermes, and Antigravity in #2871) when working on the same repository checkout, instead of keying durable workspace bindings by host integration.
Problem and proposed solution
Problem
Today, host plugins include integration inside the workspace binding key when calling /v1/scope-bindings/resolve and /v1/scope-bindings:
- In
src/powercontext_integration_lifecycle/scope_binding.py:170-174(and the generated copies in Claude Code, Codex, and Antigravity),workspace_binding_key()produces:
{"integration": host.integration, "kind": "workspace", "external_id": external_id} - Equivalent host integrations follow the same per-integration pattern, including
integrations/opencode/plugins/powercontext/src/scope.ts,integrations/dsh/plugins/powercontext/src/scope.ts,integrations/pi/plugins/powercontext/src/scope.ts,integrations/kimi-code/plugins/powercontext/shared/runtime.mjs,integrations/workbuddy/plugins/powercontext/scripts/workspace_scope.py, andintegrations/hermes/plugins/powercontext/provider.py.
Because integration is part of the key:
- If a user creates a dedicated Scope for Repository A and binds it in Codex (
("codex", "workspace", <sha256>)), opening the exact same checkout in Claude Code or Antigravity sends("claude-code", "workspace", <sha256>)or("antigravity", "workspace", <sha256>), misses the binding, and silently falls back to the Server'sDefaultScope (allow_default=True). - Switching hosts on the same repository loses recall from the repository Scope and writes new Sources/Artifacts into
Defaultinstead, splitting repository context across Scopes and forcingO(repos × hosts)manual re-binding. - Note that this is not asking to derive
scope_idautomatically from directory paths (RFC 1345 deliberately forbids path-derived Scopes). It is specifically about sharing the explicitly bound workspace lookup key across hosts on the same checkout.
This directly aligns with #2250 (which marked "Changing how workspace keys are derived" as a Non-goal for follow-up) and complements #2868 / #2875 (which resolves linked Git worktrees to the main checkout path within a single host, while still keeping host.integration in the binding key).
Proposed solution
- Host-independent workspace binding key namespace: Introduce a shared workspace binding key identity (decoupled from
host.integration) as an RFC follow-up to RFC 1345, while preserving the invariant that workspace keys remain lookup inputs only and never generatescope_id. Pair cleanly with bug(integrations): a bound checkout's Scope does not apply in its linked Git worktrees #2868's canonical checkout identity so linked worktrees across any host resolve to the same Scope. - Backward-compatible resolution precedence: Update
binding_keys()//v1/scope-bindings/resolvelookup order with deterministic precedence — for example:explicit_scope_id->sessionbinding -> optional host-specific workspace override (if present) -> host-independent shared workspace binding -> legacy per-host workspace binding -> configureddefault_scope_id(preserving409 scope_binding_target_missingstop-on-conflict invariants). - One-shot binding CLI / helper: Update
powercontext scopeand hostscope_binding.py --bind-scopeflows so binding a repository once covers every installed PowerContext host integration on that machine (unless an operator explicitly requests a host-scoped override).
Alternatives considered
- Manually bind every repository across every installed host (
O(repos × hosts)): High maintenance friction and error-prone whenever a user adds a new host or forgets one binding, causing silent fallback toDefaultand cross-repo/split-brain contamination. - Set
POWERCONTEXT_<HOST>_SCOPE_IDenvironment variables: Overrides workspace bindings globally across all repositories rather than per checkout, unless wrapped in external directory tools likedirenv.
Additional context
-
RFC alignment: Respects RFC 1345 (
docs/en/rfcs/1345_scope_organization_and_agent_integration.md) — Scopes remain Server-issued opaque IDs created explicitly when isolation is needed; only the lookup binding key becomes host-independent. -
Related issues & PRs: feat(integrations): keep host plugins thin and make them work behind the gateway #2250, bug(integrations): a bound checkout's Scope does not apply in its linked Git worktrees #2868, fix(integrations): resolve linked Git worktrees to their main checkout's workspace binding #2875, feat(integrations): add Antigravity (AGY) host plugin support #2871.
-
Yes, I am willing to contribute code, docs, or design feedback.
中文说明
功能描述
支持将同一仓库目录的工作区 Scope 绑定共享给所有 PowerContext 宿主集成(包括 Claude Code、Codex、OpenCode、Pi、DSH、WorkBuddy、Kimi Code、ZCode、Hermes 以及 #2871 中的 Antigravity),而不再按宿主 integration 名称分别隔离工作区绑定键。
问题背景与建议方案
问题描述
目前各宿主插件在调用 /v1/scope-bindings/resolve 与 /v1/scope-bindings 时,都会把客户端名称 integration 写进 workspace 绑定键:
- 在
src/powercontext_integration_lifecycle/scope_binding.py:170-174(以及生成同步到 Claude Code、Codex、Antigravity 的副本)中,workspace_binding_key()构造的是:
{"integration": host.integration, "kind": "workspace", "external_id": external_id} - 其他宿主实现也沿用了同样按宿主隔离的模式,包括
integrations/opencode/plugins/powercontext/src/scope.ts、integrations/dsh/plugins/powercontext/src/scope.ts、integrations/pi/plugins/powercontext/src/scope.ts、integrations/kimi-code/plugins/powercontext/shared/runtime.mjs、integrations/workbuddy/plugins/powercontext/scripts/workspace_scope.py与integrations/hermes/plugins/powercontext/provider.py。
由于绑定键耦合了 integration 字段,会产生以下实际痛点:
- 用户为仓库 A 新建独立 Scope 并在 Codex 中完成绑定(
("codex", "workspace", <sha256>))后,若改用 Claude Code 或 Antigravity 打开同一本地仓库,发出的键变成("claude-code", "workspace", <sha256>)或("antigravity", "workspace", <sha256>),服务端查不到绑定,会静默回落到全局DefaultScope(allow_default=True)。 - 在同一仓库切换不同宿主工作时,不仅无法召回原仓库 Scope 的历史记忆,新捕获的 Source/Artifact 还会写入
Default,造成同一项目记忆被拆散且需要按O(仓库数 × 宿主数)重复手工绑定。 - 需要明确的是,本提案并不要求按目录路径自动创建或派生
scope_id(RFC 1345 已明确禁止路径派生 Scope),而是希望在用户显式完成「仓库 -> Scope」绑定后,工作区查询键能跨宿主通用。
这与 #2250(在其 Non-goals 中单独列出后续再改 workspace key 派生方式)精准衔接,并与 #2868 / #2875(解决同一宿主下 linked Git worktree 找不到主仓库绑定的问题,但仍保留 host.integration 隔离)形成互补。
建议方案
- 定义与宿主无关的工作区绑定键命名空间:作为 RFC 1345 的后续扩展 RFC,引入不绑定
host.integration的共享工作区绑定键;同时继续严格保持「工作区键仅作查询输入、绝不派生scope_id」的设计不变量,并与 bug(integrations): a bound checkout's Scope does not apply in its linked Git worktrees #2868 的主仓库规范路径标识协同,使多宿主与 linked worktree 打开同一仓库都能命中同一 Scope。 - 向后兼容的解析优先级:在
binding_keys()与/v1/scope-bindings/resolve中保留清晰可预期的回退顺序,例如:explicit_scope_id->session绑定 -> 可选的单宿主显式覆盖绑定(如有) -> 与宿主无关的共享工作区绑定 -> 遗留的单宿主工作区绑定 ->default_scope_id(同时继续严格遵守409 scope_binding_target_missing遇损即停不回退的不变量)。 - 一次绑定多端生效的 CLI 与辅助脚本:更新
powercontext scope与插件自带scope_binding.py --bind-scope,让用户在同一仓库执行一次绑定即可覆盖本机全部已安装宿主(除非运维明确需要为特定宿主单独覆盖)。
备选方案考虑
- 在每个已安装宿主上重复绑定同一批仓库(
O(仓库数 × 宿主数)):维护成本随宿主数量线性增长,新增或漏绑一个客户端就会静默掉回Default,导致跨项目串库与记忆分裂。 - 设置
POWERCONTEXT_<HOST>_SCOPE_ID环境变量:属于进程/全局级覆盖,无法按本地不同仓库自动区分,除非额外依赖direnv等外部工具按目录切换环境变量。
补充上下文
-
与 RFC 1345 对齐:完全遵循
docs/en/rfcs/1345_scope_organization_and_agent_integration.md,Scope 仍由 Server 生成不透明 ID 并由用户按需显式创建,仅将工作区查询绑定键从「按宿主分开」调整为「跨宿主共享」。 -
关联 Issue 与 PR:feat(integrations): keep host plugins thin and make them work behind the gateway #2250、bug(integrations): a bound checkout's Scope does not apply in its linked Git worktrees #2868、fix(integrations): resolve linked Git worktrees to their main checkout's workspace binding #2875、feat(integrations): add Antigravity (AGY) host plugin support #2871。
-
Yes, I am willing to contribute code, docs, or design feedback.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsIn progress
Activity
wycocoyu commentedon Nov 27, 2026
This issue is pending evaluation.
中文说明
这个 issue 待评估。
Fengzdadi commentedon Nov 27, 2026
@wycocoyu The problem is real, and the direction is right. The key has carried
integrationsince Scope bindings were first implemented (#1401), so this is a gap in the original design and not a regression. Here is a design that closes it. It needs no Server, API, or storage change. I checked it againstmasterat 389c440.One correction first: dropping
integrationis not enoughThe issue assumes every host computes the same
<sha256>for a checkout. They do not:path.resolve)Codex and Claude Code already agree. Codex and Pi agree only when Pi starts at the repository root through a path without symbolic links. On macOS with Git 2.50.1, I hashed one checkout three ways: the Git top level,
path.resolveof the same checkout reached through a symbolic link, andpath.resolveof a subdirectory. The three IDs differ.So the work has two parts: one identity rule that every host computes, and a shared namespace for it.
1. One workspace identity
2. A shared key beside the host's own key
{"integration": "shared", "kind": "workspace", "external_id": "<id>"}ScopeBindingKey.integrationis a free string, andPOST /v1/scope-bindings/resolvetriesbinding_keysin order and returns the first key that has a binding. A host therefore sends the shared key in the list it already sends. #2875 uses the same mechanism for linked worktrees.sharedbecomes a reserved name that no host may use as its ID.3. Resolution order
The request stays a single call with at most five keys, and the Server makes one lookup per key until the first match. Because the Server is unchanged, a binding whose target is missing still stops resolution with
409 scope_binding_target_missing.The issue lists "host-specific override" and "legacy per-host binding" as two levels. They are the same stored key,
(codex, workspace, <id>), so the Server cannot tell them apart and they take one position. I put that position after the shared key for the reason above. A host that must use a different Scope sets its explicit Scope setting, for examplePOWERCONTEXT_CODEX_SCOPE_ID, which is first in the order. If a per-host override for one checkout turns out to be needed, a new key kind ahead of the shared key adds it without touching stored bindings.4. Bind and clear
powercontext scope resolvecomputes the shared key with the one rule. Its per-host table of derivations (_workspace_binding_external_id) remains only for the hosts' own keys.powercontext scope binding setgains an option that takes a directory, so nobody computes a hash by hand.allow_defaultoff. This runs in diagnostics only, not in hooks.5. Existing bindings
Nothing is migrated or rewritten.
During the rollout, a host that has not been updated does not read the shared key, so it behaves as it does today.
6. What stays as it is
scope_id, as RFC 1345 requires.7. Alternatives I rejected
integrationfor workspace keys. It changes the meaning of stored keys and the API contract, and the derivations still disagree.8. Order of work and tests
powercontext scope, and Codex session import. Then the TypeScript module (DSH, OpenCode, Pi). Then Kimi Code, ZCode, WorkBuddy, Hermes, and Bub.Tests that matter:
tests/test_git_worktree.pyin fix(integrations): resolve linked Git worktrees to their main checkout's workspace binding #2875 does for the Git helper. Windows needs its own run: drive-letter case and path separators are where the two languages can disagree, and I have not checked them.