Skip to content

Define a source layout for first-party Server plugins and migrate knowledge-base #2966

In review

Description

@Zxf-xufeng

Motivation

The knowledge-base Server plugin has two development roots. Its Python implementation and installable Dashboard assets live in plugins/knowledge-base/, while the React application, lockfile and build scripts live in frontend/knowledge-base/. A contributor has to find both trees to change one feature. Simply moving the npm project into the directory that Server loads would also make development files and potentially node_modules part of the plugin fingerprint and runtime snapshot.

Proposed repository convention

Keep the implementation of each first-party Server plugin under one repository root. For plugins with a separately built Dashboard, use this layout, starting with knowledge-base:

plugins/knowledge-base/
  README.md
  frontend/                 # React/TypeScript sources, lockfile and build tooling
  runtime/                  # contents to install under the plugin name
    plugin.py
    pc_knowledge_base/
    ui/                     # built HTML, JavaScript and CSS served by Server

Apply the same source/runtime separation to future first-party Server plugins with development-only build tooling. A small Python-only plugin can keep plugin.py directly in its named directory when that directory is already suitable for installation. Host integrations and the core Dashboard have their own packaging conventions.

The installed layout stays <configured-plugins-dir>/knowledge-base/plugin.py. Copy the contents of runtime/ into the named destination. Installing a directory named runtime would give it the wrong identity. Users currently pointing Server directly at the checkout's plugins/ need a documented staging step. Keep plugin discovery and fingerprinting in the framework as they are.

Acceptance criteria

  • Move the knowledge-base frontend and Python runtime under the proposed root. The frontend build writes the checked-in assets to runtime/ui/. Installing frontend dependencies or editing unbuilt frontend sources leaves the installable directory untouched.
  • Document the convention and its scope in the English and Chinese plugin development guides. Update the knowledge-base guides and README with working build and installation examples, including the transition for source-checkout users.
  • Update repository path references, test fixtures, packaging/tooling configuration, CI change detection, npm caching and the generated-asset drift check. Changes to either half of the plugin should select its existing checks.
  • Stage the plugin into a clean configured plugin directory and start a real Server. Verify that it discovers knowledge-base, serves the Dashboard entry and assets, and handles an existing plugin API request with the current plugin identity. The staged installation must run without Node.js or frontend development dependencies.

Related: knowledge-base implementation #2658 and the Server plugin development guide.

Activity

  1. added
    enhancement
    on Dec 2, 2026
  2. Lumea-art commented on Dec 2, 2026

    @Lumea-art
    Contributor

    I'd like to take this. Plan:

    1. Move frontend/knowledge-base/ to plugins/knowledge-base/frontend/ and the installable Python/UI tree to plugins/knowledge-base/runtime/; the frontend build writes runtime/ui/.
    2. Update the npm/CI paths, cache and generated-asset drift check, type-check include/exclude, licence path, evaluation import path and e2e staging helpers. Staging copies the contents of runtime/ into <plugins-dir>/knowledge-base so the plugin identity and fingerprint stay unchanged.
    3. Update the plugin-development guides (en/zh) with the source/runtime convention and the knowledge-base guide/README with staging instructions for checkout users.
    4. Verify a clean staged install with a real Server and no Node/frontend dependencies: discovery, Dashboard entry/assets, and an existing plugin API request.
  3. moved this from Todo to In progress in PowerContexton Dec 2, 2026
  4. self-assigned this
    on Dec 2, 2026
  5. added
    module:knowledge-base
    on Dec 2, 2026
  6. hireview001 commented on Dec 2, 2026

    @hireview001
    Collaborator

    This issue belongs to the Knowledge base module. @Zxf-xufeng, please lead follow-up, with support from @Alanxtl. Please provide a substantive response within 72 hours of issue creation, outlining the proposed disposition, any additional information needed, or the next investigation steps. After sufficient discussion and agreement on the scope and acceptance criteria, a contributor who volunteers to take it on can undertake implementation.

  7. jasper-yl commented on Dec 3, 2026

    @jasper-yl
    Contributor

    @Zxf-xufeng @frf12

    I agree with the goal: one root per first-party plugin. Before the runtime/ layout becomes a convention in the plugin guide, I'd like to offer to solve this in the framework instead, and ask which way you prefer.

    Proposal: a .pluginignore file in the plugin directory

    The loader counts every file under the plugin directory except __pycache__ (version_files in builtin/plugins/manifest.py), which is why development files cannot live there today. I would let a plugin list top-level entries that discovery, fingerprinting and the version snapshot skip:

    plugins/knowledge-base/
      plugin.py
      pc_knowledge_base/
      ui/
      README.md
      .pluginignore        # frontend/  tests/  evaluation/
      frontend/            # sources, lockfile, build tooling, node_modules
      tests/
      evaluation/
    

    Rules, kept deliberately narrow:

    • Entries are top-level names only, with no glob patterns.
    • .pluginignore itself counts toward the fingerprint, so changing it produces a new version.
    • plugin.py cannot be ignored.

    What this changes compared with the runtime/ layout

    • The install step stays cp -R plugins/knowledge-base <plugins-dir>/knowledge-base. The "copy the contents of runtime/ into a named directory" step has needed three review rounds in refactor(knowledge-base): separate frontend sources from the installable runtime #2967 to get right (missing plugin name, an unset variable resolving to /knowledge-base, build order).
    • Pointing POWERCONTEXT_SERVER_PLUGINS_DIR at the checkout's plugins/ keeps working for local development. At 42cc8b872 a real Server reports failed: the plugin directory has no plugin.py for that setup.
    • No subdirectory name has to be chosen.
    • Third-party plugin authors get the same mechanism for their own repositories.

    Tests and evaluation belong in the same root

    I'd also like the root to hold tests/knowledge_base/ and evaluation/knowledge_base/, under either layout:

    • The unit tests import pc_knowledge_base through sys.path and use no shared fixtures from tests/.
    • The evaluation measures this plugin's parser and needs the plugin's own extras, while the other suites under evaluation/ measure core behavior.

    The e2e tests can stay in tests/e2e/, since they use the shared Server helper there.

    Cost and timing

    This changes the loading contract. I will open the framework PR within 24 hours of a go-ahead, including the plugin interfaces RFC, the plugin guides in both locales, and loader tests. The knowledge-base move can then be a rebase of #2967 by @Lumea-art or a follow-up from me, whichever you prefer.

    If you would rather merge #2967 first, two requests:

    1. Rename runtime/. "Runtime" already has a meaning in this project (POWERCONTEXT_SERVER_RUNTIME, collect Runtimes), so plugins/knowledge-base/runtime/ reads as the plugin's Runtime implementation. plugin/ would say what the directory is.
    2. Document the development workflow. A symbolic link <plugins-dir>/knowledge-base -> plugins/knowledge-base/runtime restores it: at 42cc8b872 a real Server loads the plugin through the link and picks up an edit in the checkout at the next scan without a restart.

    In that case I'd also keep the layout description in the plugin's own README rather than in the plugin-writing guide, which addresses all plugin authors.

    Which do you prefer?


    我同意目标:每个一方插件一个根目录。在 runtime/ 布局写进插件指南成为约定之前,我想提出改由框架侧解决,并征求你们的意见。

    提议:在插件目录里放一个 .pluginignore,列出的顶层条目不参与发现、指纹和版本快照。规则保持很窄:只支持顶层条目名、不支持通配;.pluginignore 自身计入指纹;plugin.py 不可忽略。

    与 runtime/ 布局相比:安装命令不变,仍是整目录拷贝("拷 runtime/ 的内容到命名目录"这一步在 #2967 里已经改了三轮);本地开发仍可把插件目录直接指向 checkout 的 plugins/(在 42cc8b872 上这样做,真实 Server 报 failed: the plugin directory has no plugin.py);不需要给子目录起名;第三方插件作者也能用同一机制。

    测试和评测也应在同一个根目录下:无论采用哪种布局,我都希望把 tests/knowledge_base/ 和 evaluation/knowledge_base/ 收进来。单元测试只通过 sys.path 导入 pc_knowledge_base,不依赖 tests/ 的公共夹具;评测衡量的是这个插件的解析器并依赖插件自己的 extra,而 evaluation/ 下其他套件衡量的是核心行为。e2e 测试依赖公共的 Server 辅助模块,可以留在 tests/e2e/。

    代价与时间:这会改动加载契约。得到同意后我会在 24 小时内提框架 PR,包含插件接口 RFC、中英文指南和加载器测试。之后知识库的搬迁可以由 @Lumea-art 在 #2967 上 rebase,也可以由我跟进,看你们方便。

    如果更希望先合 #2967,有两点请求:一是给 runtime/ 换个名字,Runtime 在本项目里已有含义,建议 plugin/;二是在文档里写明开发方式,用符号链接指向该子目录即可(在 42cc8b872 上已用真实 Server 验证:通过链接可加载,checkout 里的修改在下一次扫描生效,无需重启)。另外建议把布局说明放在插件自己的 README,而不是面向所有插件作者的编写指南。

    你们倾向哪种?

  8. Zxf-xufeng commented on Dec 3, 2026

    @Zxf-xufeng
    MemberAuthor

    @jasper-yl @frf12 @Lumea-art

    I'm leaning toward Option A (framework-side .pluginignore).

    Solving this in the loader keeps direct checkout development and whole-directory installation working, avoids inventing a one-size-fits-all subdirectory convention, and gives third-party plugin repositories the same mechanism. The narrow rule set (top-level names only, no globs, .pluginignore included in the fingerprint, plugin.py non-ignorable) looks clean and easy to audit.

    Three details to align on:

    1. Deployment note on node_modules: even when .pluginignore excludes frontend/ from discovery, fingerprinting and snapshots, a plain cp -R from a dev checkout that has run npm ci will still copy node_modules to disk. Please document copying from a clean checkout or excluding node_modules in the installation instructions.
    2. Keep layout conventions per-plugin: .pluginignore should be an optional capability rather than a mandatory source layout. The plugin-writing guide should document the installed contract and .pluginignore behavior, while plugins/README.md stays a simple directory index and each plugin's own README documents its layout and build/install steps.
    3. Stage the tests/ and evaluation/ move separately: I agree that plugin-only unit tests (tests/knowledge_base/) and evaluation (evaluation/knowledge_base/) belong under plugins/knowledge-base/ (with shared-Server e2e tests staying in tests/e2e/). Let's handle that move in a separate follow-up PR after .pluginignore and the frontend/ relocation land, so each PR stays focused.

    @frf12 @Lumea-art What do you think? If we're aligned on this direction, @jasper-yl can go ahead with the .pluginignore framework PR, and we can coordinate with @Lumea-art on how best to carry #2967 forward.


    我比较倾向 方案 A(框架侧 .pluginignore)。

    在加载器侧解决可以保留 checkout 直接开发和整目录安装,不需要强行约定单一子目录结构,也能让第三方插件仓库复用同一机制。收窄后的规则(仅顶层条目名、无 glob、.pluginignore 计入指纹、plugin.py 不可忽略)边界清晰,易于维护。

    补充三点希望一起对齐的细节:

    1. node_modules 拷贝提示:即使 .pluginignore 让 Server 跳过 frontend/,在执行过 npm ci 的开发目录直接 cp -R 仍会把 node_modules 拷到磁盘上,安装文档里需要提醒从干净检出拷贝或排除 node_modules。
    2. 布局按插件自治:.pluginignore 作为可选能力而非强制目录规范;插件开发指南重点说明安装态契约和 .pluginignore 规则,plugins/README.md 保持简洁目录索引,具体子目录与构建/安装步骤放在各插件自己的 README。
    3. tests/ 与 evaluation/ 拆成后续独立 PR:同意将插件独有的单元测试(tests/knowledge_base/)和评测(evaluation/knowledge_base/)迁入 plugins/knowledge-base/(依赖公共 Server 夹具的 e2e 留在 tests/e2e/),但在 .pluginignore 和 frontend/ 迁移合入后另开 PR 推进,控制单次改动范围。

    @frf12 @Lumea-art 你们怎么看?如果大家对这个方向达成一致,再请 @jasper-yl 提 .pluginignore 的框架 PR,之后和 @Lumea-art 一起商量 #2967 怎么衔接。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementmodule:knowledge-base

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions