用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/AUTO-MAS-Project/skills --skill mas-plugin-module命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | mas-plugin-module |
| description | 用于新增、修改或审查 AUTO-MAS 插件模块,包括插件管理/市场 UI、插件页面扩展、插件声明与实例、声明式 HTTP/WS、Script Adapter、动态 Schema 表单及插件运行链。 |
统一插件从包声明、发现与实例化,到前端展示、服务暴露、脚本类型注册和生命周期执行的实现方式。优先复用现有注册表、宿主页面和 Schema 表单,不为单个插件复制平台能力。
遇到以下任务时使用本 Skill:
ScriptAdapterPlugin 注册动态脚本类型;若任务是适配一个外部自动化脚本项目,先用 mas-script-specialized-adapter 完成脚本架构问诊;本 Skill 只约束其插件平台接入部分。
涉及插件页面声明、iframe、Custom Element、前端 Manifest、宿主 API、开发模式或 UI 生命周期时,必须先阅读 插件声明式 UI 指南。涉及 Schema 表单控件、字段属性、布局、校验、动态选项或动作时,必须阅读 声明式 Schema UI 元素全集。
| 层 | 主要位置 | 职责 |
|---|---|---|
| 插件包 | plugins/<plugin>/ | pyproject.toml Entry Point、插件类、默认实例、插件专属 Schema/运行逻辑 |
| 插件平台 | app/plugins/ | 发现加载、实例生命周期、Context 门面、服务/事件/缓存、前端资源、声明式服务 |
| 管理 API | app/api/plugins.py | 插件发现、安装、实例增删改、启停、前端资源 |
| 服务网关 | app/api/plugin_gateway.py | 将插件声明的 HTTP/WS 统一分发到 /plugin/** |
| 页面注册 | app/core/page_registry.py | 校验、排序和注销主程序/插件页面声明 |
| 脚本注册 | app/core/script_types.py | 动态 ScriptTypeProvider 注册表与 owner 归属 |
| 宿主存储 | app/models/plugin_script_config.py | 用稳定容器保存动态脚本和用户配置 |
| 表面 | 主要位置 | 模式 |
|---|---|---|
| 插件管理 | frontend/src/views/Plugin.vue | 固定宿主页面;管理实例、状态、配置与布局 |
| 插件市场 | frontend/src/views/PluginMarket.vue | 固定宿主页面;展示、安装和更新插件 |
| 插件菜单页 | PluginPageHost.vue / PluginElementHost.vue | 由页面声明选择 iframe 或 Custom Element |
| 插件脚本编辑 | EditView/Script/PluginScriptEdit.vue | 注册表 + Schema 驱动通用表单 |
| 插件用户编辑 | EditView/User/PluginUserEdit.vue | 注册表 + Schema 驱动通用表单 |
| 动态路由 | router/pageDeclarations.ts | 拉取声明、排序、按 renderer 生成路由 |
插件管理和市场是平台能力,保留在主前端中。插件只能提供数据和动作,不复制管理页面。
完整字段契约、renderer 选型、Manifest、宿主 API、开发模式和排错方法见 插件声明式 UI 指南。
通过 ctx.page.register(...) 声明页面。核心字段如下:
ctx.page.register(
id="example-page",
path="/example",
title="示例页面",
menu_label="示例",
icon="app",
renderer="iframe", # component | iframe | custom-element
url="/plugin/example/page",
section="main", # main | bottom | dev
order=100,
)
约束:
id 与 path 必须稳定且唯一,path 使用绝对路径;iframe 或 custom-element;component 仅能引用主程序已注册组件;iframe 必须提供 url;相对 URL 会指向后端地址;custom-element 必须能解析 frontend_plugin、element_tag 和前端资源;section 只使用 main、bottom、dev,顺序由 order 决定;生产资源放在插件 Python 包的 frontend/,声明 frontend/manifest.json:
{
"version": 1,
"renderer": "custom-element",
"entry": "frontend/index.js",
"style": ["frontend/index.css"],
"elements": [{ "tag": "auto-mas-example" }]
}
renderer 当前仅支持 custom-element;entry、style 必须位于 frontend/,禁止绝对路径、空段、. 与 ..;frontend-src/plugin.frontend.dev.json,仅在 AUTO_MAS_DEV=1 生效;localhost、127.0.0.1、::1;/api/plugins/assets/... 提供,不自行拼接本地文件 URL。动态脚本类型默认使用 PluginScriptEdit.vue 与 PluginUserEdit.vue:
editor_kind="schema" 使用通用 Schema 编辑器;editor_kind="plugin:<key>" 表示归属插件,可响应插件 HMR;builtin:<kind> 仅用于确有复杂交互、通用 Schema 无法表达的主程序专页;frontend/src/api/ 生成文件。插件使用 Python Entry Point:
[project.entry-points."auto_mas.plugins"]
example = "example.plugin:Plugin"
插件模块可声明默认实例:
DEFAULT_INSTANCE = {
"name": "示例插件",
"enabled": True,
"config": {},
}
系统插件可额外使用稳定 id、system=True、locked=True。enabled 必须是布尔值,config 必须是对象。
class Plugin:
def __init__(self, ctx):
self.ctx = ctx
async def on_start(self) -> None: ...
async def on_stop(self, reason: str) -> None: ...
async def on_unload(self) -> None: ...
插件只通过 PluginContext 使用受控能力:
ctx.config:实例配置;ctx.logger / ctx.log:日志;ctx.event:事件;ctx.service:provides、needs、wants 服务依赖;ctx.server:HTTP、WS 与前端动作;ctx.page:页面声明;ctx.runtime / ctx.runtime_api:主程序授权能力;ctx.cache:插件缓存。不要从插件直接修改主 FastAPI router、Vue router 或全局注册表私有状态。
普通插件配置由 schema.py、schema.json 或插件模块内 Config 提供,平台按 Pydantic 规则加载和校验。字段至少声明 type,按需使用:
required、nullable、description;constraints;size:1/1、1/2、1/3、2/3、1/4、3/4 或语义尺寸;{ "label": ..., "value": ... }。已知结构用明确类型和分组;只在未知外部配置的兼容边界使用 dict[str, Any]。Schema 不执行文件、网络、进程或调度逻辑。
插件通过 Context 注册:
self.ctx.server.http("/example/items", self.list_items, methods=("GET", "POST"))
self.ctx.server.websocket("/example/events", self.on_message)
外部路径统一为 /plugin/example/...。
/api/plugins/** 只负责平台级插件与实例管理;/plugin/** 只负责插件自行声明的业务服务;PluginHttpRequest,明确读取 json、query、headers;PluginHttpResponse;code、status、message,数据放 data;/api/scripts/** 的旧兼容端点。脚本型插件继承 ScriptAdapterPlugin,实现 build_script_adapters():
ScriptAdapterDefinition(
type_key="Example",
display_name="示例脚本",
script_model=ExampleConfig,
user_model=ExampleUserConfig,
hooks_factory=ExampleHooks,
supported_modes=("AutoProxy",),
icon="General",
editor_kind="schema",
metadata={"source": "example"},
)
声明规则:
type_key 全局唯一且稳定;display_name 面向用户;script_model 与 user_model 必须同时提供;或同时提供 script_groups 与 user_groups,两套方式不可混用;supported_modes 必须有对应 hooks 实现,不声明空能力;on_start() 以 instance_id 为 owner 注册,on_stop()、on_unload() 按 owner 注销;check、prepare、finalize、on_crash 与各运行模式,不把执行循环放进 API。动态脚本持久化统一使用:
PluginScriptConfig:Meta.PluginTypeKey、Info.Name、PluginData.Config、UserData;PluginUserConfig:Meta.PluginTypeKey、Info.Name、PluginData.Config。PluginScriptConfig 是稳定的存储容器,Meta.PluginTypeKey 才是真实业务类型。前端与后端都必须据此恢复 provider;禁止用容器类名冒充业务类型。表单态与 JSON 存储态通过 codec 转换,不让 UI 直接操作宿主 JSON 字符串。
auto_mas.plugins Entry Point 发现插件包;PluginContext 并启动插件;on_start() 注册页面、服务、事件或 Script Adapter;ScriptTypeProvider;editor_kind 打开通用或专用编辑器;PluginScriptConfig / PluginUserConfig;Meta.PluginTypeKey 找到 provider,创建 manager 与 hooks 执行;DEFAULT_INSTANCE 字段合法且默认行为安全;PluginContext 使用平台能力,模块职责没有越界;id/path 唯一,renderer 所需字段齐全,资源路径安全;ctx.server 注册并使用 /plugin/**,管理 API 未混入插件业务;PluginTypeKey 在 API、前端、持久化与调度链中一致;app/api/plugins.py;type_key;/api/scripts/** 与新 /plugin/** 接口;Master entrypoint for MAS engineering standards and code conventions. Use when a task needs consistent conventions across code standards, schema naming, module boundaries, function design, API contracts, or data modeling, and route the work to one or more MAS sub-skills.
Guide specialized AUTO-MAS integration by script frontend architecture (MAA / SRC / MXU-line like MaaEnd / MFAA-line like M9A / ok-script like Okww). Before coding: run script-architecture intake (prefer repo URL). Surfaces first, then backend. Code norms: references/adapter-code-norms.md.
Define backend API contract standards for FastAPI services. Use when adding or refactoring HTTP/WebSocket endpoints in app/api, designing request/response schemas in app/models/schema.py, standardizing status/error contracts, and maintaining backward compatibility for clients.
基于 SOC 职业分类