Skip to content

feat(plugins): plugin framework — Artifact plugins, plugin APIs, and Dashboard pages - #6

Closed
jasper-yl wants to merge 31 commits into
masterfrom
feat/plugin-framework
Closed

jasper-yl wants to merge 31 commits into
masterfrom
feat/plugin-framework

Conversation

@jasper-yl

Copy link
Copy Markdown
Owner

这个 PR 是什么

插件框架的实现,对应 RFC oceanbase#2549(插件接口)中 Artifact 插件的部分,以及 RFC oceanbase#2579 中的插件接口与 Dashboard 页面。Source 插件(collect)、端侧采集、热加载、版本快照、数据升级钩子、MCP 工具还没有实现,见文末。

一个插件就是插件目录下的一个文件夹和其中的 plugin.py。它可以:

  • 声明一个 Artifact family,消费 Source 并在后台生成这个 family 的 Artifact;结果通过现有的 Artifact 接口读取、检索、打标签;
  • 实现新建、修改、合并、遗忘、恢复方法,让通用 Artifact 接口作用于插件的 family;
  • 定义自己的 Source 类型,经插件接口或通用 Source 写入接口提交;
  • 声明自己的 HTTP 路由(/v1/plugins/{name}/api/...)和 Dashboard 页面;
  • 使用 core 分配的专属存储和 Server 配置的 embedding、生成模型。

完整的知识库(RAG)插件示例在 #5,它以本分支为基础,差异里只有插件本身。

怎么读

  1. 教程 docs/{zh,en}/docs/develop/plugins.md:插件开发者看到的样子,示例都在真实 Server 上跑通过。
  2. 公共契约 src/powercontext/plugins.py:插件声明(ArtifactPlugin、Inputs、Route、PluginApi、PluginPages)、上下文 PluginContext、写入器与读取接口、用户修改的请求模型、接口请求与响应模型。
  3. 加载与检查 builtin/plugins/manifest.py:在独立子进程中导入 plugin.py、校验声明、计算代码指纹,得到可跨进程传递的 PluginManifest。
  4. 后台生成 builtin/plugins/executor.py(Worker 中的一次调用:读窗口、按类型计算 Projection、调用 generate、与游标一起提交)和 builtin/plugins/writer.py(写入器:写事务、出处校验、用户修改的约定写入与 lineage_only 出处 Source)。
  5. 宿主进程 builtin/plugins/host.py、host_protocol.py(子进程:core 运行时加上插件,自己建数据库连接和授权,执行用户修改、插件接口和插件 Source 的写入)与 server/plugin_hosts.py(Server 端:spawn、双向 Pipe、超时终止、退避重启)。
  6. 专属存储与模型 builtin/plugins/storage.py。
  7. Server 集成 server/plugins.py(插件管理:加载、注册 family 和 Source 定义、Supervisor binding、启动宿主进程)、server/app.py 中的插件部分(通用创建 / 修改 / 合并 / 遗忘 / 恢复转给宿主进程、插件 Source 写入、插件路由挂载与请求体上限)、server/http_limits.py。
  8. Dashboard 页面 server/dashboard/plugin_pages.py、templates/plugin.html(宿主页面与转发脚本)、static/plugin-client.js(插件页面使用的客户端)。
  9. 测试:tests/builtin/plugins/(写入器、Inputs 校验)、tests/e2e/test_plugins.py(加载、生成、通用 Artifact 接口、通用创建、插件 Source 写入)、tests/e2e/test_plugin_pages.py(页面沙箱、转发、请求体上限、模型调用)。

examples/plugins/atomic_memory 是用插件方式重写的 Atomic Memory,只用于验证接口设计,不打算合入上游。

接口变化

  • POST /v1/scopes/{scope_id}/artifacts:请求体增加插件分支 {"family", "content"}。CreateArtifactRequest 变为内置分支 CreateBuiltinArtifactRequest 与插件分支 CreatePluginArtifactRequest 二选一,按 family 名选择;内置 family 的校验不变。生成的 Python 客户端中内置请求多一层包装,ArtifactCreated.family 改为字符串。
  • POST /v1/scopes/{scope_id}/sources:source_type 从只能为 content 的枚举改为字符串,可以是插件定义的类型;SourceType 枚举保留。
  • 新增 GET /v1/plugins、GET /v1/plugins/{name}、GET /v1/plugins/{name}/scopes,以及治理、合并、遗忘、恢复等通用接口(对所有登记的 family 生效)。
  • 插件路由 /v1/plugins/{name}/api/... 和 Dashboard 路径 /dashboard/plugins/... 不在 OpenAPI 契约中。
  • 新增环境变量 POWERCONTEXT_SERVER_PLUGINS_DIR、POWERCONTEXT_SERVER_PLUGIN_API_MAX_BODY_BYTES。
  • Desktop 的生成契约文件已重新生成。

还没有做

  • Source 插件(collect)、采集目标与端侧采集模式;
  • 热加载、版本快照、插件数据升级钩子(RFC docs(rfc): propose plugin hot reload and plugin-defined APIs oceanbase/powercontext#2579 已写入);
  • 插件路由作为 MCP 工具;插件的 OpenAPI 描述;
  • OceanBase / seekdb 部署上的插件专属存储(目前只支持 SQLite);
  • 插件调用模型计入用量统计;
  • 移除旧的 Source 插件和 Artifact 插件框架。

验证

uv run pytest tests/builtin/plugins tests/examples tests/e2e/test_plugins.py tests/e2e/test_plugin_pages.py
uv run pytest tests/test_api_contract.py tests/test_js_operations.py
uv run ruff check . && uv run ruff format --check . && uv run ty check
make docs-test

tests/test_desktop_contract.py::test_bundled_desktop_contract_has_a_qualified_business_profile 目前失败:本分支修改了 OpenAPI 契约,新的契约摘要需要一份 Desktop 资格记录(用本分支构建的 wheel 运行 desktop/tests/real_server.py 生成),合入上游前补上。完整测试集需要更大的机器运行。

AI 使用说明

代码、测试、文档和本说明由 Claude Code(Claude Opus 5.5)在作者的指导下编写,作者审阅设计决定;测试与手动验证由 Claude Code 执行并核对结果。

🤖 Generated with Claude Code

jasper-yl and others added 30 commits November 8, 2026 10:45
Replace the Source and Artifact plugin frameworks with a few interfaces
that PC Server calls through the Supervisor. Core keeps only Sources,
Artifacts, collection targets, and consumption progress; plugins no
longer have managed lifecycle state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nstrained writer

Implements the Artifact side of RFC 2549: directory-loaded plugins, Worker
execution through the existing Supervisor, a writer whose single
transaction commits plugin writes with the cursor and acknowledgment,
public reads and text search over plugin families, durable manual
requests, and read-only plugin listing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reuses the built-in extraction and reconciliation contracts, writes
memories, revisions, merges and lifecycle changes through the plugin
writer, keeps a plugin-owned similarity index checked against core
revisions, and accepts remember, edit, forget, restore and undo_merge
commands as manual requests. Restoring a merge-frozen input now uses the
shared restoration path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Register the generate operation in the base access contract, regenerate
JS operation tables, record the plugin persistence review, and fix type
diagnostics in the plugin modules and tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…act APIs

- plugin.py assigns an ArtifactPlugin declaration; plugin.yml, ${ENV}
  substitution and the Config export are gone, settings come from the
  environment inside create.
- User changes to plugin Artifacts run in core: replace_artifact accepts
  plugin families, and generic lifecycle and undo-merge routes reuse the
  plugin writer. The manual generate route and its request queue are removed.
- Core derives search text from the declared search_fields, so plugin and
  user writes index identically.
- /v1/plugins drops in-memory call outcomes; /v1/plugins/{name}/scopes reads
  per-Scope progress from intents and cursors.
- RFC 2549 is restructured around the overall design and the two plugin
  kinds' interfaces and declarations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…registered family

Replace the plugin-only lifecycle and undo-merge routes with generic routes on
the shared merge registry: governance reads, merges, forget and restorations
now work for every family registered with ArtifactMergeApplication, including
Experience, Atomic Memory and plugin families that Server registers at load.
Plugin edits record a lineage-only content Source like built-in edits, tag
routes accept plugin families, and plugin writers no longer sign previews
with a per-process random key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g tag families in the client

The Codex hook binds the current Scope for the four new generic Artifact
operations, and the Python client recognizes legacy Memory tag queries now
that TaggableArtifactFamily is a string model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dge collection

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Key owned bulk content by content digest so rolled-back revision numbers
cannot collide, state the storage-agnostic requirements behind treating
core's commit as the only point where owned data takes effect, and align
unchanged writes with Atomic Memory and user edits with built-in replace.
Also run the host factory once per process, check the code fingerprint
before importing, return cascaded refs from revert and set_lifecycle,
and make a removed plugin's family unreadable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move executor flows, internal class names, limit values, column lists, and observability field tables to the implementation design.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A host process is core runtime plus one plugin: spawned like a Worker, it
rebuilds the database connection and authorization from configuration,
so the Server only authenticates and forwards over a duplex Pipe. Edits,
merge, forget, and restoration of plugin families now call the plugin's
optional methods there; the writer enforces exactly the agreed write,
records lineage-only Sources, checks revisions read outside the
transaction, and reports cascaded groups. Plugins also get dedicated
SQLite storage, Server embedding models, Source Definitions submitted as
observations, and their own routes under /v1/plugins/{name}/api.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every knowledge base is a Scope the plugin creates and maps in its own
storage, so callers see knowledge bases and documents only. Uploads keep
their bytes by content digest and submit a Source recording the digest;
generation chunks and embeds the text with the Server's model, or a
deterministic hash embedding when none is configured, and writes the
document Artifact. Search fuses keyword and vector rankings across the
knowledge bases a caller can read. Plugin Source manifests now register
with their schema aliases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…model

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and model generation

- POST /v1/scopes/{scope_id}/artifacts accepts any loaded plugin family through a
  CreatePluginArtifactRequest branch; built-in names keep their discriminated
  validation and the plugin's create_artifact writes revision one.
- POST /v1/scopes/{scope_id}/sources accepts Source types that plugins define; the
  plugin host validates the input, resolves and stores it like a remote observation.
- ctx.models.generate calls the Server's generation model with chat messages.
- Plugin routes may declare max_body_bytes under the deployment ceiling
  POWERCONTEXT_SERVER_PLUGIN_API_MAX_BODY_BYTES, which also replaces the general
  HTTP body limit for plugin routes.
- Plugins may declare pages: the Dashboard frames them in a sandboxed iframe and
  forwards only same-origin, session-bound requests to the plugin's own routes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…owledge base plugin

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… in the knowledge base plugin

Uploads wait for a parser unless the knowledge base has a default; processing a
batch submits one Source per document that records the file digest and parser.
Chunk sets are content-addressed and keyed by parser profile; vectors are a
derived index per embedding profile. Users can view chunks of any revision, edit
them into a new revision, restore a revision, and reparse with another parser.
PDF text is extracted page by page with pypdf, which joins the dev group.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… parser

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ne click

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A chunk edit is now a kb-chunk-edit Source that records the editor, the edited
revision, and the saved chunk set. Generation applies it only if the document is
still at that revision, so the new revision's provenance names the edit. Uploads
and edits share one request Projection, which moves kb-document to version 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Inputs keeps projection as the default for every Source type and adds
projections to name a different Projection per type; every type needs one.
The knowledge base example now receives uploads and chunk edits in their own
Projections instead of a merged request model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the knowledge base example separate

Plugin pages, page forwarding, route body limits, and model generation are now
tested with a small test-owned plugin, so the framework does not depend on an
example. The knowledge base example and its pypdf dev dependency move to their
own branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e RFC states

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s, definitions, and host startup

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ilities

The family registry is process-wide, so families registered by other plugin
managers or by plugin tests in the same process leaked into /v1/capabilities.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jasper-yl

Copy link
Copy Markdown
Owner Author

Closing: superseded by oceanbase#2616 and oceanbase#2660, both merged upstream. The branch is kept.

@jasper-yl jasper-yl closed this Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant