@xnetjs/plugins 0.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chris Smothers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,203 @@
1
+ # @xnetjs/plugins
2
+
3
+ Plugin system for xNet -- registry, sandboxed script execution, AI-powered script generation, and service integrations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @xnetjs/plugins
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - **Plugin registry** -- Register, enable/disable, and discover plugins
14
+ - **Extension system** -- `defineExtension()` for type-safe plugin definitions
15
+ - **Contribution types** -- Views, commands, slash commands, editor extensions, toolbar items, sidebar panels, property handlers, blocks, settings, schemas
16
+ - **Manifest validation** -- Validate plugin manifests before registration
17
+ - **Shortcut manager** -- Global keyboard shortcut registry
18
+ - **Middleware chain** -- Composable middleware for plugin operations
19
+ - **Extension context** -- Scoped API surface for plugins
20
+ - **Plugin/Script schemas** -- Plugins and scripts stored as Nodes
21
+ - **Sandboxed execution** -- Safe script execution with AST validation (acorn)
22
+ - **Script runner** -- Execute validated scripts in a restricted context
23
+ - **AI script generation** -- Generate scripts via Anthropic, OpenAI, or Ollama
24
+ - **Services** (Node.js only):
25
+ - Webhook emitter
26
+ - Service client (HTTP)
27
+ - Process manager
28
+ - Local API server
29
+ - MCP server (Model Context Protocol)
30
+
31
+ ## Usage
32
+
33
+ ### Plugin Registry
34
+
35
+ ```typescript
36
+ import { PluginRegistry, defineExtension, validateManifest } from '@xnetjs/plugins'
37
+
38
+ const registry = new PluginRegistry()
39
+
40
+ // Define a plugin extension
41
+ const myPlugin = defineExtension({
42
+ id: 'my-plugin',
43
+ name: 'My Plugin',
44
+ version: '1.0.0',
45
+ contributions: {
46
+ commands: [
47
+ {
48
+ id: 'my-command',
49
+ label: 'Do Something',
50
+ handler: () => {
51
+ /* ... */
52
+ }
53
+ }
54
+ ],
55
+ views: [{ id: 'my-view', label: 'Custom View', component: MyViewComponent }]
56
+ }
57
+ })
58
+
59
+ registry.register(myPlugin)
60
+ ```
61
+
62
+ ### Sandboxed Scripts
63
+
64
+ ```typescript
65
+ import { ScriptSandbox, ScriptRunner } from '@xnetjs/plugins'
66
+
67
+ // Validate and run user scripts safely
68
+ const sandbox = new ScriptSandbox()
69
+ const runner = new ScriptRunner(sandbox)
70
+
71
+ const result = await runner.run(
72
+ `
73
+ const items = context.query({ schema: 'myapp://Task' })
74
+ return items.filter(t => t.status === 'todo').length
75
+ `,
76
+ { context: extensionContext }
77
+ )
78
+ ```
79
+
80
+ ### AI Script Generation
81
+
82
+ ```typescript
83
+ import { ScriptGenerator } from '@xnetjs/plugins'
84
+
85
+ const generator = new ScriptGenerator({
86
+ provider: 'anthropic',
87
+ apiKey: process.env.ANTHROPIC_API_KEY
88
+ })
89
+
90
+ const script = await generator.generate(
91
+ 'Create a script that counts overdue tasks and sends a summary'
92
+ )
93
+ ```
94
+
95
+ ### Shortcut Manager
96
+
97
+ ```typescript
98
+ import { ShortcutManager } from '@xnetjs/plugins'
99
+
100
+ const shortcuts = new ShortcutManager()
101
+ shortcuts.register('mod+shift+t', () => openTaskPanel())
102
+ shortcuts.register('mod+/', () => openSlashMenu())
103
+ ```
104
+
105
+ ### Node.js Services
106
+
107
+ ```typescript
108
+ // Import from the /node subpath
109
+ import { MCPServer, WebhookEmitter, LocalAPIServer } from '@xnetjs/plugins/node'
110
+
111
+ // MCP server for AI tool integration
112
+ const mcp = new MCPServer(registry, store)
113
+ await mcp.start(3001)
114
+
115
+ // Webhook emitter for external integrations
116
+ const webhooks = new WebhookEmitter()
117
+ webhooks.on('node:created', 'https://example.com/webhook')
118
+
119
+ // Local API server for plugin HTTP access
120
+ const api = new LocalAPIServer(registry, store)
121
+ await api.start(3002)
122
+ ```
123
+
124
+ ## Architecture
125
+
126
+ ```mermaid
127
+ flowchart TD
128
+ subgraph Core["Plugin Core"]
129
+ Registry["PluginRegistry<br/><small>Register + discover</small>"]
130
+ Extension["defineExtension()<br/><small>Type-safe plugins</small>"]
131
+ Manifest["Manifest Validator"]
132
+ Middleware["MiddlewareChain"]
133
+ Context["ExtensionContext<br/><small>Scoped API</small>"]
134
+ end
135
+
136
+ subgraph Contributions["Contribution Types"]
137
+ Views["Views"]
138
+ Commands["Commands"]
139
+ Slash["Slash Commands"]
140
+ EditorExt["Editor Extensions"]
141
+ Toolbar["Toolbar Items"]
142
+ Sidebar["Sidebar Panels"]
143
+ PropHandlers["Property Handlers"]
144
+ Blocks["Blocks"]
145
+ Settings["Settings"]
146
+ Schemas["Schemas"]
147
+ end
148
+
149
+ subgraph Execution["Script Execution"]
150
+ Sandbox["ScriptSandbox<br/><small>AST validation</small>"]
151
+ Runner["ScriptRunner<br/><small>Restricted context</small>"]
152
+ AI["ScriptGenerator<br/><small>Anthropic/OpenAI/Ollama</small>"]
153
+ end
154
+
155
+ subgraph Services["Node.js Services"]
156
+ MCP["MCPServer"]
157
+ Webhooks["WebhookEmitter"]
158
+ API["LocalAPIServer"]
159
+ Process["ProcessManager"]
160
+ end
161
+
162
+ Registry --> Contributions
163
+ Registry --> Context --> Execution
164
+ AI --> Runner --> Sandbox
165
+ Registry --> Services
166
+ ```
167
+
168
+ ## Modules
169
+
170
+ | Module | Description |
171
+ | ----------------------------- | ------------------------------------- |
172
+ | `registry.ts` | Plugin registry |
173
+ | `types.ts` | Plugin, Extension, Contribution types |
174
+ | `manifest.ts` | Manifest validation |
175
+ | `contributions.ts` | Contribution type definitions |
176
+ | `shortcuts.ts` | Global shortcut manager |
177
+ | `middleware.ts` | Composable middleware chain |
178
+ | `context.ts` | Scoped extension context |
179
+ | `schemas/plugin.ts` | Plugin node schema |
180
+ | `schemas/script.ts` | Script node schema |
181
+ | `sandbox/sandbox.ts` | Script sandbox |
182
+ | `sandbox/runner.ts` | Script runner |
183
+ | `sandbox/ast-validator.ts` | AST validation (acorn) |
184
+ | `ai/generator.ts` | AI script generation |
185
+ | `ai/providers.ts` | LLM provider adapters |
186
+ | `services/mcp-server.ts` | MCP server (Node.js) |
187
+ | `services/webhook-emitter.ts` | Webhook emitter (Node.js) |
188
+ | `services/local-api.ts` | Local API server (Node.js) |
189
+ | `services/process-manager.ts` | Process manager (Node.js) |
190
+
191
+ ## Dependencies
192
+
193
+ - `@xnetjs/core`, `@xnetjs/data`
194
+ - `acorn` -- JavaScript AST parsing for sandbox validation
195
+ - Peer deps: `@tiptap/core`, `react`
196
+
197
+ ## Testing
198
+
199
+ ```bash
200
+ pnpm --filter @xnetjs/plugins test
201
+ ```
202
+
203
+ 8 test files covering registry, middleware, sandbox, shortcuts, AI, local API, webhooks, and MCP.