@x-otto/plugin 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # @otto/plugin
2
+
3
+ > Plugin 清单(`otto-plugin.json`)的解析、目录发现、贡献词表、信任模型与作者 SDK——RFC-044 插件体系的「只读不执行」地基层。
4
+
5
+ `@otto/plugin` 是 otto 插件系统的协议层与契约层。一个插件 = 一个目录 + 一份 `otto-plugin.json`,其目录下用 `skills/`、`agents/`、`commands/`、`.mcp.json` 等子目录贡献能力(由消费方 `@otto/coding` 的各轴 loader 消费)。
6
+
7
+ ## 核心功能
8
+
9
+ | 模块 | 功能 |
10
+ |------|------|
11
+ | `parsePluginManifest` | 解析 manifest(fail-closed + lenient 混合) |
12
+ | `discoverPlugins` | 扫描三层插件目录(项目/仓库/用户) |
13
+ | `topoSortPlugins` | 拓扑排序 + 缺依赖传递剔除 + 环检测 |
14
+ | `filterEngineCompatible` | 引擎 ABI 版本兼容过滤 |
15
+ | `definePlugin` | 插件作者 SDK(Vite defineConfig 对等物) |
16
+ | 信任模型 | 布尔信任 + 逐高危能力授予 |
17
+ | `PluginI18nRegistry` | 国际化条目注册表(与 TUI STR 平行) |
18
+ | 贡献点系统 | 动作/菜单/context-key 贡献点解析与派发 |
19
+
20
+ ## 安装
21
+
22
+ ```bash
23
+ pnpm add @otto/plugin
24
+ ```
25
+
26
+ ## 用法
27
+
28
+ ```ts
29
+ // 发现已安装插件
30
+ import { discoverPlugins } from '@otto/plugin'
31
+ const plugins = discoverPlugins({ cwd, homedir, disabled: ['plugin-x'] })
32
+
33
+ // 解析单一 manifest
34
+ import { parsePluginManifest } from '@otto/plugin'
35
+ const manifest = parsePluginManifest(content, path) // null on fail
36
+
37
+ // 作者定义插件
38
+ import { definePlugin } from '@otto/plugin'
39
+ export default definePlugin((ctx) => ({
40
+ hooks: {
41
+ preToolUse: (ctx) => ctx.toolName === 'write' ? { decision: 'deny' } : { decision: 'allow' },
42
+ },
43
+ }))
44
+ ```
45
+
46
+ ## 目录概览
47
+
48
+ ```
49
+ src/
50
+ manifest.ts # PluginManifest zod schema + parsePluginManifest
51
+ discovery.ts # discoverPlugins 三层目录扫描
52
+ contributions.ts # PluginContributions 统一贡献词表类型
53
+ contribution-points.ts # 贡献点注册表(POINT 常量)
54
+ contribution-resolver.ts # 贡献点解析器
55
+ context-keys.ts # 上下文键求值
56
+ contribution-dispatch.ts # 贡献点派发器
57
+ sdk.ts # definePlugin + PluginModule/PluginContext/PluginHooks
58
+ dependency-graph.ts # topoSortPlugins 拓扑排序
59
+ engine-compat.ts # 引擎版本兼容门
60
+ api-version.ts # PLUGIN_API_VERSION 常量
61
+ plugin-trust.ts # 信任模型(HIGH_RISK_CAPABILITIES)
62
+ trust-store.ts # 信任白名单持久化
63
+ i18n-registry.ts # 国际化条目注册表
64
+ input/ # sigil 输入系统(builtin/file/registry)
65
+ index.ts
66
+ tests/ # 测试文件
67
+ ```
68
+
69
+ ## 关键类型
70
+
71
+ - `PluginManifest`:插件清单(id/name/scripts/capabilities/engines/contributes)
72
+ - `PluginContributions`:统一贡献词表(commands/agents/skills/mcp/providers/oauth/panels/actions/menus/...)
73
+ - `PluginModule`:代码插件的运行时模块(hooks/tools/monitors/providerFactories/services/...)
74
+ - `PluginContext`:装载时注入工厂的上下文
75
+ - `DiscoveredPlugin`:发现结果(id/dir/manifest/scope)
76
+
77
+ ## 信任模型
78
+
79
+ 高危能力清单(`HIGH_RISK_CAPABILITIES`):provider / tools / tui.renderer / network / wire-protocol / a2ui.component / panel.backend / input.resolver / a2ui.renderer / agent.dispatch / service。已信任插件升级后首次声明这些能力必须重新确认。
80
+
81
+ ## 依赖
82
+
83
+ - Internal: `@otto/env`, `@otto/interchange`, `@otto/provider`, `@otto/shared`
84
+ - External: `zod`, `semver`
85
+
86
+ ## 相关
87
+
88
+ - [Architecture](./ARCHITECTURE.md)
89
+ - RFC-044 插件体系(D2 manifest/发现;R4 fail-closed、R6 source key、R7 层源覆盖)
90
+ - `@otto/extension`(re-export 本包 SDK 作为 extension 作者统一入口)