@x-otto/plugin 0.1.0-alpha.1 → 0.1.0-alpha.10
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 +58 -45
- package/dist/index.d.ts +886 -76
- package/dist/index.js +2 -2
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -1,90 +1,103 @@
|
|
|
1
1
|
# @x-otto/plugin
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Parsing of the plugin manifest (`otto-plugin.json`), directory discovery, contribution vocabulary, trust model, and author SDK — the "read-only, no execution" foundation layer of the plugin system.
|
|
4
4
|
|
|
5
|
-
`@x-otto/plugin`
|
|
5
|
+
`@x-otto/plugin` is the protocol and contract layer of otto's plugin system. A plugin = a directory + an
|
|
6
|
+
`otto-plugin.json` file, which contributes capabilities via subdirectories such as `skills/`, `agents/`, `commands/`,
|
|
7
|
+
and `.mcp.json` (consumed by the various axis loaders in `@x-otto/coding`).
|
|
6
8
|
|
|
7
|
-
##
|
|
9
|
+
## Core Features
|
|
8
10
|
|
|
9
|
-
|
|
|
11
|
+
| Module | Function |
|
|
10
12
|
|------|------|
|
|
11
|
-
| `parsePluginManifest` |
|
|
12
|
-
| `discoverPlugins` |
|
|
13
|
-
| `topoSortPlugins` |
|
|
14
|
-
| `filterEngineCompatible` |
|
|
15
|
-
| `definePlugin` |
|
|
16
|
-
|
|
|
17
|
-
| `PluginI18nRegistry` |
|
|
18
|
-
|
|
|
13
|
+
| `parsePluginManifest` | Parses the manifest (fail-closed + lenient hybrid) |
|
|
14
|
+
| `discoverPlugins` | Scans the three-tier plugin directory structure (project/repository/user) |
|
|
15
|
+
| `topoSortPlugins` | Topological sort + transitive removal of missing dependencies + cycle detection |
|
|
16
|
+
| `filterEngineCompatible` | Filters by engine ABI version compatibility |
|
|
17
|
+
| `definePlugin` | Plugin-author SDK (equivalent to Vite's defineConfig) |
|
|
18
|
+
| Trust Model | Boolean trust + per-high-risk-capability grants |
|
|
19
|
+
| `PluginI18nRegistry` | Internationalization entry registry (parallel to TUI STR) |
|
|
20
|
+
| Contribution Point System | Parsing and dispatch of action/menu/context-key contribution points |
|
|
19
21
|
|
|
20
|
-
##
|
|
22
|
+
## Installation
|
|
21
23
|
|
|
22
24
|
```bash
|
|
23
25
|
pnpm add @x-otto/plugin
|
|
24
26
|
```
|
|
25
27
|
|
|
26
|
-
##
|
|
28
|
+
## Usage
|
|
27
29
|
|
|
28
30
|
```ts
|
|
29
|
-
//
|
|
31
|
+
// Discover installed plugins
|
|
30
32
|
import { discoverPlugins } from '@x-otto/plugin'
|
|
31
33
|
const plugins = discoverPlugins({ cwd, homedir, disabled: ['plugin-x'] })
|
|
32
34
|
|
|
33
|
-
//
|
|
35
|
+
// Parse a single manifest
|
|
34
36
|
import { parsePluginManifest } from '@x-otto/plugin'
|
|
35
37
|
const manifest = parsePluginManifest(content, path) // null on fail
|
|
36
38
|
|
|
37
|
-
//
|
|
39
|
+
// Author-defined plugin
|
|
38
40
|
import { definePlugin } from '@x-otto/plugin'
|
|
39
41
|
export default definePlugin((ctx) => ({
|
|
40
42
|
hooks: {
|
|
41
43
|
preToolUse: (ctx) => ctx.toolName === 'write' ? { decision: 'deny' } : { decision: 'allow' },
|
|
44
|
+
// 通知出站交付(turn_complete/error/approval_required/input_required 归一后触发)。
|
|
45
|
+
// 例:把 otto 通知转发到自己的推送渠道。
|
|
46
|
+
onNotification: (ctx) => {
|
|
47
|
+
console.log(`[${ctx.notification_type}] ${ctx.message}`)
|
|
48
|
+
},
|
|
42
49
|
},
|
|
43
50
|
}))
|
|
44
51
|
```
|
|
45
52
|
|
|
46
|
-
##
|
|
53
|
+
## Directory Overview
|
|
47
54
|
|
|
48
55
|
```
|
|
49
56
|
src/
|
|
50
57
|
manifest.ts # PluginManifest zod schema + parsePluginManifest
|
|
51
|
-
discovery.ts # discoverPlugins
|
|
52
|
-
contributions.ts # PluginContributions
|
|
53
|
-
contribution-points.ts #
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
contribution-
|
|
58
|
+
discovery.ts # discoverPlugins three-tier directory scanning
|
|
59
|
+
contributions.ts # PluginContributions unified contribution vocabulary type
|
|
60
|
+
contribution-points.ts # contribution point registry (POINT constants)
|
|
61
|
+
points-extension.ts # per-domain contribution point constants
|
|
62
|
+
points-shell.ts # per-domain contribution point constants
|
|
63
|
+
contribution-resolver.ts # contribution point resolver
|
|
64
|
+
context-keys.ts # context key evaluation
|
|
65
|
+
contribution-dispatch.ts # contribution point dispatcher
|
|
57
66
|
sdk.ts # definePlugin + PluginModule/PluginContext/PluginHooks
|
|
58
|
-
dependency-graph.ts # topoSortPlugins
|
|
59
|
-
engine-compat.ts #
|
|
60
|
-
api-version.ts # PLUGIN_API_VERSION
|
|
61
|
-
|
|
62
|
-
trust
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
dependency-graph.ts # topoSortPlugins topological sort
|
|
68
|
+
engine-compat.ts # engine version compatibility gate
|
|
69
|
+
api-version.ts # PLUGIN_API_VERSION constant
|
|
70
|
+
capabilities.ts # PLUGIN_CAPABILITIES + HIGH_RISK_CAPABILITIES risk classification (single source)
|
|
71
|
+
plugin-trust.ts # trust model (executable surface scan + per-capability grant)
|
|
72
|
+
trust-store.ts # trust allowlist persistence
|
|
73
|
+
i18n-registry.ts # internationalization entry registry
|
|
74
|
+
input/ # sigil input system (builtin/file/registry)
|
|
65
75
|
index.ts
|
|
66
|
-
tests/ #
|
|
76
|
+
tests/ # test files
|
|
67
77
|
```
|
|
68
78
|
|
|
69
|
-
##
|
|
79
|
+
## Key Types
|
|
70
80
|
|
|
71
|
-
- `PluginManifest
|
|
72
|
-
- `PluginContributions
|
|
73
|
-
- `PluginModule
|
|
74
|
-
- `PluginContext
|
|
75
|
-
- `DiscoveredPlugin
|
|
81
|
+
- `PluginManifest`: the plugin manifest (id/name/scripts/capabilities/engines/contributes)
|
|
82
|
+
- `PluginContributions`: unified contribution vocabulary (commands/agents/skills/mcp/providers/oauth/panels/actions/menus/...)
|
|
83
|
+
- `PluginModule`: the runtime module of a code plugin (hooks/tools/monitors/providerFactories/services/...)
|
|
84
|
+
- `PluginContext`: the context injected with factories at load time
|
|
85
|
+
- `DiscoveredPlugin`: a discovery result (id/dir/manifest/scope)
|
|
76
86
|
|
|
77
|
-
##
|
|
87
|
+
## Trust Model
|
|
78
88
|
|
|
79
|
-
|
|
89
|
+
High-risk capability list (`HIGH_RISK_CAPABILITIES`, derived in `capabilities.ts` from the per-capability risk
|
|
90
|
+
classification): provider / tools / tui.renderer / network / wire-protocol / a2ui.component / panel.backend /
|
|
91
|
+
mcp.server / input.resolver / a2ui.renderer / agent.dispatch / service / session.read / llm.complete / user.ask.
|
|
92
|
+
When an already-trusted plugin is upgraded and declares one of these capabilities for the first time, it must be
|
|
93
|
+
re-confirmed.
|
|
80
94
|
|
|
81
|
-
##
|
|
95
|
+
## Dependencies
|
|
82
96
|
|
|
83
|
-
- Internal: `@x-otto/env`, `@x-otto/interchange`, `@x-otto/provider`, `@x-otto/shared`
|
|
97
|
+
- Internal: `@x-otto/env`, `@x-otto/hook-contracts`, `@x-otto/interchange`, `@x-otto/provider`, `@x-otto/shared`
|
|
84
98
|
- External: `zod`, `semver`
|
|
85
99
|
|
|
86
|
-
##
|
|
100
|
+
## Related
|
|
87
101
|
|
|
88
102
|
- [Architecture](./ARCHITECTURE.md)
|
|
89
|
-
-
|
|
90
|
-
- `@x-otto/extension`(re-export 本包 SDK 作为 extension 作者统一入口)
|
|
103
|
+
- `@x-otto/extension` (re-exports this package's SDK as the unified entry point for extension authors)
|