Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions desktop/VALIDATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -3586,3 +3586,34 @@ uv run --no-sync python desktop/tests/real_server.py \
--product-qualification sqlite-source-plugins-9f113a72-v1 \
--wheel desktop/.artifacts/source-plugins/powercontext-1.5.2.dev248+g9f113a729-py3-none-any.whl
```


## Server bc22089e plugin Scope listing protocol qualification

`sqlite-plugin-scope-listing-bc22089e-v1` qualifies all thirteen Desktop protocol operations against
Server source `bc22089e9dc9fcefe6cc1d26d56a2a0c677bbd68`, which leaves plugin-created Scopes out of Scope listings and states
that rule in the `list_scopes` description.

- Normalized OpenAPI SHA-256: `eaa14b1581221ea89706140c5181c9ca701d685caaa9ebcbfdbcf5758db3d713`.
- Wheel: `powercontext-1.5.2.dev238+gbc22089e9-py3-none-any.whl`.
- Wheel SHA-256: `d7c7644cb32bc54bba8e9a2c5dd64d88d7db58d8c46a96008bbe4c4134b43fde`.
- Native debug probe SHA-256 (built without debug info): `0feb207b3fdb9be2293c67f6a0cdd4d01ea51c6685f71b20ac6af6c4fa2770f2`.

On 2026-11-18, Linux 7.0 x86_64 (Ubuntu 24.04, glibc 2.39) and Python 3.12.3 passed anonymous loopback,
static Bearer, HTTPS with explicit CA/base path, and enforced Provider modes of the unchanged
`desktop/tests/real_server.py` through the ordinary product ConnectionManager. The probe was built with
the product Cargo lock without `ci-fixtures` and selected this bundled qualification; the client and
qualified contract digests are identical. `bundled_product_qualification_covers_every_desktop_operation`
passed against the same records. The wheel and report are retained under ignored
`desktop/.artifacts/plugin-scope-listing/` and `desktop/.artifacts/real-server.json`.
This qualifies the observed local SQLite protocol; it does not establish installed WebView, native
credential persistence, other operating systems, native database upgrades or release acceptance.

Reproduce against the recorded artifact:

```sh
cargo build --locked --manifest-path desktop/src-tauri/Cargo.toml --example server_probe
uv run --no-sync python desktop/tests/real_server.py \
--product-qualification sqlite-plugin-scope-listing-bc22089e-v1 \
--wheel desktop/.artifacts/plugin-scope-listing/powercontext-1.5.2.dev238+gbc22089e9-py3-none-any.whl
```
22 changes: 22 additions & 0 deletions desktop/src-tauri/src/connections/compatibility.json
Original file line number Diff line number Diff line change
Expand Up @@ -1772,5 +1772,27 @@
"search_memory"
],
"evidence": "desktop/VALIDATION.md#server-9f113a72-source-plugins-protocol-qualification"
},
{
"id": "sqlite-plugin-scope-listing-bc22089e-v1",
"serverCommit": "bc22089e9dc9fcefe6cc1d26d56a2a0c677bbd68",
"contractSha256": "eaa14b1581221ea89706140c5181c9ca701d685caaa9ebcbfdbcf5758db3d713",
"artifactSha256": "d7c7644cb32bc54bba8e9a2c5dd64d88d7db58d8c46a96008bbe4c4134b43fde",
"operations": [
"get_access_principal",
"get_artifact_revision",
"get_capabilities",
"get_connection_identity",
"get_default_scope",
"get_liveness",
"get_readiness",
"get_scope",
"get_server_info",
"get_stats",
"list_scopes",
"remember_memory",
"search_memory"
],
"evidence": "desktop/VALIDATION.md#server-bc22089e-plugin-scope-listing-protocol-qualification"
}
]
2 changes: 1 addition & 1 deletion desktop/src-tauri/src/transport/operations.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"contractSha256": "d133a4c382a734d1e6fd194b1dbf4d90f7ffabc37fe335fc27d93f59fa4e636f",
"contractSha256": "eaa14b1581221ea89706140c5181c9ca701d685caaa9ebcbfdbcf5758db3d713",
"operations": {
"get_liveness": {
"method": "GET",
Expand Down
2 changes: 1 addition & 1 deletion desktop/ui/src/generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export interface paths {
};
/**
* List observable Scopes
* @description Inspect available Scopes for an explicit navigation or organization request. Do not enumerate Scopes to bypass the current session binding or search another work context implicitly. Reuse the host-selected Scope for ordinary data-plane operations. Discover Scope descriptors with an explicit literal-substring field and exact relationship filters. Query matches the selected original field using the database's native substring operation. Regular expressions and wildcard syntax are not supported. Case, accent, and full-width/half-width matching follow the underlying database collation; results need not be identical across backends. Requests without query parameters preserve the existing complete-list behavior.
* @description Inspect available Scopes for an explicit navigation or organization request. Do not enumerate Scopes to bypass the current session binding or search another work context implicitly. Reuse the host-selected Scope for ordinary data-plane operations. Discover Scope descriptors with an explicit literal-substring field and exact relationship filters. Query matches the selected original field using the database's native substring operation. Regular expressions and wildcard syntax are not supported. Case, accent, and full-width/half-width matching follow the underlying database collation; results need not be identical across backends. Requests without query parameters return the complete list in one response. Scopes created by a plugin (external reference kind `powercontext.plugin`) are used through that plugin and are left out of every listing, unless `external_reference_kind` is `powercontext.plugin`.
*/
get: operations["list_scopes"];
put?: never;
Expand Down
2 changes: 1 addition & 1 deletion desktop/ui/src/generated/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

// Generated from openapi/powercontext.yaml. Do not edit.
export const contractSha256 = "d133a4c382a734d1e6fd194b1dbf4d90f7ffabc37fe335fc27d93f59fa4e636f";
export const contractSha256 = "eaa14b1581221ea89706140c5181c9ca701d685caaa9ebcbfdbcf5758db3d713";
export const operations = {
"get_liveness": {
"method": "GET",
Expand Down
4 changes: 4 additions & 0 deletions docs/en/docs/develop/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ plugin = ArtifactPlugin(
`ctx.scopes.update(scope_id, expected_version=..., title=..., summary=...)` changes a Scope this plugin created and
also needs `server.admin`; the API returns 404 when the Scope does not exist and 403 when another plugin or user
created it.
- Scopes a plugin creates are used through the plugin: the `GET /v1/scopes` listing leaves them out, so the Dashboard's
Scope selector, the desktop app, and an agent's `list_scopes` do not show them, also after the plugin is removed. A
request with `external_reference_kind=powercontext.plugin` lists exactly these Scopes. Only listings change: reading a
Scope by ID, access to its data, and authorization stay as they are.
- `request.body` is the validated `request_model` instance, `bytes`, or `None`, according to `body`;
`request.path_params`, `request.query`, and `request.caller` are the path parameters, query parameters, and caller.
- Return a Pydantic model or a dict for JSON, `BinaryResponse(content=..., content_type=..., filename=...)` for a file,
Expand Down
3 changes: 2 additions & 1 deletion docs/en/rfcs/2579-plugin-reload-and-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ Scopes created by plugins:

- At creation, core adds the external reference `{"kind": "powercontext.plugin", "value": "<plugin name>"}` to the Scope;
`ctx.scopes.list()` and `ctx.scopes.update()` use it to decide ownership, and deployers can see which plugin created a
Scope.
Scope. The `GET /v1/scopes` listing leaves out Scopes with a reference of this kind; a request with
`external_reference_kind=powercontext.plugin` lists them.
- The permission to create Scopes is not relaxed for plugins. Letting non-administrators create Scopes (for example,
child Scopes under a parent) requires changing core's authorization model and is out of scope for this proposal.
- A plugin's business configuration (for example, a knowledge base's chunking strategy) is not written into the Scope;
Expand Down
3 changes: 3 additions & 0 deletions docs/zh/docs/develop/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ plugin = ArtifactPlugin(
- 需要创建 Scope 时用 `ctx.scopes.create(title=..., summary=..., idempotency_key=...)`,要求调用者具备 `server.admin`。
`ctx.scopes.list()` 返回本插件创建、且调用者可读的 Scope。`ctx.scopes.update(scope_id, expected_version=..., title=...,
summary=...)` 修改本插件创建的 Scope,同样要求 `server.admin`;Scope 不存在时接口返回 404,不是本插件创建的返回 403。
- 插件创建的 Scope 只通过插件使用:`GET /v1/scopes` 的列表不包含它们,所以 Dashboard 的 Scope 选择器、桌面端和 Agent 的
`list_scopes` 都看不到,插件卸载后也一样。带上 `external_reference_kind=powercontext.plugin` 时列出的就是这些 Scope。这只
影响列表:按 ID 读取 Scope、访问其中的数据和权限判定都不变。
- `request.body` 按 `body` 声明是校验后的 `request_model` 实例、`bytes` 或 `None`;`request.path_params`、`request.query`、
`request.caller` 分别是路径参数、查询参数和调用者。
- 返回值:Pydantic 模型或 dict 返回 JSON;`BinaryResponse(content=..., content_type=..., filename=...)` 返回文件;
Expand Down
3 changes: 2 additions & 1 deletion docs/zh/rfcs/2579-plugin-reload-and-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ RFC #2549 的上下文(专属存储、模型、日志),自定义接口调
插件创建的 Scope:

- core 在创建时给 Scope 加上外部引用 `{"kind": "powercontext.plugin", "value": "<插件名>"}`,`ctx.scopes.list()` 和
`ctx.scopes.update()` 据此判断归属,部署者也能看出 Scope 由哪个插件创建。
`ctx.scopes.update()` 据此判断归属,部署者也能看出 Scope 由哪个插件创建。`GET /v1/scopes` 的列表不包含带有这类引用的
Scope,请求带上 `external_reference_kind=powercontext.plugin` 时才列出它们。
- 创建 Scope 的权限要求不因插件而放宽。允许非管理员创建 Scope(例如在父 Scope 下创建子 Scope)需要修改 core 的授权
模型,不在本提案范围内。
- 插件的业务配置(例如知识库的分块策略)不写入 Scope,由插件以 `scope_id` 为键存进自己的存储。先创建 Scope,再写配置;
Expand Down
4 changes: 3 additions & 1 deletion openapi/powercontext.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,9 @@ paths:
Query matches the selected original field using the database's native substring operation.
Regular expressions and wildcard syntax are not supported. Case, accent, and full-width/half-width
matching follow the underlying database collation; results need not be identical across backends.
Requests without query parameters preserve the existing complete-list behavior.
Requests without query parameters return the complete list in one response.
Scopes created by a plugin (external reference kind `powercontext.plugin`) are used through that plugin and
are left out of every listing, unless `external_reference_kind` is `powercontext.plugin`.
operationId: list_scopes
x-powercontext-feature-contracts: [scope.selection]
x-powercontext-access: {action: server.observe, resource: {type: server}}
Expand Down
3 changes: 2 additions & 1 deletion src/powercontext/builtin/plugins/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
from powercontext.builtin.plugins.writer import PluginArtifactWriter, PluginContractError, PluginWriteError, UserChange
from powercontext.builtin.records import ArtifactRevisionPreconditionError, BaseValueConflictError
from powercontext.builtin.runtime.artifact_merge import ArtifactMergeAccess
from powercontext.builtin.scope.models import PLUGIN_SCOPE_REFERENCE_KIND
from powercontext.builtin.sources import BUILTIN_SOURCE_REGISTRY
from powercontext.errors import RevisionConflictError
from powercontext.plugins import (
Expand Down Expand Up @@ -738,7 +739,7 @@ async def submit(self, scope_id: str, definition: str, value: BaseModel, /) -> S


class _Scopes:
_KIND = "powercontext.plugin"
_KIND = PLUGIN_SCOPE_REFERENCE_KIND

def __init__(self, host: _Host) -> None:
self._host = host
Expand Down
5 changes: 4 additions & 1 deletion src/powercontext/builtin/scope/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,16 @@ async def list(
*,
scope_ids: Sequence[str] | None = None,
external_reference: ScopeExternalReference | None = None,
exclude_external_reference_kind: str | None = None,
) -> tuple[ScopeDescriptor, ...]:
async with self._database.transaction() as connection:
if scope_ids is not None:
return await self._repository.get_many(connection, tuple(scope_ids))
if external_reference is not None:
return await self._repository.with_external_reference(connection, external_reference)
return await self._repository.list(connection)
return await self._repository.list(
connection, exclude_external_reference_kind=exclude_external_reference_kind
)

async def navigation(self, scope_ids):
"""Resolve ancestor names without discovering unrelated Scopes or their contents."""
Expand Down
6 changes: 6 additions & 0 deletions src/powercontext/builtin/scope/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,17 @@ def validate_scope_id(cls, value: str) -> str:
]


# Scopes a plugin creates carry this external reference kind, with the plugin's name as the value.
PLUGIN_SCOPE_REFERENCE_KIND = "powercontext.plugin"


class ScopeDiscovery(_ScopeValue):
query: str | None = Field(default=None, max_length=256)
query_field: ScopeQueryField | None = None
parent_scope_id: str | None = None
external_reference_kind: str | None = None
# Scopes with a reference of this kind are left out; not part of the cursor's query identity.
exclude_external_reference_kind: str | None = None
binding_integration: str | None = None
binding_kind: str | None = None
limit: StrictInt = Field(default=50, ge=1, le=100)
Expand Down
25 changes: 22 additions & 3 deletions src/powercontext/builtin/scope/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from functools import lru_cache
from hashlib import sha256

from sqlalchemy import bindparam, delete, false, insert, literal, null, select, union_all, update
from sqlalchemy import bindparam, delete, false, insert, literal, null, select, true, union_all, update
from sqlalchemy.ext.asyncio import AsyncConnection

from powercontext.builtin.persistence.tables import (
Expand All @@ -45,6 +45,20 @@
_DEFAULT_SETTING = "default"


def _without_reference_kind(kind: str | None):
"""Scopes that carry no external reference of this kind; every Scope when no kind is given."""

if kind is None:
return true()
external = SCOPE_EXTERNAL_REFERENCES_TABLE.alias("scope_excluded_external_reference")
return ~(
select(1)
.where(external.c.scope_id == SCOPES_TABLE.c.scope_id, external.c.kind == kind)
.correlate(SCOPES_TABLE)
.exists()
)


def _scope_projection(statement):
"""Read Scope metadata and its relationships in one ordered result."""
metadata = ("scope_id", "title", "summary", "parent_scope_id", "version")
Expand Down Expand Up @@ -115,8 +129,11 @@ async def navigation(self, connection, scope_ids):
).mappings()
return tuple(dict(row) for row in rows)

async def list(self, connection: AsyncConnection, /) -> tuple[ScopeDescriptor, ...]:
return await self._load(connection, _scope_projection(select(SCOPES_TABLE).order_by(SCOPES_TABLE.c.scope_id)))
async def list(
self, connection: AsyncConnection, /, *, exclude_external_reference_kind: str | None = None
) -> tuple[ScopeDescriptor, ...]:
statement = select(SCOPES_TABLE).where(_without_reference_kind(exclude_external_reference_kind))
return await self._load(connection, _scope_projection(statement.order_by(SCOPES_TABLE.c.scope_id)))

async def with_external_reference(
self, connection: AsyncConnection, reference: ScopeExternalReference, /
Expand Down Expand Up @@ -174,6 +191,8 @@ async def discover(
if len(external_conditions) > 1:
statement = statement.where(select(1).where(*external_conditions).correlate(SCOPES_TABLE).exists())

statement = statement.where(_without_reference_kind(discovery.exclude_external_reference_kind))

binding = SCOPE_BINDINGS_TABLE.alias("scope_discovery_binding")
binding_conditions = [binding.c.scope_id == SCOPES_TABLE.c.scope_id]
if discovery.binding_integration is not None:
Expand Down
8 changes: 6 additions & 2 deletions src/powercontext/http/_generated/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,12 @@
"full-width/half-width matching follow the "
"underlying database collation; results need not "
"be identical across backends. Requests without "
"query parameters preserve the existing "
"complete-list behavior.",
"query parameters return the complete list in one "
"response. Scopes created by a plugin (external "
"reference kind `powercontext.plugin`) are used "
"through that plugin and are left out of every "
"listing, unless `external_reference_kind` is "
"`powercontext.plugin`.",
"operationId": "list_scopes",
"x-powercontext-feature-contracts": ["scope.selection"],
"x-powercontext-access": {"action": "server.observe", "resource": {"type": "server"}},
Expand Down
8 changes: 7 additions & 1 deletion src/powercontext/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@
from powercontext.builtin.scope import (
ScopeSelection as DomainScopeSelection,
)
from powercontext.builtin.scope.models import PLUGIN_SCOPE_REFERENCE_KIND
from powercontext.builtin.source_eligibility import SourceNotEligibleError
from powercontext.builtin.sources import (
ObservedInvocation,
Expand Down Expand Up @@ -2610,8 +2611,12 @@ async def list_scopes(
)
or "limit" in http_request.query_params
)
# A plugin's Scopes hold what the plugin manages and are reached through the plugin. Listings leave
# them out unless the request asks for that reference kind.
hidden = None if request.external_reference_kind == PLUGIN_SCOPE_REFERENCE_KIND else PLUGIN_SCOPE_REFERENCE_KIND
if not pagination_requested:
return ScopePage(items=[_scope_descriptor_response(scope) for scope in await scopes.list()])
listed = await scopes.list(exclude_external_reference_kind=hidden)
return ScopePage(items=[_scope_descriptor_response(scope) for scope in listed])

principal = current_principal()
caller = "anonymous" if principal is None else f"{principal.type}:{principal.id}"
Expand All @@ -2621,6 +2626,7 @@ async def list_scopes(
query_field=None if request.query_field is None else request.query_field.value,
parent_scope_id=request.parent_scope_id,
external_reference_kind=request.external_reference_kind,
exclude_external_reference_kind=hidden,
binding_integration=request.binding_integration,
binding_kind=request.binding_kind,
limit=request.limit,
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/test_plugin_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,15 @@ async def scenario():
assert renamed.json()["title"] == "renamed"
assert west["scope_id"] not in listed.json()["scope_ids"]

# Scope listings leave a plugin's Scopes out, as one complete list and as pages with any filter.
rooms = {east["scope_id"], west["scope_id"]}
for query in ("", "?limit=100", "?query=e&query_field=title"):
page = await admin.get(f"/v1/scopes{query}")
assert page.status_code == 200, page.text
assert not rooms & {item["scope_id"] for item in page.json()["items"]}
assert other in {item["scope_id"] for item in (await admin.get("/v1/scopes")).json()["items"]}
# Asking for the plugin reference kind lists exactly them.
asked = await admin.get("/v1/scopes?external_reference_kind=powercontext.plugin")
assert {item["scope_id"] for item in asked.json()["items"]} == rooms

asyncio.run(scenario())
Loading