Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
caf47e8
test(plugins): check host process growth without depending on how fas…
jasper-yl Nov 14, 2026
61d380b
fix(plugins): carry host Pipe messages on dedicated threads
jasper-yl Nov 15, 2026
f1f77a9
fix(plugins): list only a plugin's own Scopes and check server.admin …
jasper-yl Nov 15, 2026
0b3531b
fix(plugins): close a host Pipe only after both channel threads stop,…
jasper-yl Nov 15, 2026
2aa03e0
fix(plugins): keep user changes and background writes consistent with…
jasper-yl Nov 15, 2026
baa1d87
feat(dashboard): let a plugin page call the generic Artifact API of i…
jasper-yl Nov 15, 2026
ddea02e
feat(plugins): serve dedicated plugin storage on OceanBase and seekdb
jasper-yl Nov 15, 2026
89026bb
docs(develop): describe plugin storage backends, page access to Artif…
jasper-yl Nov 15, 2026
6c6a543
test: follow the v1_5_0_005 migration and the current Prepared Contex…
jasper-yl Nov 15, 2026
2ffa8a8
fix(scopes): match an external reference exactly when listing Scopes …
jasper-yl Nov 15, 2026
6b3200b
fix(dashboard): keep a plugin page's forwarded requests inside its ow…
jasper-yl Nov 15, 2026
738479d
fix(dashboard): forward repeated query parameters of a plugin page's …
jasper-yl Nov 15, 2026
a84c638
fix(dashboard): pass forwarded query pairs as a tuple so the type che…
jasper-yl Nov 15, 2026
3985b95
test(native): expect the v1_5_0_005 head after OceanBase engine crash…
jasper-yl Nov 16, 2026
24a7840
fix(plugins): check the observed governance state again when a plugin…
jasper-yl Nov 16, 2026
756327f
test(plugins): cover concurrent forget during artifact writes
hidb4ai Nov 16, 2026
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
39 changes: 31 additions & 8 deletions docs/en/docs/develop/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ Listing, reading revisions and history, governance state, and tags call no plugi
`source_refs`. Content identical to the current revision adds no revision, so repeated delivery never writes duplicate
revisions. `writer.stable_id(...)` derives a stable ID from its inputs, so the same Source always writes to the same
Artifact.
- For an Artifact read outside the transaction with `writer.get` and similar methods, core checks at write time whether
it changed since: if its content was edited, or it was forgotten, restored, or merged, the write conflicts, the batch of
Sources is delivered again later, and the plugin decides again from the new state. The plugin need not compare anything
itself.
- Other operations include `tx.set_lifecycle`, `tx.merge`, `tx.revert`, and `tx.set_tags`; read current state with
`writer.get`, `writer.list`, and `writer.by_source`.
`tx.revert` and `tx.set_lifecycle` return `ArtifactChange`: `result.artifact` is the target snapshot,
Expand Down Expand Up @@ -248,7 +252,9 @@ class Notes:
write.
- The response reports the revision this write committed, even if later writes have followed.
- Raising `InvalidContent` returns 422 with the message shown to the caller.
- User changes record provenance as the person who made them, as edits of built-in Artifacts do.
- User changes record provenance as the person who made them, as edits of built-in Artifacts do. What is recorded is
the request's `content` as submitted: a method may treat it as a description of one change and write content computed
from it, and the provenance still keeps what the caller submitted.

## Define Source types

Expand Down Expand Up @@ -363,15 +369,21 @@ plugin = ArtifactPlugin(
- `scope.read` / `scope.contribute`: the caller needs that permission on the Scope in the path parameter named by
`scope_param`.
- In handlers, `ctx.require(action, scope_id)` checks further permissions and makes the API return 403 when the caller
lacks them; `ctx.allowed(...)` only answers true or false.
lacks them; `ctx.allowed(...)` only answers true or false. When an API only accepts a request and `generate` changes
an existing Artifact later, first check the caller's write permission on that Artifact with
`ctx.require("artifact.write", scope_id, artifact_id=...)`: the background write has no caller identity. This check
covers only Artifacts of this plugin's family.
- Reading and writing core data: `ctx.reads(scope_id)` reads with the caller's permissions; `ctx.writer(scope_id)` and
`ctx.sources.submit(...)` work only for Scopes whose `scope.contribute` was confirmed earlier in the request (by the
route's `access` or a prior `ctx.require`). Changing an existing Artifact, including its tags, handles, and lifecycle,
also needs the caller's `artifact.write` on that Artifact, as through the generic API; otherwise the API returns 403.
- Writes in APIs do not record who did what. When you need that provenance, submit the operation as a Source, as in the
example above, and let `generate` write the new revision referencing it.
- To create a Scope, call `ctx.scopes.create(title=..., summary=..., idempotency_key=...)`; the caller needs
`server.admin`.
`server.admin`. `ctx.scopes.list()` returns the Scopes this plugin created that the caller can read.
`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.
- `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 Expand Up @@ -409,9 +421,16 @@ async def setup(ctx):
return Notes(ctx)
```

- `ctx.storage.engine()` returns an async SQLAlchemy engine for `plugins/<plugin name>.sqlite3` in the data directory. The
plugin owns its tables and migrations; core never reads or backs up this storage. Only SQLite deployments are supported
for now; on Servers using OceanBase or seekdb, accessing `ctx.storage` raises an error.
- `ctx.storage.engine()` returns an async SQLAlchemy engine for this plugin's storage only, on the Server's database
backend and with its connection settings: `plugins/<plugin name>.sqlite3` in the data directory on SQLite deployments,
and a database named `powercontext_plugin_<plugin name>` (with `-` replaced by `_`) on the same tenant or instance on
OceanBase and seekdb deployments. `ctx.storage.backend` names the backend (`sqlite`, `oceanbase`, or `seekdb`) so the
plugin can choose its table definitions and indexes. The plugin owns its tables and migrations; core never reads or
backs up this storage.
- On OceanBase and seekdb, core creates the database when the plugin loads and reuses an existing one. When the Server's
database login cannot create databases, the deployer creates it and grants access beforehand. If the database is
missing and cannot be created, or its name exceeds 64 characters (a plugin name longer than 44), the plugin still
loads, and `ctx.storage.engine()` raises an error that states the reason.
- This storage is outside core's transactions. Store large content such as files and vectors under its content digest and
reference the digest from Artifacts: retried writes and rolled-back transactions then leave only unreferenced records,
never Artifacts pointing at the wrong data.
Expand Down Expand Up @@ -444,9 +463,14 @@ plugin = ArtifactPlugin(..., pages=PluginPages(directory="ui", entry="index.html

- The page appears in the Dashboard's side navigation at `/dashboard/plugins/<plugin name>`.
- The page runs in a sandboxed iframe without the user's session; the Dashboard forwards its requests as the current user,
only to routes the plugin declares.
only to routes the plugin declares and to the generic Artifact API of the plugin's family.
- `client.request(method, path, options)` accepts `json`, `body` (such as a file's `ArrayBuffer`), `contentType`, and
`query`, and returns `status`, `ok`, `json`, `blob`, and `filename`.
- `client.artifacts(method, path, options)` calls the generic Artifact API of this plugin's family, with no route to
declare. `path` follows `/v1/scopes/{scope_id}/artifacts/{family}`: an empty string lists (`GET`) or creates (`POST`),
`/{artifact_id}` reads or edits, `/{artifact_id}/forget` forgets, and so on. `options` also takes `scopeId` (the page's
current Scope by default) and `ifMatch`, and the result also has `etag` and `location`. Permissions, version checks,
and provenance are the same as calling the generic API directly, and the page cannot name another family.
- Build the page as a single-page app: after the page navigates, the Dashboard stops forwarding and asks the user to reopen
it. Browser dialogs such as `alert` and `confirm` are unavailable in the sandbox.
- Pages are static files only (HTML, JavaScript, CSS, images, fonts), up to 5 MiB each; scripts may come only from the
Expand All @@ -466,6 +490,5 @@ plugin = ArtifactPlugin(..., pages=PluginPages(directory="ui", entry="index.html
## Current limits

- Updating a plugin requires a Server restart; hot reload is not available yet.
- Dedicated plugin storage supports only SQLite deployments for now.
- Deployers install plugin dependencies into the Server environment by hand.
- Plugin code has the Server's permissions; host processes and Workers isolate failures, not untrusted code.
28 changes: 22 additions & 6 deletions docs/zh/docs/develop/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ Server 在一个独立的子进程中导入 `plugin.py` 并检查声明,导入
- 调用模型、解析文件等慢操作放在事务之外,事务里只做写入。
- `tx.put(artifact_id, content=..., source_refs=[...])` 写一个新版本,`source_refs` 记录出处。内容与当前版本相同时不产生新版本,
所以重复交付不会写出重复的版本。`writer.stable_id(...)` 按输入生成稳定的 ID,便于同一条 Source 总是写到同一个 Artifact。
- 事务外用 `writer.get` 等方法读过的 Artifact,写入时 core 会核对它之后有没有变化:内容被修改过,或者被遗忘、恢复、合并过,
这次写入都会冲突,整批 Source 稍后再次交付,插件基于新状态重新决定。插件不需要自己比较。
- 还可以用 `tx.set_lifecycle`、`tx.merge`、`tx.revert`、`tx.set_tags` 等方法,以及 `writer.get`、`writer.list`、
`writer.by_source` 读取当前状态。
`tx.revert` 和 `tx.set_lifecycle` 返回 `ArtifactChange`:`result.artifact` 是目标快照,
Expand Down Expand Up @@ -228,7 +230,8 @@ class Notes:
(修改内容时为 412),插件不必自己重复检查。方法只负责校验内容并完成约定的那一次写入。
- 接口返回本次写入提交的版本,即使之后已有其他写入。
- 抛出 `InvalidContent` 时接口返回 422,错误信息展示给调用者。
- 用户修改会以修改人的身份记录出处,与内置 Artifact 的修改相同。
- 用户修改会以修改人的身份记录出处,与内置 Artifact 的修改相同。记录的是请求中的 `content` 原文:方法可以把它当作对一次
修改的描述,写入另行算出的内容,出处里保留的仍是调用者提交的那一份。

## 定义 Source 类型

Expand Down Expand Up @@ -340,12 +343,17 @@ plugin = ArtifactPlugin(
- `authenticated`:只要求已登录;
- `scope.read` / `scope.contribute`:要求调用者对 `scope_param` 指定的路径参数中的 Scope 具备该权限。
- 处理函数里用 `ctx.require(action, scope_id)` 检查其他权限,不具备时接口返回 403;`ctx.allowed(...)` 只返回真假。
接口只是接受请求、之后由 `generate` 修改已有 Artifact 时,先用
`ctx.require("artifact.write", scope_id, artifact_id=...)` 检查调用者对这个 Artifact 的写权限:后台写入时没有调用者身份。
这项检查只针对本插件 family 的 Artifact。
- 读写核心数据:`ctx.reads(scope_id)` 按调用者权限读取;`ctx.writer(scope_id)` 和 `ctx.sources.submit(...)` 只能用于本次
请求中已经确认 `scope.contribute` 的 Scope(路由声明了该权限,或处理函数先调用了 `ctx.require`)。修改已有 Artifact
(包括标签、handle 和生命周期)还需要调用者对该 Artifact 有 `artifact.write` 权限,与通用接口相同;没有权限时接口返回 403。
- 接口中的写入不会自动记录"谁做了什么"。需要这类出处时,像上面的例子一样把操作作为 Source 提交,由 `generate` 写入新版本并
引用它。
- 需要创建 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。
- `request.body` 按 `body` 声明是校验后的 `request_model` 实例、`bytes` 或 `None`;`request.path_params`、`request.query`、
`request.caller` 分别是路径参数、查询参数和调用者。
- 返回值:Pydantic 模型或 dict 返回 JSON;`BinaryResponse(content=..., content_type=..., filename=...)` 返回文件;
Expand Down Expand Up @@ -379,9 +387,13 @@ async def setup(ctx):
return Notes(ctx)
```

- `ctx.storage.engine()` 返回一个 SQLAlchemy 异步引擎,指向数据目录下的 `plugins/<插件名>.sqlite3`。表结构和迁移由插件自己
管理,core 不读取、不备份这块存储。目前只支持 SQLite 部署;使用 OceanBase 或 seekdb 的 Server 上,访问 `ctx.storage`
会报错。
- `ctx.storage.engine()` 返回一个 SQLAlchemy 异步引擎,只指向本插件的存储,使用 Server 的数据库后端和连接配置:SQLite
部署是数据目录下的 `plugins/<插件名>.sqlite3`;OceanBase 和 seekdb 部署是同一个租户或实例上名为
`powercontext_plugin_<插件名>` 的库(`-` 换成 `_`)。`ctx.storage.backend` 给出后端(`sqlite`、`oceanbase` 或 `seekdb`),
插件据此选择建表语句和索引。表结构和迁移由插件自己管理,core 不读取、不备份这块存储。
- OceanBase 和 seekdb 上的库在插件加载时由 core 创建,已存在则直接使用。Server 的数据库登录没有建库权限时,由部署者
事先建好并授权。库不存在又无法创建,或者库名超过 64 个字符(插件名超过 44 个字符)时,插件照常加载,调用
`ctx.storage.engine()` 时报错并说明原因。
- 这块存储不在 core 的事务里。大块内容(文件、向量)建议按内容摘要保存,再在 Artifact 中引用摘要:写入重试或事务回滚只会
留下没人引用的记录,不会让 Artifact 指向错误的数据。
- 存储属于整个插件,不按 Scope 隔离。按 `scope_id` 划分数据,并在读取时确认数据属于本次请求的 Scope。
Expand Down Expand Up @@ -411,9 +423,14 @@ plugin = ArtifactPlugin(..., pages=PluginPages(directory="ui", entry="index.html
```

- 页面出现在 Dashboard 左侧导航中,地址是 `/dashboard/plugins/<插件名>`。
- 页面运行在沙箱 iframe 中,拿不到用户的登录会话;请求由 Dashboard 以当前用户的身份转发,只能调用本插件声明的路由。
- 页面运行在沙箱 iframe 中,拿不到用户的登录会话;请求由 Dashboard 以当前用户的身份转发,只能调用本插件声明的路由和本插件
family 的通用 Artifact 接口。
- `client.request(method, path, options)` 的 `options` 可以有 `json`、`body`(例如文件的 `ArrayBuffer`)、`contentType` 和
`query`;返回 `status`、`ok`、`json`、`blob`、`filename`。
- `client.artifacts(method, path, options)` 调用本插件 family 的通用 Artifact 接口,不需要声明路由。`path` 接在
`/v1/scopes/{scope_id}/artifacts/{family}` 之后:空字符串是列表(`GET`)或新建(`POST`),`/{artifact_id}` 是读取或编辑,
`/{artifact_id}/forget` 是遗忘,依此类推。`options` 另有 `scopeId`(默认是页面当前的 Scope)和 `ifMatch`;返回值另有
`etag` 和 `location`。权限、版本校验和出处记录与直接调用通用接口相同,页面不能指定其他 family。
- 页面要做成单页应用:页面跳转后 Dashboard 会停止转发,提示用户重新打开。沙箱中不能使用 `alert`、`confirm` 等浏览器对话框。
- 只提供静态文件(HTML、JavaScript、CSS、图片、字体),单个文件不超过 5 MiB;脚本只能来自插件自己的目录和
`/dashboard/plugins/_client.js`。
Expand All @@ -432,6 +449,5 @@ plugin = ArtifactPlugin(..., pages=PluginPages(directory="ui", entry="index.html
## 当前限制

- 插件更新需要重启 Server,还不支持热加载。
- 插件专属存储目前只支持 SQLite 部署。
- 插件依赖由部署者手动安装到 Server 环境。
- 插件代码与 Server 有相同的权限,宿主进程和 Worker 隔离的是故障,不是不可信代码。
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,7 @@
"sensitivity_of": null,
"path": "assembly",
"max_bytes": 3000,
"input_sha256": "bc7766a4de352fc6d6a3f704a95c5b1cd9239555f210a4767746d4bfb9b03933",
"input_sha256": "74132e65051a1c2c34aedde5f414789d373136598206ce4234d31aabd88b0e17",
"baseline_content_bytes": 2952,
"candidate_content_bytes": 3000,
"baseline_coverage": 0.5857421563596759,
Expand Down Expand Up @@ -2047,7 +2047,7 @@
"sensitivity_of": null,
"path": "assembly",
"max_bytes": 1400,
"input_sha256": "391945926fe015cfee954ef91b0cec6ebd2e50564af31d86f54008fa3af2bbd1",
"input_sha256": "8d00f828905ab0d2e5a2a6a12bc521b8a88e425b3270d759dac83ff52d293038",
"baseline_content_bytes": 1399,
"candidate_content_bytes": 1400,
"baseline_coverage": 0.4944314063466925,
Expand Down Expand Up @@ -2159,7 +2159,7 @@
"sensitivity_of": null,
"path": "assembly",
"max_bytes": 640,
"input_sha256": "7960458af30d40aff0c152b08205fd1ed19094e940756936be4a17580048e76d",
"input_sha256": "3c2cf212de65546866d245aad3703f51771a391a84b0de78ee30e69fa01f4d28",
"baseline_content_bytes": 640,
"candidate_content_bytes": 640,
"baseline_coverage": 0.051853254067369715,
Expand Down Expand Up @@ -2330,7 +2330,7 @@
"sensitivity_of": null,
"path": "assembly",
"max_bytes": 2400,
"input_sha256": "e996105f32ead0a09138d8182dde67e23252c8dca26a009fc37fb038f953a345",
"input_sha256": "93a5308fa74066923ec1fa76c687ea3e5b9b4b7792131cc4e79a8b9f724f683f",
"baseline_content_bytes": 2234,
"candidate_content_bytes": 2400,
"baseline_coverage": 0.4690000933206748,
Expand Down Expand Up @@ -2703,7 +2703,7 @@
"sensitivity_of": "assembly-large-early-then-small",
"path": "assembly",
"max_bytes": 3000,
"input_sha256": "bfb0fc5f1aad7c0558a227dd8cee2319fef9a9100de3c9a5ae95f3108d7a8e3d",
"input_sha256": "119ec1d83cfd36e1c008dd0205d193d0a20beec1c52452ea2fbe68544c58e92a",
"baseline_content_bytes": 3000,
"candidate_content_bytes": 3000,
"baseline_coverage": 0.8389852114932723,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Inputs SHA-256: `7898b82f155accc150e507ba8eab48a1a1aa34681521dd71e201af5fa0f6bc6

### `assembly-large-early-then-small`

Inputs SHA-256: `bc7766a4de352fc6d6a3f704a95c5b1cd9239555f210a4767746d4bfb9b03933`
Inputs SHA-256: `74132e65051a1c2c34aedde5f414789d373136598206ce4234d31aabd88b0e17`

| Pos | Kind | Artifact | Rank | Display | Baseline | Delivered | Retained | Candidate | Delivered | Retained |
| ---: | --- | --- | ---: | ---: | --- | ---: | ---: | --- | ---: | ---: |
Expand All @@ -231,7 +231,7 @@ Inputs SHA-256: `bc7766a4de352fc6d6a3f704a95c5b1cd9239555f210a4767746d4bfb9b0393

### `assembly-controls-and-line-endings`

Inputs SHA-256: `391945926fe015cfee954ef91b0cec6ebd2e50564af31d86f54008fa3af2bbd1`
Inputs SHA-256: `8d00f828905ab0d2e5a2a6a12bc521b8a88e425b3270d759dac83ff52d293038`

| Pos | Kind | Artifact | Rank | Display | Baseline | Delivered | Retained | Candidate | Delivered | Retained |
| ---: | --- | --- | ---: | ---: | --- | ---: | ---: | --- | ---: | ---: |
Expand All @@ -242,7 +242,7 @@ Inputs SHA-256: `391945926fe015cfee954ef91b0cec6ebd2e50564af31d86f54008fa3af2bbd

### `assembly-infeasible-640`

Inputs SHA-256: `7960458af30d40aff0c152b08205fd1ed19094e940756936be4a17580048e76d`
Inputs SHA-256: `3c2cf212de65546866d245aad3703f51771a391a84b0de78ee30e69fa01f4d28`

| Pos | Kind | Artifact | Rank | Display | Baseline | Delivered | Retained | Candidate | Delivered | Retained |
| ---: | --- | --- | ---: | ---: | --- | ---: | ---: | --- | ---: | ---: |
Expand All @@ -257,7 +257,7 @@ Inputs SHA-256: `7960458af30d40aff0c152b08205fd1ed19094e940756936be4a17580048e76

### `assembly-four-sections`

Inputs SHA-256: `e996105f32ead0a09138d8182dde67e23252c8dca26a009fc37fb038f953a345`
Inputs SHA-256: `93a5308fa74066923ec1fa76c687ea3e5b9b4b7792131cc4e79a8b9f724f683f`

| Pos | Kind | Artifact | Rank | Display | Baseline | Delivered | Retained | Candidate | Delivered | Retained |
| ---: | --- | --- | ---: | ---: | --- | ---: | ---: | --- | ---: | ---: |
Expand Down Expand Up @@ -289,7 +289,7 @@ Inputs SHA-256: `c07ebcd45331d109c14dea3742a00af25cbcd18da56dc80847ad5fa589ac76c

### `sensitivity-assembly-large-last`

Inputs SHA-256: `bfb0fc5f1aad7c0558a227dd8cee2319fef9a9100de3c9a5ae95f3108d7a8e3d`
Inputs SHA-256: `119ec1d83cfd36e1c008dd0205d193d0a20beec1c52452ea2fbe68544c58e92a`

| Pos | Kind | Artifact | Rank | Display | Baseline | Delivered | Retained | Candidate | Delivered | Retained |
| ---: | --- | --- | ---: | ---: | --- | ---: | ---: | --- | ---: | ---: |
Expand Down
4 changes: 2 additions & 2 deletions release/upgrade-support.json

Large diffs are not rendered by default.

Loading
Loading