@eworkbase/sdk 0.1.1 → 0.2.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 DELETED
@@ -1,442 +0,0 @@
1
- # Workbase 插件开发指南
2
-
3
- 适用于 Workbase 0.4.x、插件 API 1。外部插件与内置插件使用同一 SDK、依赖调度、命令目录、工具准备和 UI 桥接。插件后端是受信任的本机 Node.js 代码;仅从公开的 `@eworkbase/plugin-*` npm 目录安装。包元数据校验不能把 Node 后端隔离成安全沙箱。
4
-
5
- ## 1. 安装和启用
6
-
7
- 1. 进入「仓库 → 插件管理」,刷新公开 npm 插件目录。包名必须为 `@eworkbase/plugin-<id>`。
8
- 2. 查看功能介绍、版本及依赖,点击「安装」,确认来源和固定版本。mise 负责下载、完整性检查和安装,不运行安装脚本。
9
- 3. 新安装的可选插件默认停用,开启开关后生效。依赖插件须分别安装并启用。
10
- 4. 环境尚未准备时进入工作区准备环境;缺少 Node 或业务工具的插件会显示 blocked。
11
- 5. 出现新版时点击「更新」,旧启用状态与配置保留。安装失败不覆盖旧声明;「移除」删除当前项目的包声明及启用引用,不删除其他项目使用的 mise 安装、配置或 workspace store。
12
-
13
- AI MCP、AI Rules、CodeGraph 为固定内置能力,始终启用,没有启停/卸载操作;版本由应用固定,也通过 mise npm 安装。OpenSpec 为可选插件,不随应用自动启用。桌面应用只携带 Node Bridge,插件业务代码和 UI 来自 npm。
14
-
15
- 项目共享目录如下:
16
-
17
- ```text
18
- .workbase/
19
- project.yaml # 可选插件启用状态
20
- plugin/
21
- team-provider/
22
- package.json # 固定 npm 名称、完整版本及 workbase 元数据
23
- config.yaml # 插件业务配置
24
- ```
25
-
26
- 安装、更新、移除及启停沿用配置发布事务,只发布本次涉及的路径。远端不可用时保留本地结果并提示待同步;其他成员同步项目后,通用加载流程会自动安装选定的同一版本,无需再次导入。不会追随 latest 自动升级。机器路径、node_modules、压缩包不写入项目。旧 `.workbase/plugins/<id>.yaml` 在新配置缺失时兼容读取,之后的写入使用新路径。
27
-
28
- 已经安装的固定版本可离线使用;未安装版本需要联网下载。刷新目录失败会保留当前项目记录及重试提示。目录使用 npm 的公开组织包接口,避免依赖搜索索引更新;首次发布后元数据仍可能有短暂传播延迟,可稍后刷新重试。
29
-
30
- ```yaml
31
- # .workbase/project.yaml 中的相关片段;保留既有 name、roles 等字段。
32
- plugins:
33
- team-consumer:
34
- enabled: true
35
- team-provider:
36
- enabled: true
37
- ```
38
-
39
- 依赖排序优先于声明顺序,因此以上反向声明也能正常初始化。缺失、停用、失败或循环依赖会阻塞相应插件,不影响无关插件。手动修改或同步引入的缺失引用会独立报告不可用;管理页可刷新目录后安装,也可直接移除引用。已知版本的损坏插件可用「重试安装」重新下载同版,保留启用状态。
40
-
41
- ## 2. npm 包协议
42
-
43
- npm 发布目录直接包含以下预构建文件:
44
-
45
- ```text
46
- package.json
47
- plugin.mjs
48
- ui/ # 可选
49
- index.html
50
- app.js
51
- ```
52
-
53
- 最小 `package.json`:
54
-
55
- ```json
56
- {
57
- "name": "@eworkbase/plugin-team-provider",
58
- "description": "提供团队共享命令、状态和上下文。",
59
- "files": ["plugin.mjs", "ui"],
60
- "exports": "./plugin.mjs",
61
- "publishConfig": { "access": "public" },
62
- "version": "1.0.0",
63
- "type": "module",
64
- "workbase": {
65
- "id": "team-provider",
66
- "title": "团队基础能力",
67
- "description": "提供团队共享命令、状态和上下文。",
68
- "apiVersion": 1,
69
- "workbaseVersion": "^0.4",
70
- "dependencies": [],
71
- "tools": []
72
- }
73
- }
74
- ```
75
-
76
- | 字段 | 契约 |
77
- | --- | --- |
78
- | `name` | 必填,必须是 `@eworkbase/plugin-<workbase.id>`。 |
79
- | `version` | 必填,完整 SemVer,如 `1.0.0`。 |
80
- | `workbase.id` | 以小写字母开头的 kebab-case 标识,其余为字母/数字段,以单个 `-` 分隔;不能使用 `runtime`,可选插件不能占用内置 ID。 |
81
- | `workbase.title` | 必填非空名称,必须与 `definePlugin.title` 相同。 |
82
- | `workbase.description` | 可选功能介绍,纯文本,支持换行;管理列表超过 100 字符时折叠。建议与顶层 npm description 保持一致。 |
83
- | `workbase.apiVersion` | 必填整数 `1`。 |
84
- | `workbase.workbaseVersion` | 必填 Rust semver crate 范围,例如 `^0.4`、`>=0.4.0, <0.5.0`;不支持 npm 的 `||` 范围语法。 |
85
- | `workbase.dependencies` | 默认 `[]`,插件 ID 数组;不能重复或依赖自身,必须与代码中的数组及顺序一致。依赖版本不单独求解。 |
86
- | `workbase.tools` | 默认 `[]`,工具声明与现有 `tools.yaml` 字段相同,额外带 `id`。 |
87
-
88
- 包必须包含普通文件 `plugin.mjs`。`workbase` 拒绝未知字段,不能指定任意代码入口、权限白名单或其他 scope。`builtin` 仅用于应用编译目录;npm 作者设置它不会获得内置身份。元数据限额 4 MiB,入口和 UI 文件必须处于安装包目录内。
89
-
90
- 插件后端与 UI 都应构建为自包含产物:后端把 SDK、Zod 和专属依赖打入 ESM bundle,不引用相邻的宿主 runtime。仅 Node 内置模块在运行时由 Node 提供。使用配套 SDK 版本并正确声明 Workbase/API 兼容范围,不依赖 instanceof 跨 bundle 判断私有类型。
91
-
92
- mise 的 npm backend 安装完整精确版本;平台固定公开 registry、关闭安装脚本,并为本团队新发布包允许低下载量。安装路径通过 `mise where` 取得,再验证名称、版本、manifest 和入口;不自行解压 npm tarball。发布包不需要伪造 CLI `bin` 字段,已验证无 bin 的自包含插件可通过 mise 安装并由 Node 导入。
93
-
94
- ## 3. 完整 provider/consumer 示例
95
-
96
- 以下为 ESM 源码。分别建立两个插件目录,写入各自 package.json,并把源码与 SDK 构建为 plugin.mjs 后发布。
97
-
98
- ### Provider:注册命令、状态和上下文
99
-
100
- `team-provider/plugin-source.js`:
101
-
102
- ```js
103
- /** 团队共享查询能力。 */
104
- import { definePlugin, z } from "@eworkbase/sdk";
105
-
106
- export default definePlugin({
107
- id: "team-provider",
108
- title: "团队基础能力",
109
- setup(context, hooks) {
110
- hooks.registerCommand({
111
- id: "greet",
112
- title: "生成问候",
113
- description: "根据输入名称生成团队问候语。",
114
- input: z.object({ name: z.string().min(1) }),
115
- agent: { callable: true, readOnly: true, idempotent: true },
116
- run: ({ name }) => ({ message: `你好,${name}` }),
117
- });
118
- hooks.registerStatus({
119
- id: "health",
120
- label: "团队能力",
121
- description: "当前工作区的插件就绪信息。",
122
- resolve: () => ({ ready: true, workspaceId: context.workspace.id }),
123
- });
124
- hooks.registerAgentContext({
125
- id: "team",
126
- title: "团队上下文",
127
- description: "团队共享的非敏感上下文。",
128
- resolve: () => ({ team: context.config.team ?? "default" }),
129
- });
130
- },
131
- });
132
- ```
133
-
134
- 可选 `.workbase/plugin/team-provider/config.yaml`:
135
-
136
- ```yaml
137
- team: engineering
138
- ```
139
-
140
- ### Consumer:发现、调用依赖和项目 task
141
-
142
- consumer 的 `package.json` 使用以下 `workbase`,顶层 `version` 等字段与前例一致:
143
-
144
- ```json
145
- {
146
- "id": "team-consumer",
147
- "title": "团队工作台",
148
- "apiVersion": 1,
149
- "workbaseVersion": "^0.4",
150
- "dependencies": ["team-provider"],
151
- "tools": []
152
- }
153
- ```
154
-
155
- `team-consumer/plugin-source.js`:
156
-
157
- ```js
158
- /** 通过公开命令协作,并调用当前项目授权的任务。 */
159
- import { definePlugin, PluginCommandEffect, z } from "@eworkbase/sdk";
160
-
161
- export default definePlugin({
162
- id: "team-consumer",
163
- title: "团队工作台",
164
- dependencies: ["team-provider"],
165
- setup(context, hooks) {
166
- const provider = context.services.capabilities.catalog().commands.find(
167
- ({ pluginId, id }) => pluginId === "team-provider" && id === "greet",
168
- );
169
- if (!provider) throw new Error("team-provider/greet 尚未注册");
170
-
171
- hooks.registerCommand({
172
- id: "greet",
173
- title: "团队问候",
174
- input: z.object({ name: z.string().min(1) }),
175
- run: (input, { services }) => services.capabilities.executeCommand({
176
- pluginId: provider.pluginId,
177
- commandId: provider.id,
178
- input,
179
- }),
180
- });
181
- hooks.registerCommand({
182
- id: "tasks-list",
183
- title: "查看可用任务",
184
- run: (_input, { services }) => services.tasks.list(),
185
- });
186
- hooks.registerCommand({
187
- id: "task-run",
188
- title: "执行项目任务",
189
- effect: PluginCommandEffect.LongRunning,
190
- input: z.object({ taskId: z.string().min(1) }),
191
- run: async ({ taskId }, { services }) => {
192
- const result = await services.tasks.run(taskId);
193
- if (!result.success) {
194
- throw new Error(`任务 ${taskId} 失败;日志 ${result.logId}:${result.stderr}`);
195
- }
196
- return result;
197
- },
198
- });
199
- hooks.registerView({
200
- id: "main",
201
- title: "团队工作台",
202
- slot: "workspace.tab",
203
- entry: "ui/index.html",
204
- });
205
- },
206
- });
207
- ```
208
-
209
- `setup` 只声明静态贡献;所有注册应在它返回前完成,失败时本插件贡献会回滚。不要在 setup 执行任务。业务调用放入 command/view 的 invocation,使用其 `services`、`signal`,避免保存 setup 的服务后绕过调用的取消/事务上下文。
210
-
211
- `catalog()` 返回 `commands/statuses/contexts/views` 副本。命令以 `pluginId + commandId` 定位;状态和上下文用 `resolveStatus({pluginId,id,input?})`、`resolveContext({pluginId,id,input?})`。不暴露插件实例,也不能调用其他插件的私有 view handler。catalog 共享给活动的受信任插件;`dependencies` 保证顺序和就绪,**不是权限白名单**。
212
-
213
- 依赖调用传播输入校验错误、provider 异常和取消。标记 `transaction: PluginCommandTransaction.ProjectMutation` 的命令必须从 Workbase 已建立的项目事务进入;consumer 若要嵌套调用该命令,自身也需声明同一事务。不能把一个普通 Node 调用升级成项目写事务。MCP 仅调用显式 `agent.callable: true` 且非 projectMutation 的命令,其他命令仍可由插件 UI 正常触发。
214
-
215
- ## 4. Tasks 的精确语义
216
-
217
- ```ts
218
- interface PluginTaskDescriptor {
219
- readonly id: string;
220
- readonly description: string | null;
221
- readonly depends: readonly string[];
222
- }
223
- interface PluginTaskResult {
224
- readonly success: boolean;
225
- readonly stdout: string;
226
- readonly stderr: string;
227
- readonly logId: string;
228
- }
229
- interface PluginTaskService {
230
- list(): Promise<readonly PluginTaskDescriptor[]>;
231
- run(taskId: string): Promise<PluginTaskResult>;
232
- }
233
- ```
234
-
235
- 来源是当前项目 `.workbase/tasks.yaml`;执行上下文绑定当前工作区,不另建第二份任务目录。例如:
236
-
237
- ```yaml
238
- tasks:
239
- bootstrap:
240
- description: 准备当前工作区
241
- run: echo bootstrap
242
- release:
243
- description: 发布
244
- roles: [maintainer]
245
- depends: [bootstrap]
246
- run: echo release
247
- ```
248
-
249
- `maintainer` 须已在项目 roles 中声明。无 roles 限制的 task 对全局可用;角色限定任务只对当前授权角色可用,依赖链同样经过验证。列表只返回元数据,不暴露脚本;执行只接受声明的 ID,不接受 shell 字符串、额外参数、角色或任意项目路径。
250
-
251
- Rust 每次重新验证活动项目、workspace、角色、任务及依赖,准备 mise 后在启动前再次验证。任务复用生成的 mise 配置,在项目目录运行,`WORKBASE_WORKTREE_ROOT` 指向当前工作区根目录。插件 task 服务只允许已就绪插件使用。
252
-
253
- 进程非零退出返回 `success:false`;授权/配置/启动失败抛出错误。启动阶段的失败会附带 `pluginTaskFailed` 和可用的 logId,启动前的拒绝不会伪造执行日志。stdout/stderr 为经过脱敏、截断的摘要,执行日志也沿用现有输出限额。不要把返回摘要当作完整产物传输通道。
254
-
255
- 长任务使用现有 runner 的一小时执行上限,建议命令标记 `LongRunning`。普通 task 持有工作区写保护,冲突的切换或写操作会被拒绝。准备生命周期和 projectMutation 命令可调用 tasks.run:宿主签发并传播限定当前操作的写保护上下文,避免重复争锁;过期或跨工作区上下文会被拒绝。平台状态 mutex 不会被长任务持有。
256
-
257
- **取消边界:**调用开始前已取消则不启动;执行中取消或宿主关闭会通知统一执行器终止任务进程树,待进程退出、日志记录完毕后释放写保护并返回取消错误(含 logId)。取消不回滚已经发生的业务副作用。其他独立请求仍可响应。
258
-
259
- ## 5. 插件能力索引
260
-
261
- | 入口 | 能力和边界 |
262
- | --- | --- |
263
- | `context.config` | 当前插件 YAML 的只读初始化快照;缺失为 `{}`。 |
264
- | `services.config.patch/replace` | 递归合并/整体替换当前插件 YAML;不修改其他插件。结果返回新配置,旧快照不会原地更新。 |
265
- | `services.store.getState/setState/subscribe` | 按 project/workspace/plugin 隔离的 JSON 状态,大小限制 1 MB;`setState` 合并部分状态。订阅需在 cleanup 释放。 |
266
- | `context.project/workspace` | 项目路径、工作区路径、仓库列表和准备状态。 |
267
- | `services.system.getContext()` | 宿主汇总项目、工作区、当前角色、工具、插件和应用信息。 |
268
- | `services.tasks.list/run` | 当前授权 task 的发现和执行。 |
269
- | `services.capabilities` | 标准共享命令、状态、上下文和视图目录。 |
270
- | `context.process.run(options, signal)` | 统一子进程执行,结构化 program/arguments、cwd、环境、超时;可读 exitCode、failed、timedOut、wasCancelled 和输出。不会代替 task 角色授权。 |
271
- | `context.logger` / `services.logger` | 运行日志与交互日志;后者支持 success/custom/getEntries。 |
272
- | `services.logs.query({cursor?,limit?})` | 当前工作区宿主执行日志,分页、截断和脱敏。 |
273
- | `services.prompt.ask(question)` | 原生 input/confirm/list/rawlist/search-list/search-checkbox/fuzzy-path,返回按 name 定位的答案对象。 |
274
- | `services.toast.show/update/dismiss` | 原生提示,支持 info/warn/error/success。 |
275
- | `hooks.registerCommand` | 共享业务动作,支持 Zod input、事务、执行方式、分类、Agent 策略。 |
276
- | `hooks.registerStatus/registerAgentContext` | 只读状态/结构化 Agent 上下文。不要放凭据。 |
277
- | `hooks.registerView` | 独立 HTML 入口,支持局部 handlers/request、order、content/fill layout。 |
278
-
279
- 生命周期通过 `hooks.onWorkspaceProvision/onWorkspaceActivate/onWorkspaceAfterPrepare/onWorkspaceDeactivate/onProjectReconcile/onCleanup.tap(name, handler)` 注册。依赖先初始化,cleanup 负责释放自己创建的订阅/连接;释放应幂等。处理器可以返回 `standardOutput/standardError/warnings`。Node 宿主只为当前活动 workspace 提供一个平台实例,不提供跨项目共享 plugin 实例或任意运行期追加贡献。
280
-
281
- Node 后端可以使用 Node 原生 API,因此以上入口约束是受信任插件的协作契约,不能当成对恶意代码的强制权限隔离。禁止向日志、MCP Context 或团队 YAML 写入 token。使用 invocation 的 process 服务时,显式传入 signal,保留统一取消和输出脱敏行为。
282
-
283
- ## 6. 默认工具
284
-
285
- 例如包的 `workbase.tools` 可以声明:
286
-
287
- ```json
288
- [
289
- {
290
- "id": "team-cli",
291
- "label": "团队 CLI",
292
- "category": "runtime",
293
- "runtimeId": "npm:@your-team/cli",
294
- "version": "1.2.3"
295
- }
296
- ]
297
- ```
298
-
299
- 此处是作者自己发布的示例包名,按实际 CLI 替换。工具字段沿用项目配置的校验;带 `runtimeId` 时必须声明 version。平台合并启用插件的工具,再应用 `.workbase/tools.yaml` 同 ID 项目覆盖;工具页、角色上下文、mise 环境与准备流程都使用这个来源。
300
-
301
- 所有启用插件自动要求 Workbase 的 Node 宿主,不需要每个包重复声明 node。项目 tools.yaml 显式覆盖优先;未覆盖时,两个插件对同 ID 工具提供不一致默认值只阻塞相关插件,应统一团队版本。包安装本身不会启动工具安装;准备环境时才通过现有工具流程检测和安装。
302
-
303
- ## 7. UI 示例与打包
304
-
305
- UI SDK 入口是 `@eworkbase/sdk/ui`,通过 Penpal 与宿主连接。不能直接使用 Tauri API;task 能力通过上面注册的后端 command 调用。
306
-
307
- `team-consumer/ui/index.html`:
308
-
309
- ```html
310
- <!doctype html>
311
- <html lang="zh-CN">
312
- <head><meta charset="UTF-8"><title>团队工作台</title></head>
313
- <body>
314
- <button id="refresh" type="button" disabled>读取任务</button>
315
- <pre id="result" aria-live="polite">正在连接工作区…</pre>
316
- <script type="module" src="./app.js"></script>
317
- </body>
318
- </html>
319
- ```
320
-
321
- 作者源文件 `team-consumer/ui-source.js`:
322
-
323
- ```js
324
- /** 当前项目任务列表的最小界面。 */
325
- import { defineWorkbasePluginUi } from "@eworkbase/sdk/ui";
326
-
327
- const button = document.querySelector("#refresh");
328
- const result = document.querySelector("#result");
329
- const ui = defineWorkbasePluginUi({
330
- onInit() {
331
- button.disabled = false;
332
- result.textContent = "已连接,点击读取任务。";
333
- },
334
- });
335
- button.addEventListener("click", async () => {
336
- button.disabled = true;
337
- try {
338
- const tasks = await ui.commands.execute("tasks-list", {});
339
- result.textContent = JSON.stringify(tasks, null, 2);
340
- } catch (error) {
341
- result.textContent = error instanceof Error ? error.message : String(error);
342
- } finally {
343
- button.disabled = false;
344
- }
345
- });
346
- ```
347
-
348
- UI 还支持 `ui.commands.cancel(executionId)`、`ui.status.resolve`、`ui.view.call`、`ui.showPrompt/showToast/selectFiles`、`ui.openOutput/updateOutput/closeOutput` 和应用内 `ui.navigate`。`onInit` 接收 locale/theme/project/workspace/view/route/params。UI 请求绑定当前插件,不接受其他插件 ID;跨插件业务请通过自己的后端命令转发。
349
-
350
- SDK 通过公开的 `@eworkbase/sdk` 提供后端 ESM、类型声明、浏览器 UI API、`ui/model` 和 `ui/index.css`。在自己的目录中安装即可,无需克隆 Workbase。Runtime 是应用内的插件宿主,不需要作为 npm 依赖安装;插件的 API 兼容性通过 `apiVersion` 和 `workbaseVersion` 声明。
351
-
352
- 将上面的示例文件放入当前目录的 `team-provider/` 和 `team-consumer/`,在它们的父目录执行:
353
-
354
- ```bash
355
- npm init -y
356
- npm install --save-dev @eworkbase/sdk@0.1.1 esbuild typescript
357
-
358
- # UI SDK 及浏览器依赖合并进 app.js。
359
- npx esbuild team-consumer/ui-source.js \
360
- --bundle --platform=browser --format=esm --target=es2022 \
361
- --outfile=team-consumer/ui/app.js
362
-
363
- # 后端与 SDK 构建为自包含 ESM,不把 SDK 标记为 external。
364
- npx esbuild team-provider/plugin-source.js \
365
- --bundle --platform=node --format=esm --target=node22 \
366
- --outfile=team-provider/plugin.mjs
367
- npx esbuild team-consumer/plugin-source.js \
368
- --bundle --platform=node --format=esm --target=node22 \
369
- --outfile=team-consumer/plugin.mjs
370
-
371
- # files 字段只包含运行产物;先检查再发布。
372
- npm pack ./team-provider --dry-run --ignore-scripts
373
- npm publish ./team-provider --access public --ignore-scripts
374
- npm publish ./team-consumer --access public --ignore-scripts
375
- ```
376
-
377
- TypeScript 工程可直接从 SDK 导入类型,使用 `module: "NodeNext"` 和 `moduleResolution: "NodeNext"` 检查后端,浏览器工程也支持 `moduleResolution: "Bundler"`。SDK 不需要运行安装脚本。CSS 可在浏览器入口使用 `import "@eworkbase/sdk/ui/index.css"` 交给打包工具处理。
378
-
379
- consumer 的 npm 名称须为 `@eworkbase/plugin-team-consumer`,依赖的是插件 ID `team-provider`,不是 npm 依赖求解器。UI 采用 `base: "./"`,SDK 一并打入浏览器 bundle。
380
-
381
- Workbase 的日常 `pnpm build` 和桌面开发只构建宿主资源,不构建业务插件。测试或发布使用 `pnpm build-packages` 构建全部插件和 SDK;不再生成 `packages/dist/<plugin-id>` 的重复副本。`packages/dist/runtime` 是桌面实际需要的宿主资源,不能随业务插件一起删除。
382
-
383
- Workbase 自带插件的发布产物通过 `pnpm build-packages` 写入 `packages/plugin-<id>/dist`。源工作区 package.json 仍是私有开发包;dist/package.json 才是 `@eworkbase` 的公开发布契约,移除了 workspace 依赖、源码入口及构建脚本。示例:
384
-
385
- ```bash
386
- npm pack ./packages/plugin-openspec/dist --dry-run --ignore-scripts
387
- npm publish ./packages/plugin-openspec/dist --access public --ignore-scripts
388
- ```
389
-
390
- SDK 发布目录是 `packages/plugin-sdk/dist`,使用 `npm publish ./packages/plugin-sdk/dist --access public --ignore-scripts`。源工作区继续使用私有包名 `@workbase/plugin-sdk`;公开消费者只使用 `@eworkbase/sdk`,因此 SDK 不会出现在 `plugin-*` 目录中。
391
-
392
- npm 名称+版本发布后不可覆盖,升级必须发布新版本。平台发现公开 scope 中的 `plugin-*`,不依赖需要登录的 npm settings 网页。npm 发布与工作区 task 发布为两种独立操作。
393
-
394
- 工作区就绪表示仓库与公共环境可用;插件的加载/准备状态在独立插件区域展示。插件失败仍记录准备日志,不覆盖工作区状态。
395
-
396
- ## 8. 验证与排错
397
-
398
- | 现象 | 检查 |
399
- | --- | --- |
400
- | 目录为空 | npm scope 是否已有公开包、名称是否匹配、组织包目录及 latest 元数据是否可读;首次发布可稍后刷新。 |
401
- | 安装失败 | npm 精确版本是否存在、API/兼容范围是否正确、mise 是否就绪。 |
402
- | definition mismatch | 对齐包与 `definePlugin` 的 id/title/dependencies。 |
403
- | 插件 blocked | 依赖是否已安装、启用、准备;工具和 Node 是否就绪。 |
404
- | 更新暂不可用 | 等待工作区准备/写操作完成;安装成功后才保存新版本并停止旧宿主。 |
405
- | task 列表缺项 | 当前角色、task.roles 和依赖授权;不要传其他项目路径。 |
406
- | task busy | 普通调用与其他写操作冲突;嵌套调用须使用 invocation 服务以继承有效上下文。 |
407
- | task 返回失败 | 检查 success、stderr 和 logId;取消等待进程清理,已有副作用不回滚。 |
408
- | UI 空白 | entry 是包内普通文件,浏览器产物使用相对资源路径,UI SDK 与宿主版本匹配。 |
409
-
410
- 仓库回归命令:
411
-
412
- ```bash
413
- pnpm test:plugins
414
- pnpm bindings:check
415
- pnpm typecheck
416
- cargo test --manifest-path src-tauri/Cargo.toml plugins:: --no-fail-fast
417
- cargo fmt --manifest-path src-tauri/Cargo.toml --all -- --check
418
- cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets -- -D warnings
419
- ```
420
-
421
- 完整 Node 测试含真实本地 Bridge 和 MCP loopback 监听;只需本机临时目录和本地端口,不需要外部服务。外部包/任务测试使用构造包和 fake runner,不安装真实工具或执行团队任务。
422
-
423
- ## 9. 从 ZIP 流程迁移
424
-
425
- ZIP API、选择器、预览令牌、解压缓存和 zip crate 已移除。旧 ZIP 文件不再被扫描或执行,也不自动删除团队文件;请先把插件发布到指定 npm scope,再在管理页安装。原 project.yaml 启用项和 config.yaml 保留。
426
-
427
- 分发复杂度交给 npm/mise 后,不再自维护压缩包的路径、链接、重复文件、解压限额、暂存替换和 SDK 复制。仍需保留 Workbase 元数据校验、版本声明、项目同步、依赖命令、任务授权和运行生命周期。它减少了维护边界,不意味着插件平台主体可以删除。
428
-
429
- ## 10. 首次发布验收(2026-09-09)
430
-
431
- | npm 包 | 已验证版本 |
432
- | --- | --- |
433
- | `@eworkbase/plugin-ai-mcp` | `0.1.1` |
434
- | `@eworkbase/plugin-ai-rules` | `0.1.0` |
435
- | `@eworkbase/plugin-codegraph` | `0.1.0` |
436
- | `@eworkbase/plugin-openspec` | `0.1.0` |
437
-
438
- AI MCP 0.1.0 缺少 manifest 的 ai-rules 依赖声明,已标记弃用;0.1.1 补齐声明,应用内置版本已同步更新。构建产物测试同时验证 manifest 和运行定义的依赖一致性。
439
-
440
- 已使用无 npm 凭据的临时环境验证组织包目录、latest 元数据、tarball SHA-512 完整性、四个包的 mise 安装/where 和 UI 文件。公开安装产物经真实 Node Bridge 注册为 ready,共 17 个命令、4 个视图;AI MCP 到 AI Rules 的依赖状态调用通过,离线复用无需 registry。测试未修改真实项目的插件配置或执行项目业务任务。
441
-
442
- 目录发现使用 npm CLI `libnpmaccess.getPackages` 同源接口 `https://registry.npmjs.org/-/org/eworkbase/package`,再读取各包 latest。首次发布时搜索 API 曾返回空列表,因此不依赖搜索分页或索引及时性;安装仍固定完整 SemVer。
package/definition.d.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * Validates and freezes canonical Workbase plugin definitions.
3
- */
4
- import type { WorkbasePluginDefinition } from "./types.js";
5
- export type DefinedWorkbasePlugin = Readonly<WorkbasePluginDefinition>;
6
- export declare function definePlugin(definition: WorkbasePluginDefinition): DefinedWorkbasePlugin;
7
- export declare function isDefinedPlugin(value: unknown): value is DefinedWorkbasePlugin;
package/definition.js DELETED
@@ -1,41 +0,0 @@
1
- /**
2
- * Validates and freezes canonical Workbase plugin definitions.
3
- */
4
- const PLUGIN_ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
5
- export function definePlugin(definition) {
6
- validateDefinition(definition);
7
- return Object.freeze({
8
- ...definition,
9
- dependencies: Object.freeze([...(definition.dependencies ?? [])]),
10
- });
11
- }
12
- export function isDefinedPlugin(value) {
13
- try {
14
- validateDefinition(value);
15
- return true;
16
- }
17
- catch {
18
- return false;
19
- }
20
- }
21
- function validateDefinition(definition) {
22
- if (!isRecord(definition)) {
23
- throw new TypeError("definePlugin requires a plugin definition object.");
24
- }
25
- if (typeof definition.id !== "string" || !PLUGIN_ID_PATTERN.test(definition.id)) {
26
- throw new TypeError("Plugin id must use lowercase kebab-case.");
27
- }
28
- if (typeof definition.setup !== "function") {
29
- throw new TypeError("Plugin setup must be a function.");
30
- }
31
- if (typeof definition.title !== "string" || definition.title.trim() === "") {
32
- throw new TypeError("Plugin title must be a non-empty string.");
33
- }
34
- const dependencies = definition.dependencies ?? [];
35
- if (!Array.isArray(dependencies) || dependencies.some((id) => (typeof id !== "string" || !PLUGIN_ID_PATTERN.test(id) || id === definition.id)) || new Set(dependencies).size !== dependencies.length) {
36
- throw new TypeError("Plugin dependencies must be unique plugin ids and cannot include itself.");
37
- }
38
- }
39
- function isRecord(value) {
40
- return value !== null && typeof value === "object" && !Array.isArray(value);
41
- }
@@ -1,168 +0,0 @@
1
- /**
2
- * Workbase-owned services available to trusted Workbase plugins.
3
- */
4
- import type { ZodType } from "zod";
5
- import type { PluginCommandArgument, PluginCommandCategory, PluginCommandDefinition, PluginCommandOption, PluginCommandTransaction, PluginLogger } from "./types.js";
6
- export interface PluginColoredMessage {
7
- readonly color?: string;
8
- readonly text: string;
9
- }
10
- export interface PluginLogEntry {
11
- readonly level: "log" | "success" | "warn" | "error" | "debug" | "custom";
12
- readonly message: string;
13
- readonly segments?: readonly PluginColoredMessage[];
14
- readonly timestamp: number;
15
- }
16
- export interface PluginInteractiveLogger extends PluginLogger {
17
- readonly custom: (segments: readonly PluginColoredMessage[]) => void;
18
- readonly getEntries: () => readonly PluginLogEntry[];
19
- readonly log: (message: string) => void;
20
- readonly success: (message: string) => void;
21
- }
22
- export interface PluginPromptChoice<Value = unknown> {
23
- readonly description?: string;
24
- readonly key?: string;
25
- readonly name: string;
26
- readonly short?: string;
27
- readonly value: Value;
28
- }
29
- export type PluginPromptType = "input" | "confirm" | "list" | "rawlist" | "search-list" | "search-checkbox" | "fuzzy-path";
30
- export interface PluginPromptQuestion<Key = string, Value = unknown, Choice = unknown> {
31
- readonly choices?: readonly PluginPromptChoice<Choice>[] | readonly string[];
32
- readonly default?: Value;
33
- readonly excludePath?: (path: string) => boolean;
34
- readonly itemType?: "file" | "directory" | "any";
35
- readonly message: string;
36
- readonly name: Key;
37
- readonly pageSize?: number;
38
- readonly rootPath?: string;
39
- readonly type: PluginPromptType;
40
- readonly validate?: (value: unknown) => boolean | string;
41
- }
42
- export interface PluginPromptApi<Parameters extends Record<string, unknown> = Record<string, unknown>> {
43
- readonly ask: <Key extends keyof Parameters>(question: PluginPromptQuestion<Key, Parameters[Key]>) => Promise<{
44
- [Property in Key]: Parameters[Property];
45
- }>;
46
- }
47
- export type PluginToastLevel = "info" | "warn" | "error" | "success";
48
- export interface PluginToastOptions {
49
- readonly duration?: number;
50
- }
51
- export interface PluginToastApi {
52
- readonly dismiss: (id: number) => void;
53
- readonly show: (message: string, level?: PluginToastLevel, options?: PluginToastOptions) => number;
54
- readonly update: (id: number, message: string, level?: PluginToastLevel, options?: PluginToastOptions) => number;
55
- }
56
- export interface PluginStoreApi {
57
- readonly getState: () => Readonly<Record<string, unknown>>;
58
- readonly setState: (partial: Readonly<Record<string, unknown>>) => void;
59
- readonly subscribe: (listener: () => void) => () => void;
60
- }
61
- export interface PluginConfigApi {
62
- readonly patch: (patch: Readonly<Record<string, unknown>>) => Promise<Readonly<Record<string, unknown>>>;
63
- readonly replace: (config: Readonly<Record<string, unknown>>) => Promise<Readonly<Record<string, unknown>>>;
64
- }
65
- export interface PluginCommandCatalogEntry {
66
- readonly agent?: PluginAgentPolicy;
67
- readonly arguments?: readonly PluginCommandArgument[];
68
- readonly category?: PluginCommandCategory;
69
- readonly description?: string;
70
- readonly executionMode?: PluginCommandDefinition["executionMode"];
71
- readonly id: string;
72
- readonly input?: ZodType;
73
- readonly options?: readonly PluginCommandOption[];
74
- readonly pluginId: string;
75
- readonly title: string;
76
- readonly transaction: PluginCommandTransaction;
77
- }
78
- export interface PluginAgentPolicy {
79
- readonly callable: boolean;
80
- readonly destructive?: boolean;
81
- readonly idempotent?: boolean;
82
- readonly openWorld?: boolean;
83
- readonly readOnly: boolean;
84
- }
85
- export interface PluginCapabilityCommandRequest {
86
- readonly commandId: string;
87
- readonly executionId?: string;
88
- readonly input?: unknown;
89
- readonly pluginId: string;
90
- readonly signal?: AbortSignal;
91
- }
92
- export interface PluginCapabilityResolveRequest {
93
- readonly id: string;
94
- readonly input?: unknown;
95
- readonly pluginId: string;
96
- }
97
- export interface PluginStatusCatalogEntry {
98
- readonly description: string;
99
- readonly id: string;
100
- readonly label: string;
101
- readonly pluginId: string;
102
- }
103
- export interface PluginAgentContextCatalogEntry {
104
- readonly description: string;
105
- readonly id: string;
106
- readonly pluginId: string;
107
- readonly title: string;
108
- }
109
- export interface PluginViewCatalogEntry {
110
- readonly description?: string;
111
- readonly id: string;
112
- readonly pluginId: string;
113
- readonly slot: string;
114
- readonly title: string;
115
- }
116
- export interface PluginCapabilityCatalog {
117
- readonly commands: readonly PluginCommandCatalogEntry[];
118
- readonly contexts: readonly PluginAgentContextCatalogEntry[];
119
- readonly statuses: readonly PluginStatusCatalogEntry[];
120
- readonly views: readonly PluginViewCatalogEntry[];
121
- }
122
- export interface PluginCapabilityService {
123
- readonly catalog: () => PluginCapabilityCatalog;
124
- readonly executeCommand: (request: PluginCapabilityCommandRequest) => Promise<unknown>;
125
- readonly resolveContext: (request: PluginCapabilityResolveRequest) => Promise<unknown>;
126
- readonly resolveStatus: (request: PluginCapabilityResolveRequest) => Promise<unknown>;
127
- }
128
- export interface PluginSystemContextService {
129
- readonly getContext: () => Promise<Readonly<Record<string, unknown>>>;
130
- }
131
- export interface PluginLogQueryRequest {
132
- readonly cursor?: string;
133
- readonly limit?: number;
134
- readonly workspaceId?: string;
135
- }
136
- export interface PluginLogQueryResult {
137
- readonly items: readonly unknown[];
138
- readonly nextCursor: string | null;
139
- }
140
- export interface PluginLogService {
141
- readonly query: (request?: PluginLogQueryRequest) => Promise<PluginLogQueryResult>;
142
- }
143
- export interface PluginTaskDescriptor {
144
- readonly id: string;
145
- readonly description: string | null;
146
- readonly depends: readonly string[];
147
- }
148
- export interface PluginTaskResult {
149
- readonly success: boolean;
150
- readonly stdout: string;
151
- readonly stderr: string;
152
- readonly logId: string;
153
- }
154
- export interface PluginTaskService {
155
- readonly list: () => Promise<readonly PluginTaskDescriptor[]>;
156
- readonly run: (taskId: string) => Promise<PluginTaskResult>;
157
- }
158
- export interface PluginHostServices {
159
- readonly capabilities: PluginCapabilityService;
160
- readonly config: PluginConfigApi;
161
- readonly logger: PluginInteractiveLogger;
162
- readonly logs: PluginLogService;
163
- readonly prompt: PluginPromptApi;
164
- readonly store: PluginStoreApi;
165
- readonly system: PluginSystemContextService;
166
- readonly toast: PluginToastApi;
167
- readonly tasks: PluginTaskService;
168
- }
package/host-services.js DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * Workbase-owned services available to trusted Workbase plugins.
3
- */
4
- export {};