@tinyforge/dsh-plugin-manager-wj 1.4.0 → 1.5.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 +19 -13
- package/README.zh.md +19 -13
- package/client.js +137 -86
- package/index.js +293 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,27 +10,31 @@
|
|
|
10
10
|
|
|
11
11
|
- **Switchable views:** one tab strip switches between plugin health, configuration, the skill catalog, and tool registration ownership. A visited view stays mounted, so a configuration draft and the search term survive switching.
|
|
12
12
|
- **Harness Core:** consumes the Host's plugin registry, configuration resolver, conflict detector, lifecycle/dependency manager, and settings services.
|
|
13
|
-
- **Management API:** shows plugin state
|
|
14
|
-
- **Management UI:** filters the active view, edits non-secret scalar settings through the existing schema-backed `configForms`, and
|
|
13
|
+
- **Management API:** shows plugin state, derived activation findings, configuration provenance, and tool runtime registrations. It can enable or disable profile-addressable plugins.
|
|
14
|
+
- **Management UI:** filters the active view, edits non-secret scalar settings through the existing schema-backed `configForms`, and reports each tool's scope with its owner (an MCP server, or the plugin package the Host half matched).
|
|
15
15
|
|
|
16
16
|
### Views
|
|
17
17
|
|
|
18
18
|
| View | Source | Notes |
|
|
19
19
|
| --- | --- | --- |
|
|
20
|
-
| Plugins |
|
|
20
|
+
| Plugins | the Loader projection from `pluginInventory.list()` | Enable/disable addressable entries; findings are derived from failed fibers and their `diagnostic`. |
|
|
21
21
|
| Configuration | `configForms.describe`, `pluginManager.getConfigProvenance` | Secret fields are omitted; provenance shows layers and redacted identities. |
|
|
22
22
|
| Skills | `skills/list` through the active session | Session-scoped, so the catalog resolves from the session working directory and reloads automatically when the active session changes. Model-invocable and user-only entries are marked separately. |
|
|
23
|
-
| Tools | `
|
|
23
|
+
| Tools | this package's Host half, `GET /api/wj/tool-inventory` | Runtime tool registrations, with the plugin that provides each tool and the scope it applies to. |
|
|
24
24
|
|
|
25
|
-
Enabling or disabling a plugin writes through the Host's
|
|
25
|
+
Enabling or disabling a plugin writes through the Host's `pluginManager.setPluginEnabled`. A change can apply immediately, require a restart, be overridden by a higher-priority layer, be cancelled, or be refused by the Host; the outcome is reported as it arrives.
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
Ownership has three sources: a `mcp__<server>__<tool>` name belongs to that server; any other name is matched by the Host half against `name: '…'` literals in each plugin package's entry bundle and labelled **inferred**; a name neither source explains is reported as unrecorded instead of guessed.
|
|
28
|
+
|
|
29
|
+
MCP servers themselves belong to the Host's MCP settings bundle (for example `@tinyforge/dsh-mcp-settings`), which registers the `settings.section` page `mcp` and reads `mcpClientStatus/list`. This bundle neither reads `mcpClientStatus` nor lists MCP servers a second time, so the settings UI has exactly one MCP management entry point; the Tools view still shows MCP tools, attributed to their server.
|
|
28
30
|
|
|
29
31
|
Configuration fields are discovered from each Host-provided schema. Secret fields are omitted from the editor, and provenance shows layer names and redacted identities, never values or filesystem paths. The Host remains responsible for schema validation and persistence.
|
|
30
32
|
|
|
31
33
|
## Requirements and limitations
|
|
32
34
|
|
|
33
|
-
Use a Harness Host that exposes the
|
|
35
|
+
Use a Harness Host that exposes the Loader projection (`pluginInventory.list()`), which the 0.2.2-rc line does. An older Host that still answers with a `toolRegistrations` snapshot keeps working: plugin and tool rows render, only the failed-fiber findings are missing. The Tools view needs the `/api/wj/tool-inventory` route registered by this package's Host half; a Host that mounts only the Client half says so explicitly instead of showing an empty list. Only plugins addressable through the active profile can be toggled.
|
|
36
|
+
|
|
37
|
+
This package no longer depends on a diagnostics Remote: `getHealthSnapshot`, `previewRemediation` and `applyRemediation` do not exist in the current official Host, so the page derives findings from the Loader projection itself (a failed fiber and its `diagnostic`) and never falls back to a whole-page "this Host does not expose diagnostics" notice.
|
|
34
38
|
|
|
35
39
|
The tab hard-injects only two core client services, `slots` and `locale`. Everything else — the `pluginInventory` and `pluginManager` remotes, `configForms`, the skills Remote and the live session — is resolved through `ctx.get` at call time rather than declared in `inject`, because a Client plugin that lists an optional service in `inject` stays pending on a Host without it, and a pending plugin registers no tab at all: the settings page then shows no plugin views instead of a degraded one. The Skills view therefore degrades rather than disappearing: no Remote means an explanatory message, and no session means a waiting state that loads the catalog by itself as soon as a session appears or the active session changes, with no manual refresh. The namespace is discovered rather than hardcoded (`skills`, `skill`, `skillCatalog`, then any registered `remote.*` name containing "skill"), so a Host that renames it needs no code change. Skills are read-only here: the Host exposes only `skills/list` (policy `reader-session-read`) and no skills configuration namespace, so there is no Remote to enable or disable an entry and the view shows what the active session can see instead of offering a switch that cannot work. The UI never loads skill bodies. The UI does not install/remove packages, edit credentials, or run arbitrary repair commands.
|
|
36
40
|
|
|
@@ -51,25 +55,27 @@ npm install @tinyforge/dsh-plugin-manager-wj
|
|
|
51
55
|
## Release
|
|
52
56
|
|
|
53
57
|
```sh
|
|
54
|
-
npm test # node --test:
|
|
58
|
+
npm test # node --test: 27 checks (views, tool ownership, Host route, inject contract, module id, patch shape)
|
|
55
59
|
npm publish --access public # writes to registry.npmjs.org
|
|
56
60
|
```
|
|
57
61
|
|
|
58
|
-
The package name is scoped, so publishing a new version needs maintainer access to the `@tinyforge` npm scope. Tag the published commit (`git tag v1.
|
|
62
|
+
The package name is scoped, so publishing a new version needs maintainer access to the `@tinyforge` npm scope. Tag the published commit (`git tag v1.5.0 && git push --tags`) so the GitHub history matches the registry.
|
|
59
63
|
|
|
60
64
|
## Development
|
|
61
65
|
|
|
62
|
-
The package is an ES module
|
|
66
|
+
The package is an ES module with two halves: `index.js` is the Host entry point and `client.js` contains the browser UI. Localized package metadata is in `locale/`; the UI's full dictionaries are registered in `client.js`.
|
|
67
|
+
|
|
68
|
+
The Host half publishes what a browser cannot read. The official `ctx.remote` table is a compile-time allowlist, so a third-party package cannot add a namespace, and `ctx.tools` only exists on the Host. The tool registry therefore travels through `ctx.connection.fetch.register()` as `GET /api/wj/tool-inventory`, which the shared channel admits for owner peers only. Its `inject` names just `connection`; a Host without that channel keeps the plugin active and lets the page explain itself, instead of failing activation.
|
|
63
69
|
|
|
64
70
|
`client.js` registers with `__ModuleLoader__.load({ id: '@tinyforge/dsh-plugin-manager-wj', … })`. That id must be the bare package name, scope included: the client module loader keys each Loader row by package name, and a bundle that registers any other id is reported as loaded without registering its row, which leaves the plugin without a fiber and the settings tab missing entirely. Renaming the package means updating that id in the same commit.
|
|
65
71
|
|
|
66
|
-
- `node --test` runs the bundle behavior checks in `tests/client.test.js
|
|
67
|
-
- `node --check client.js`
|
|
72
|
+
- `node --test` runs the bundle behavior checks in `tests/client.test.js` (the four views render and switch, visited views stay mounted, search and enable/disable act on the active view, a secret configuration object stays out of the editor, opening a session loads the skill catalog without a refresh, a renamed skills namespace is discovered, a transient catalog failure recovers from the inline retry, the tab still registers on a Host that mounts no optional services, the tool view reads its Host route, a missing route explains itself, and a legacy snapshot still fills both views) and `tests/host.test.js` (MCP naming, package-source scan budget, per-scope collection, snapshot shape, the authenticated JSON route, and a Host without the shared channel).
|
|
73
|
+
- `node --check client.js` and `node --check index.js` check both halves' syntax.
|
|
68
74
|
- `tests/patch.test.js` parses `cordis.patch.yml` and asserts no plain scalar starts with a reserved YAML indicator — the scoped package name must stay quoted, or the Host rejects the bundle patch.
|
|
69
75
|
- `tests/inject.test.js` pins the plugin's `inject` list to the core services only, so a regressed hard-injection of an optional remote fails the suite instead of silently emptying the settings page on some Hosts.
|
|
70
76
|
- `tests/module-id.test.js` asserts the registered module id equals `package.json`'s `name`, so a rename cannot silently detach the browser bundle from its Loader row.
|
|
71
77
|
- `tests/harness.html` mounts the real `client.js` against fixtures in a browser and asserts the same behavior without Node; open it directly from disk and read the JSON report.
|
|
72
|
-
- `tests/parse-check.html` is a minimal browser smoke page: it confirms `client.js` parses and registers `settings.plugins.tab
|
|
78
|
+
- `tests/parse-check.html` is a minimal browser smoke page: it confirms `client.js` parses and registers `plugins.tab`, the Plugins page's tab slot (the older `settings.plugins.tab` does not exist in current DSH, so that registration landed nowhere).
|
|
73
79
|
|
|
74
80
|
Harness API and Host behavior are implemented and tested in the `deepseek-harness` repository.
|
|
75
81
|
|
package/README.zh.md
CHANGED
|
@@ -10,27 +10,31 @@
|
|
|
10
10
|
|
|
11
11
|
- **可切换视图:**一条标签栏在插件健康、配置、Skill 目录与工具注册归属之间切换。已访问过的视图保持挂载,因此切换时配置草稿和搜索词都不会丢失。
|
|
12
12
|
- **Harness Core:**使用 Host 提供的插件注册表、配置解析、冲突检测、生命周期与依赖管理,以及设置服务。
|
|
13
|
-
- **Management API
|
|
14
|
-
- **Management UI:**按视图过滤,通过现有 schema 表单 `configForms`
|
|
13
|
+
- **Management API:**查看插件状态、激活诊断、配置来源和工具运行时注册;可启停当前 Profile 能寻址的插件。
|
|
14
|
+
- **Management UI:**按视图过滤,通过现有 schema 表单 `configForms` 编辑非密钥标量配置;工具视图给出每个工具的作用域与归属(MCP 服务器或推断出的插件包)。
|
|
15
15
|
|
|
16
16
|
### 视图
|
|
17
17
|
|
|
18
18
|
| 视图 | 数据来源 | 说明 |
|
|
19
19
|
| --- | --- | --- |
|
|
20
|
-
| 插件 | `
|
|
20
|
+
| 插件 | `pluginInventory.list()` 的 Loader 投影 | 启停当前 Profile 能寻址的条目,并由失败 fiber 派生激活诊断。 |
|
|
21
21
|
| 配置 | `configForms.describe`、`pluginManager.getConfigProvenance` | 隐藏密钥字段;来源只显示层名称与脱敏标识。 |
|
|
22
22
|
| Skill | 通过当前会话读取 `skills/list` | 按会话解析,目录来自会话工作目录,并在活动会话变化时自动重新加载;模型可调用与仅用户可调用分开标记。 |
|
|
23
|
-
| 工具 | `
|
|
23
|
+
| 工具 | 本包 Host 半边的 `GET /api/wj/tool-inventory` | 运行时工具注册清单,以及每个工具由哪个插件提供、作用于哪个范围。 |
|
|
24
24
|
|
|
25
|
-
启停操作通过 Host
|
|
25
|
+
启停操作通过 Host 的 `pluginManager.setPluginEnabled` 写入 Profile。更改可能即时生效、需要重启、被更高优先级配置覆盖、被 Host 取消或被拒绝,结果原样回显。
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
工具归属分三种来源:名字符合 `mcp__<服务器>__<工具>` 的 MCP 工具直接归给该服务器;其余名字由 Host 半边扫描各插件包入口 bundle 中的 `name: '…'` 字面量匹配,标注为**推断**;两者都匹配不到时如实显示"宿主未暴露归属",不做猜测。
|
|
28
|
+
|
|
29
|
+
MCP 服务器本身由 Host 的 MCP 设置 bundle 管理(例如 `@tinyforge/dsh-mcp-settings`):它注册 `settings.section` 的 `mcp` 页面,并读取 `mcpClientStatus/list`。本插件既不读取 `mcpClientStatus`,也不列出 MCP 服务器清单——工具视图只展示工具注册行,MCP 工具由所属服务器标注。
|
|
28
30
|
|
|
29
31
|
配置字段来自 Host 提供的 schema。编辑器隐藏密钥字段;配置来源只显示层名称和脱敏标识,不暴露值或文件系统路径。schema 校验和持久化由 Host 负责。
|
|
30
32
|
|
|
31
33
|
## 要求与限制
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
需要提供插件 Loader 投影(`pluginInventory.list()`)的 Harness Host;0.2.2-rc 系列即如此。较旧 Host 若返回的是带 `toolRegistrations` 的旧清单,插件仍能显示插件与工具行,只是没有失败 fiber 诊断。工具视图依赖本包 Host 半边注册的 `/api/wj/tool-inventory`;该路由不存在的 Host(例如只装客户端半边)会明确提示路由缺失,而不是显示空清单。只有当前 Profile 可寻址的插件可以启停。
|
|
36
|
+
|
|
37
|
+
本包**不再依赖** Host 的诊断接口:`getHealthSnapshot`、`previewRemediation`、`applyRemediation` 在当前官方 Host 中已不存在,页面改为由 Loader 投影自行派生诊断(失败 fiber + 其 `diagnostic`),因此不会再出现"此 Harness Host 尚未提供诊断接口"的整页提示。
|
|
34
38
|
|
|
35
39
|
标签页只硬注入两个核心客户端服务:`slots` 与 `locale`。其余服务 —— `pluginInventory`、`pluginManager` 两个 remote、`configForms`、skills Remote 与存活会话 —— 都在调用时通过 `ctx.get` 解析,而不写进 `inject`:把可选服务写进 `inject` 会让客户端插件在缺少该服务的 Host 上一直处于 pending 状态,而 pending 的插件不注册任何标签页,设置页面会变成完全没有插件视图,而不是降级显示。因此 Skill 视图只会降级而不会消失:没有 Remote 时给出说明;没有会话时进入等待状态,一旦出现会话或活动会话切换,就自动加载目录,无需手动刷新。命名空间是探测出来的而不是写死的(依次尝试 `skills`、`skill`、`skillCatalog`,再扫描任何含 “skill” 的已注册 `remote.*`),所以 Host 改名也不需要改代码。Skill 在这里是只读的:Host 只提供 `skills/list`(策略 `reader-session-read`),也没有 skills 配置命名空间,因此没有可用于启用或停用条目的 Remote,界面展示当前会话可见的内容,而不提供一个实际无效的开关。界面不会加载 skill 正文。此界面不安装或卸载包、不编辑凭据,也不运行任意修复命令。
|
|
36
40
|
|
|
@@ -51,25 +55,27 @@ npm install @tinyforge/dsh-plugin-manager-wj
|
|
|
51
55
|
## 发布
|
|
52
56
|
|
|
53
57
|
```sh
|
|
54
|
-
npm test # node --test:
|
|
58
|
+
npm test # node --test:27 项检查(视图、工具归属、Host 路由、inject 契约、模块 id、patch 结构)
|
|
55
59
|
npm publish --access public # 发布到 registry.npmjs.org
|
|
56
60
|
```
|
|
57
61
|
|
|
58
|
-
包名带 scope,发布新版本需要 `@tinyforge` npm scope 的维护者权限。发布后给对应提交打 tag(`git tag v1.
|
|
62
|
+
包名带 scope,发布新版本需要 `@tinyforge` npm scope 的维护者权限。发布后给对应提交打 tag(`git tag v1.5.0 && git push --tags`),让 GitHub 历史与 registry 版本对应。
|
|
59
63
|
|
|
60
64
|
## 开发
|
|
61
65
|
|
|
62
|
-
本包使用 ES module
|
|
66
|
+
本包使用 ES module,两个半边各有入口:`index.js` 是 Host 入口,`client.js` 是浏览器界面。本地化包元数据位于 `locale/`,界面完整词典在 `client.js` 中注册。
|
|
67
|
+
|
|
68
|
+
Host 半边把浏览器读不到的东西端出去:官方 `ctx.remote` 是编译期白名单,第三方包无法新增命名空间,`ctx.tools` 又只存在于 Host,因此工具清单经 `ctx.connection.fetch.register()` 以 `GET /api/wj/tool-inventory` 提供给自己的客户端,只对 owner peer 开放。`inject` 只写 `connection`,缺少它会话时插件保持 active 并让页面自行说明,而不是启动失败。
|
|
63
69
|
|
|
64
70
|
`client.js` 以 `__ModuleLoader__.load({ id: '@tinyforge/dsh-plugin-manager-wj', … })` 注册。这个 id 必须是完整包名(含 scope):客户端模块加载器按包名给每个 Loader 行建索引,注册成别的 id 会被判定为"加载了却没有注册自身所在的行",插件因此拿不到 fiber,设置里的标签页完全不出现。改包名时必须在同一次提交里一起改这个 id。
|
|
65
71
|
|
|
66
|
-
- `node --test`
|
|
67
|
-
- `node --check client.js`
|
|
72
|
+
- `node --test` 运行行为检查:四个视图渲染并可切换、访问过的视图保持挂载、搜索与启停作用于当前视图、密钥配置对象不会进入编辑器、打开会话后无需刷新即加载 Skill 目录、改名后的 skills 命名空间能被发现、瞬时目录失败可就地重试恢复、Host 不挂载任何可选服务时标签页仍然注册;Host 半边侧另有一组纯函数与路由检查(MCP 命名、包源码扫描预算、按作用域收集工具、快照形状、`GET /api/wj/tool-inventory` 的 JSON 与响应头、缺少 connection 时不激活路由)。
|
|
73
|
+
- `node --check client.js` 与 `node --check index.js` 检查两个半边的语法。
|
|
68
74
|
- `tests/patch.test.js` 解析 `cordis.patch.yml`,确保没有裸标量以 YAML 保留字符开头 —— 带 scope 的包名必须保持加引号,否则 Host 会拒绝该 bundle patch。
|
|
69
75
|
- `tests/inject.test.js` 把插件的 `inject` 固定为仅核心服务,这样一旦有人重新硬注入可选 remote,测试就会失败,而不是在某些 Host 上悄悄把设置页清空。
|
|
70
76
|
- `tests/module-id.test.js` 断言注册的模块 id 等于 `package.json` 的 `name`,避免改名后浏览器 bundle 悄悄脱离自己的 Loader 行。
|
|
71
77
|
- `tests/harness.html` 在浏览器中用测试夹具挂载真实 `client.js`,不依赖 Node 也能断言同一批行为;直接从磁盘打开并读取 JSON 报告。
|
|
72
|
-
- `tests/parse-check.html` 是最小的浏览器冒烟页:确认 `client.js` 能解析并注册 `settings.plugins.tab
|
|
78
|
+
- `tests/parse-check.html` 是最小的浏览器冒烟页:确认 `client.js` 能解析并注册 `plugins.tab`(插件页的标签槽;旧版的 `settings.plugins.tab` 在当前 DSH 中并不存在,注册会落空)。
|
|
73
79
|
|
|
74
80
|
Harness API 和 Host 行为在 `deepseek-harness` 仓库实现并测试。
|
|
75
81
|
|
package/client.js
CHANGED
|
@@ -13,6 +13,9 @@ window.__ModuleLoader__.load({
|
|
|
13
13
|
// server list of its own: a second list here duplicated that page and read the same remote.
|
|
14
14
|
const TAB_ORDER = ['plugins', 'config', 'skill', 'tools']
|
|
15
15
|
const TAB_KEY = 'dsh-plugin-manager-wj/tab'
|
|
16
|
+
// The Host half serves the tool registry on the shared authenticated `/api` channel; the
|
|
17
|
+
// official Remote table carries no tool namespace, so this route is the only way in.
|
|
18
|
+
const TOOL_INVENTORY_URL = '/api/wj/tool-inventory'
|
|
16
19
|
|
|
17
20
|
function unwrap(result, name) {
|
|
18
21
|
if (!result || result.ok !== true) throw new Error(`${name}: ${result?.error?.message ?? 'unavailable'}`)
|
|
@@ -60,6 +63,38 @@ window.__ModuleLoader__.load({
|
|
|
60
63
|
return source ? `${t(source.layer)} · ${source.identity}` : t('sourceUnknown')
|
|
61
64
|
}
|
|
62
65
|
|
|
66
|
+
// The official Host projects the Loader, not a health model: a failed fiber plus its diagnostic
|
|
67
|
+
// is the whole of what it still reports, and it is exactly what this page diagnoses.
|
|
68
|
+
function findingsOf(entries) {
|
|
69
|
+
const findings = []
|
|
70
|
+
for (const entry of entries) {
|
|
71
|
+
if (entry?.fiberPhase !== 'failed') continue
|
|
72
|
+
const entryId = String(entry.entryId ?? entry.moduleName ?? '')
|
|
73
|
+
findings.push({
|
|
74
|
+
id: `activation:${entryId}`,
|
|
75
|
+
code: 'plugin.activation-failed',
|
|
76
|
+
severity: 'error',
|
|
77
|
+
affectedEntryIds: entry.entryId === undefined ? [] : [entry.entryId],
|
|
78
|
+
remediationEntryIds: [],
|
|
79
|
+
evidence: {
|
|
80
|
+
name: entry.moduleName,
|
|
81
|
+
...(typeof entry.diagnostic === 'string' && entry.diagnostic !== '' ? { detail: entry.diagnostic } : {}),
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
return findings
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// One Loader projection serves both shapes: the official `{ entries, managementAvailable }`
|
|
89
|
+
// snapshot and the older `{ toolRegistrations, mcpClients }` inventory.
|
|
90
|
+
function readInventory(value) {
|
|
91
|
+
return {
|
|
92
|
+
entries: Array.isArray(value?.entries) ? value.entries : [],
|
|
93
|
+
managementAvailable: value?.managementAvailable !== false,
|
|
94
|
+
toolRegistrations: Array.isArray(value?.toolRegistrations) ? value.toolRegistrations : [],
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
63
98
|
const SEVERITY_KEY = { error: 'severityError', warning: 'severityWarning', info: 'severityInfo' }
|
|
64
99
|
|
|
65
100
|
function readStoredTab() {
|
|
@@ -231,19 +266,11 @@ window.__ModuleLoader__.load({
|
|
|
231
266
|
}, h('span', null, item.label), item.count === undefined ? null : h('span', { style: styles.tabCount }, String(item.count)))))
|
|
232
267
|
}
|
|
233
268
|
|
|
234
|
-
function PluginsPanel({ pluginRows, findings, plugins, query, busy,
|
|
269
|
+
function PluginsPanel({ pluginRows, findings, plugins, query, busy, canManage, onToggle, t }) {
|
|
235
270
|
const name = row => row.meta?.title?.en ?? row.meta?.title?.zh ?? row.moduleName
|
|
236
271
|
const severity = value => t(SEVERITY_KEY[value] ?? 'severityInfo')
|
|
237
272
|
return h('div', { style: styles.page },
|
|
238
273
|
h('p', { style: styles.description }, t('pluginsIntro')),
|
|
239
|
-
preview ? h('section', { style: { ...styles.section, padding: 16 }, 'aria-label': t('repairPreview') },
|
|
240
|
-
h('h2', { style: styles.sectionTitle }, t('repairPreview')),
|
|
241
|
-
h('p', { style: styles.meta }, `${t('target')}: ${plugins.find(row => row.entryId === preview.targetEntryId)?.moduleName ?? preview.targetEntryId}`),
|
|
242
|
-
h('p', { style: styles.meta }, `${t('effect')}: ${t('disablePlugin')}`),
|
|
243
|
-
h('p', { style: styles.meta }, `${t('risk')}: ${t(preview.risk)} · ${t(preview.reversible ? 'reversible' : 'notReversible')}`),
|
|
244
|
-
h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
|
245
|
-
h('button', { type: 'button', style: { ...styles.button, ...styles.primary }, disabled: busy === preview.previewId, onClick: () => { void onApplyPreview() } }, t(preview.requiresConfirmation ? 'confirmRepair' : 'applyRepair')),
|
|
246
|
-
h('button', { type: 'button', style: styles.button, onClick: onCancelPreview }, t('cancel')))) : null,
|
|
247
274
|
h(Section, { id: 'findings', title: t('findingsTitle'), count: `${findings.length} ${t('items')}`, empty: t(query ? 'noMatches' : 'noRows') },
|
|
248
275
|
findings.length ? h('ul', { style: styles.list }, findings.map(finding => {
|
|
249
276
|
const severe = finding.severity === 'error'
|
|
@@ -257,11 +284,7 @@ window.__ModuleLoader__.load({
|
|
|
257
284
|
finding.evidence?.name || finding.evidence?.serverName || finding.evidence?.packageName
|
|
258
285
|
? h('div', { style: styles.meta }, `${t('evidence')}: ${finding.evidence.name ?? finding.evidence.serverName ?? finding.evidence.packageName}`)
|
|
259
286
|
: null,
|
|
260
|
-
finding.
|
|
261
|
-
const target = plugins.find(plugin => plugin.entryId === id)
|
|
262
|
-
if (!target) return null
|
|
263
|
-
return h('button', { key: id, type: 'button', style: styles.button, disabled: busy === finding.id, onClick: () => { void onPreview(finding, id) } }, t('previewRepair', { name: target.moduleName }))
|
|
264
|
-
}))
|
|
287
|
+
finding.evidence?.detail ? h('p', { style: { ...styles.message, padding: '4px 0 0' } }, finding.evidence.detail) : null)
|
|
265
288
|
})) : null),
|
|
266
289
|
h(Section, { id: 'plugins', title: t('pluginsTitle'), count: `${pluginRows.length} ${t('items')}`, empty: t(query ? 'noMatches' : 'noRows') },
|
|
267
290
|
pluginRows.length ? h('ul', { style: styles.list }, pluginRows.map(row => h('li', { key: row.entryId, style: styles.row },
|
|
@@ -271,7 +294,7 @@ window.__ModuleLoader__.load({
|
|
|
271
294
|
h('div', { style: styles.meta }, h('span', null, row.entryId), h('span', null, t(row.fiberPhase ?? 'notRunning')), row.readOnlyReason ? h('span', null, t(row.readOnlyReason)) : null)),
|
|
272
295
|
h('button', {
|
|
273
296
|
type: 'button', style: { ...styles.button, ...(row.enabled ? styles.primary : {}) },
|
|
274
|
-
'aria-pressed': String(row.enabled), disabled: busy === row.entryId || row.readOnlyReason !== undefined,
|
|
297
|
+
'aria-pressed': String(row.enabled), disabled: !canManage || busy === row.entryId || row.readOnlyReason !== undefined,
|
|
275
298
|
onClick: () => { void onToggle(row) },
|
|
276
299
|
}, t(row.enabled ? 'disable' : 'enable'))),
|
|
277
300
|
row.diagnostic ? h('p', { style: styles.meta }, t('activationFailed')) : null))) : null))
|
|
@@ -322,19 +345,35 @@ window.__ModuleLoader__.load({
|
|
|
322
345
|
|
|
323
346
|
// Tool ownership is the one diagnostic the MCP settings page does not carry: it answers
|
|
324
347
|
// "which plugin registered this tool", which belongs to plugin management, not to MCP setup.
|
|
325
|
-
function ToolsPanel({
|
|
326
|
-
const
|
|
348
|
+
function ToolsPanel({ tools, needle, rows, onRetry, t }) {
|
|
349
|
+
const scopeText = row => row.scope === 'agent' && row.agentId ? `${t('scoped')} · ${row.agentId}` : t('global')
|
|
350
|
+
const ownerText = row => {
|
|
351
|
+
const owner = row.owner
|
|
352
|
+
if (!owner) return t('ownerUnknown')
|
|
353
|
+
if (owner.kind === 'mcp') return `${t('ownerMcp')}: ${owner.serverName}`
|
|
354
|
+
const base = owner.entryId ? `${owner.moduleName} (${owner.entryId})` : owner.moduleName
|
|
355
|
+
return owner.inferred ? `${base} · ${t('ownerInferred')}` : base
|
|
356
|
+
}
|
|
357
|
+
const copy = tools?.kind === 'loading' ? t('loadingTools')
|
|
358
|
+
: tools?.kind === 'unavailable' ? t('toolInventoryUnavailable')
|
|
359
|
+
: tools?.kind === 'error' ? t('toolInventoryError')
|
|
360
|
+
: needle ? t('noMatches') : t('noRows')
|
|
361
|
+
const retryable = tools?.kind === 'error' || tools?.kind === 'unavailable'
|
|
327
362
|
return h('div', { style: styles.page },
|
|
328
363
|
h('p', { style: styles.description }, t('toolsIntro')),
|
|
329
364
|
h('p', { style: styles.message }, t('toolsMcpNote')),
|
|
330
|
-
h(Section, {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
h('
|
|
334
|
-
|
|
365
|
+
h(Section, {
|
|
366
|
+
id: 'tools', title: t('tools'), count: tools?.kind === 'ready' ? `${rows.length} ${t('items')}` : undefined,
|
|
367
|
+
empty: rows.length ? null : h('div', { style: { display: 'grid', gap: 10, justifyItems: 'start', padding: 16 } },
|
|
368
|
+
h('p', { style: { ...styles.message, padding: 0 } }, copy),
|
|
369
|
+
retryable ? h('button', { type: 'button', style: styles.button, onClick: () => { if (onRetry) onRetry() } }, t('retry')) : null),
|
|
370
|
+
}, rows.length ? h('ul', { style: styles.list }, rows.map(row => h('li', { key: `${row.name}:${row.scope}:${row.agentId ?? ''}`, style: styles.row },
|
|
371
|
+
h('h3', { style: styles.rowTitle }, row.name),
|
|
372
|
+
h('div', { style: styles.meta }, h('span', null, `${t('owner')}: ${ownerText(row)}`), h('span', null, scopeText(row))),
|
|
373
|
+
row.description ? h('p', { style: styles.muted }, row.description) : null))) : null))
|
|
335
374
|
}
|
|
336
375
|
|
|
337
|
-
function ManagerPage({ list, manager, forms, loadSkills, readSessionId, watchSessions, t }) {
|
|
376
|
+
function ManagerPage({ list, manager, forms, loadSkills, loadTools, readSessionId, watchSessions, t }) {
|
|
338
377
|
const initialTab = readStoredTab()
|
|
339
378
|
const [tab, setTab] = React.useState(initialTab)
|
|
340
379
|
const [visited, setVisited] = React.useState([initialTab])
|
|
@@ -343,10 +382,10 @@ window.__ModuleLoader__.load({
|
|
|
343
382
|
const [revision, setRevision] = React.useState(0)
|
|
344
383
|
const [busy, setBusy] = React.useState('')
|
|
345
384
|
const [notice, setNotice] = React.useState('')
|
|
346
|
-
const [preview, setPreview] = React.useState(null)
|
|
347
385
|
const [sessionId, setSessionId] = React.useState(() => typeof readSessionId === 'function' ? readSessionId() : undefined)
|
|
348
386
|
const [skills, setSkills] = React.useState({ kind: 'loading' })
|
|
349
387
|
const [skillsRevision, setSkillsRevision] = React.useState(0)
|
|
388
|
+
const [tools, setTools] = React.useState({ kind: 'idle' })
|
|
350
389
|
|
|
351
390
|
// The catalog follows the active session: opening one (or switching) reloads it without a
|
|
352
391
|
// manual refresh, which is what a Host that requires a live session for `skills/list` needs.
|
|
@@ -381,16 +420,23 @@ window.__ModuleLoader__.load({
|
|
|
381
420
|
React.useEffect(() => {
|
|
382
421
|
let live = true
|
|
383
422
|
Promise.resolve().then(async () => {
|
|
384
|
-
const [inventoryResult,
|
|
423
|
+
const [inventoryResult, settingsResult] = await Promise.allSettled([
|
|
385
424
|
list(),
|
|
386
|
-
manager?.listPlugins ? manager.listPlugins() : Promise.reject(new Error('unavailable')),
|
|
387
|
-
manager?.getHealthSnapshot ? manager.getHealthSnapshot() : Promise.reject(new Error('unavailable')),
|
|
388
425
|
forms?.describe ? forms.describe().ensure().then(() => forms.describe().getSnapshot()) : Promise.reject(new Error('unavailable')),
|
|
389
426
|
])
|
|
390
427
|
if (inventoryResult.status !== 'fulfilled') throw inventoryResult.reason
|
|
391
|
-
const inventory = inventoryResult.value
|
|
392
|
-
|
|
393
|
-
|
|
428
|
+
const inventory = readInventory(inventoryResult.value)
|
|
429
|
+
// The official Host projects the Loader, so entries are the plugin list and a failed
|
|
430
|
+
// fiber is the finding; the older inventory's separate health snapshot no longer exists.
|
|
431
|
+
const plugins = inventory.entries.map(entry => ({
|
|
432
|
+
...entry,
|
|
433
|
+
...(inventory.managementAvailable ? {} : { readOnlyReason: entry.readOnlyReason ?? 'management-required' }),
|
|
434
|
+
}))
|
|
435
|
+
const health = {
|
|
436
|
+
pluginCount: plugins.length,
|
|
437
|
+
enabledCount: plugins.filter(row => row.enabled).length,
|
|
438
|
+
findings: findingsOf(plugins),
|
|
439
|
+
}
|
|
394
440
|
const settings = settingsResult.status === 'fulfilled' ? settingsResult.value.view : undefined
|
|
395
441
|
const provenance = new Map()
|
|
396
442
|
if (settings && manager?.getConfigProvenance) {
|
|
@@ -413,6 +459,20 @@ window.__ModuleLoader__.load({
|
|
|
413
459
|
return () => { live = false }
|
|
414
460
|
}, [list, manager, forms, revision])
|
|
415
461
|
|
|
462
|
+
// The tool registry is session-wide Host state and the route scans package sources once, so
|
|
463
|
+
// it loads when the view is first opened, and again only when the page is refreshed.
|
|
464
|
+
React.useEffect(() => {
|
|
465
|
+
if (tab !== 'tools' || typeof loadTools !== 'function') return undefined
|
|
466
|
+
if (tools.kind !== 'idle' && tools.revision === revision) return undefined
|
|
467
|
+
let live = true
|
|
468
|
+
setTools({ kind: 'loading', revision })
|
|
469
|
+
Promise.resolve()
|
|
470
|
+
.then(() => loadTools())
|
|
471
|
+
.then(result => { if (live) setTools({ ...result, revision }) })
|
|
472
|
+
.catch(() => { if (live) setTools({ kind: 'error', revision }) })
|
|
473
|
+
return () => { live = false }
|
|
474
|
+
}, [loadTools, tab, revision, tools.kind, tools.revision])
|
|
475
|
+
|
|
416
476
|
const refresh = () => {
|
|
417
477
|
setState(current => ({ kind: 'loading', snapshot: current.snapshot }))
|
|
418
478
|
setRevision(value => value + 1)
|
|
@@ -426,9 +486,10 @@ window.__ModuleLoader__.load({
|
|
|
426
486
|
}
|
|
427
487
|
|
|
428
488
|
const applyNotice = result => {
|
|
429
|
-
setNotice(result
|
|
430
|
-
: result
|
|
431
|
-
: result
|
|
489
|
+
setNotice(result?.application === 'applied' ? t('changeApplied')
|
|
490
|
+
: result?.application === 'restart-required' ? t('restartRequired')
|
|
491
|
+
: result?.application === 'overridden' ? t('changeOverridden')
|
|
492
|
+
: result?.application === 'cancelled' ? t('changeCancelled')
|
|
432
493
|
: t('changeFailed'))
|
|
433
494
|
}
|
|
434
495
|
|
|
@@ -445,39 +506,6 @@ window.__ModuleLoader__.load({
|
|
|
445
506
|
}
|
|
446
507
|
}
|
|
447
508
|
|
|
448
|
-
const makePreview = async (finding, targetEntryId) => {
|
|
449
|
-
setBusy(finding.id)
|
|
450
|
-
setPreview(null)
|
|
451
|
-
try {
|
|
452
|
-
const next = unwrap(await manager.previewRemediation({ findingId: finding.id, targetEntryId }), 'pluginManager.previewRemediation')
|
|
453
|
-
if (next.requiresConfirmation) setPreview(next)
|
|
454
|
-
else {
|
|
455
|
-
applyNotice(unwrap(await manager.applyRemediation(next.previewId, false), 'pluginManager.applyRemediation'))
|
|
456
|
-
refresh()
|
|
457
|
-
}
|
|
458
|
-
} catch (_error) {
|
|
459
|
-
setNotice(t('previewOrRepairFailed'))
|
|
460
|
-
} finally {
|
|
461
|
-
setBusy('')
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
const applyPreview = async () => {
|
|
466
|
-
if (!preview) return
|
|
467
|
-
setBusy(preview.previewId)
|
|
468
|
-
try {
|
|
469
|
-
applyNotice(unwrap(await manager.applyRemediation(preview.previewId, preview.requiresConfirmation), 'pluginManager.applyRemediation'))
|
|
470
|
-
setPreview(null)
|
|
471
|
-
refresh()
|
|
472
|
-
} catch (_error) {
|
|
473
|
-
setNotice(t('stalePreview'))
|
|
474
|
-
setPreview(null)
|
|
475
|
-
refresh()
|
|
476
|
-
} finally {
|
|
477
|
-
setBusy('')
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
509
|
const current = state.snapshot
|
|
482
510
|
const inventory = current?.inventory
|
|
483
511
|
const plugins = current?.plugins ?? []
|
|
@@ -485,15 +513,21 @@ window.__ModuleLoader__.load({
|
|
|
485
513
|
const settings = current?.settings
|
|
486
514
|
const needle = query.trim().toLocaleLowerCase()
|
|
487
515
|
const matches = values => !needle || values.filter(Boolean).some(value => String(value).toLocaleLowerCase().includes(needle))
|
|
488
|
-
const pluginRows = plugins.filter(row => matches([row.moduleName, row.entryId, row.meta?.title, row.meta?.description]))
|
|
489
|
-
const findings = (health?.findings ?? []).filter(row => matches([row.id, row.code, row.evidence?.name, row.evidence?.
|
|
490
|
-
|
|
516
|
+
const pluginRows = plugins.filter(row => matches([row.moduleName, row.entryId, row.meta?.title?.en, row.meta?.title?.zh, row.meta?.description]))
|
|
517
|
+
const findings = (health?.findings ?? []).filter(row => matches([row.id, row.code, row.evidence?.name, row.evidence?.detail]))
|
|
518
|
+
// Legacy Hosts answered the inventory with registrations of their own; a Host served by this
|
|
519
|
+
// package answers the `/api` route instead, so either source fills the same rows.
|
|
520
|
+
const legacyRows = (inventory?.toolRegistrations ?? []).filter(row => matches([row.name, row.owner?.moduleName, row.owner?.entryId]))
|
|
521
|
+
const routeRows = tools.kind === 'ready' ? (tools.rows ?? []) : []
|
|
522
|
+
const toolRows = (routeRows.length > 0 ? routeRows : legacyRows).filter(row => matches([row.name, row.owner?.moduleName, row.owner?.entryId, row.owner?.serverName, row.agentId]))
|
|
523
|
+
const toolsView = tools.kind === 'ready' || legacyRows.length > 0 ? { kind: 'ready', rows: toolRows } : tools
|
|
524
|
+
const canManage = inventory !== undefined && inventory.managementAvailable && typeof manager?.setPluginEnabled === 'function'
|
|
491
525
|
|
|
492
526
|
const tabs = [
|
|
493
527
|
{ id: 'plugins', label: t('tabs.plugins'), count: plugins.length },
|
|
494
528
|
{ id: 'config', label: t('tabs.config'), count: settings?.namespaces?.length },
|
|
495
529
|
{ id: 'skill', label: t('tabs.skill'), count: skills?.kind === 'ready' ? skills.items.length : undefined },
|
|
496
|
-
{ id: 'tools', label: t('tabs.tools'), count: toolRows.length },
|
|
530
|
+
{ id: 'tools', label: t('tabs.tools'), count: toolsView.kind === 'ready' ? toolRows.length : undefined },
|
|
497
531
|
]
|
|
498
532
|
|
|
499
533
|
const panel = (id, children) => visited.includes(id) ? h('div', {
|
|
@@ -510,7 +544,7 @@ window.__ModuleLoader__.load({
|
|
|
510
544
|
[health?.enabledCount ?? plugins.filter(row => row.enabled).length, 'enabled'],
|
|
511
545
|
[health ? health.findings.length : '—', 'findings'],
|
|
512
546
|
[skills?.kind === 'ready' ? skills.items.length : '—', 'skills'],
|
|
513
|
-
[
|
|
547
|
+
[toolsView.kind === 'ready' ? toolRows.length : '—', 'toolsStat'],
|
|
514
548
|
]
|
|
515
549
|
const showStats = state.kind === 'ready' && current !== undefined
|
|
516
550
|
|
|
@@ -533,14 +567,13 @@ window.__ModuleLoader__.load({
|
|
|
533
567
|
h('p', { style: styles.message }, t('error')),
|
|
534
568
|
h('button', { type: 'button', style: styles.button, onClick: refresh }, t('retry'))) : null,
|
|
535
569
|
notice ? h('p', { role: 'status', style: styles.message }, notice) : null,
|
|
536
|
-
!health && state.kind === 'ready' ? h('p', { role: 'status', style: styles.message }, t('diagnosticsUnavailable')) : null,
|
|
537
570
|
panel('plugins', h(PluginsPanel, {
|
|
538
|
-
pluginRows, findings, plugins, query: needle, busy,
|
|
539
|
-
onToggle: toggle,
|
|
571
|
+
pluginRows, findings, plugins, query: needle, busy, canManage,
|
|
572
|
+
onToggle: toggle, t,
|
|
540
573
|
})),
|
|
541
574
|
panel('config', h(ConfigPanel, { settings, settingsReady: settings !== undefined, plugins, forms, provenance: current?.provenance, t })),
|
|
542
575
|
panel('skill', h(SkillPanel, { skills, needle, onRetry: refresh, t })),
|
|
543
|
-
panel('tools', h(ToolsPanel, {
|
|
576
|
+
panel('tools', h(ToolsPanel, { tools: toolsView, toolRows, rows: toolRows, needle, onRetry: refresh, t })))
|
|
544
577
|
}
|
|
545
578
|
|
|
546
579
|
return {
|
|
@@ -559,8 +592,9 @@ window.__ModuleLoader__.load({
|
|
|
559
592
|
skillIntro: '当前会话可用的 Skill 目录,按会话工作目录解析,并随会话切换自动刷新;模型可调用与仅用户可调用的条目分开标记。',
|
|
560
593
|
toolsIntro: '运行时工具注册清单,以及每个工具由哪个插件提供、作用于哪个范围。',
|
|
561
594
|
toolsMcpNote: 'MCP 服务器的添加与连接配置由 Host 的 MCP 设置页负责;这里只做插件侧的注册归属诊断,不再重复列出 MCP 服务器。',
|
|
562
|
-
error: '无法读取运行时清单。', retry: '重试', noRows: '暂无记录。', noMatches: '没有匹配的记录。',
|
|
563
|
-
|
|
595
|
+
error: '无法读取运行时清单。', retry: '重试', noRows: '暂无记录。', noMatches: '没有匹配的记录。',
|
|
596
|
+
loadingTools: '正在读取工具注册清单…', toolInventoryUnavailable: '此 Host 未提供工具注册清单路由(/api/wj/tool-inventory),工具视图不可用。', toolInventoryError: '无法读取工具注册清单。',
|
|
597
|
+
ownerUnknown: '未记录(Host 未暴露归属)', ownerMcp: 'MCP 服务器', ownerInferred: '推断',
|
|
564
598
|
findingsTitle: '健康诊断', pluginsTitle: '插件', configurationTitle: '配置管理', plugins: '插件', enabled: '已启用', findings: '发现项', severity: '严重程度', affected: '相关插件', evidence: '证据',
|
|
565
599
|
configEmpty: 'Host 未暴露可编辑的配置命名空间。', configUnavailable: '此 Host 未提供设置表单接口,配置视图不可用。',
|
|
566
600
|
skillsTitle: 'Skill 目录', skillEmpty: '当前会话没有可用的 Skill。', skillUnsupported: '此 Host 未提供 skills 接口,Skill 目录不可用。', skillNoSession: '尚无可用会话。打开或切换会话后,这里会自动加载,无需刷新。', skillError: '无法读取 Skill 目录。', loadingSkills: '正在读取 Skill 目录…',
|
|
@@ -570,8 +604,7 @@ window.__ModuleLoader__.load({
|
|
|
570
604
|
'bundle.compatibility-rejected': '组合包版本不兼容', 'bundle.dependency-invalid': '所选依赖无效', severityError: '错误', severityWarning: '警告', severityInfo: '提示', warning: '警告', info: '提示',
|
|
571
605
|
source: '配置来源', shadowed: '被覆盖来源', sourceUnknown: '未知(Host 未提供来源)', bundle: '组合包', profile: 'Profile', home: 'Home', invocation: '本次启动',
|
|
572
606
|
save: '保存', reset: '恢复继承值', saved: '已保存', revisionConflict: '配置已被其他操作修改;草稿仍保留,请刷新后重试。', saveFailed: '保存失败,草稿已保留。', invalidNumber: '请输入有效数字。', loadingForm: '正在载入表单…', formUnavailable: '此配置表单当前不可用。', noSchemaFields: '没有可编辑的 schema 字段。', secretsHidden: '密钥字段已隐藏({count} 项)。',
|
|
573
|
-
|
|
574
|
-
changeApplied: '设置已保存并应用。', restartRequired: '设置已保存;重启后生效。', changeOverridden: '设置已保存,但被更高优先级配置覆盖。', changeFailed: 'Host 未能应用此更改。',
|
|
607
|
+
changeApplied: '设置已保存并应用。', restartRequired: '设置已保存;重启后生效。', changeOverridden: '设置已保存,但被更高优先级配置覆盖。', changeCancelled: 'Host 取消了此更改,未做修改。', changeFailed: 'Host 未能应用此更改。',
|
|
575
608
|
enable: '启用', disable: '停用', disabled: '已停用', enabledTag: '已启用', disabledTag: '已停用', active: '运行中', failed: '失败', loadingPhase: '加载中', pending: '等待中', unloading: '卸载中', notRunning: '未运行',
|
|
576
609
|
skillReadOnly: 'Skill 的启用与停用由 profile 的 skills 目录与指令文件决定;本 Host 未提供开关接口,因此这里只读展示当前会话可见的条目。',
|
|
577
610
|
'management-required': '管理服务受保护', unaddressable: '此条目无法通过当前 Profile 修改', activationFailed: '插件未能完成启动。', owner: '所属插件', tools: '工具注册', global: '全局', scoped: '作用域',
|
|
@@ -585,8 +618,9 @@ window.__ModuleLoader__.load({
|
|
|
585
618
|
skillIntro: 'Skills available to the current session, resolved from its working directory and reloaded automatically when the session changes; model-invocable and user-only entries are marked separately.',
|
|
586
619
|
toolsIntro: 'Runtime tool registrations, with the plugin that provides each tool and the scope it applies to.',
|
|
587
620
|
toolsMcpNote: 'Adding and connecting MCP servers belongs to the Host’s MCP settings page; this view covers plugin-side ownership only and deliberately lists no MCP servers of its own.',
|
|
588
|
-
error: 'The runtime inventory could not be read.', retry: 'Retry', noRows: 'No records.', noMatches: 'No matching records.',
|
|
589
|
-
|
|
621
|
+
error: 'The runtime inventory could not be read.', retry: 'Retry', noRows: 'No records.', noMatches: 'No matching records.',
|
|
622
|
+
loadingTools: 'Reading the tool registry…', toolInventoryUnavailable: 'This Host does not serve the tool registry route (/api/wj/tool-inventory); the tool view is unavailable.', toolInventoryError: 'The tool registry could not be read.',
|
|
623
|
+
ownerUnknown: 'Not recorded (the Host exposes no owner)', ownerMcp: 'MCP server', ownerInferred: 'inferred',
|
|
590
624
|
findingsTitle: 'Health findings', pluginsTitle: 'Plugins', configurationTitle: 'Configuration', plugins: 'plugins', enabled: 'enabled', findings: 'findings', severity: 'Severity', affected: 'Affected plugins', evidence: 'Evidence',
|
|
591
625
|
configEmpty: 'The Host exposes no editable configuration namespaces.', configUnavailable: 'This Host does not expose settings forms; configuration is unavailable.',
|
|
592
626
|
skillsTitle: 'Skill catalog', skillEmpty: 'The current session has no available skills.', skillUnsupported: 'This Host does not expose the skills interface; the catalog is unavailable.', skillNoSession: 'No session yet. Open or switch a session and this view loads automatically — no refresh needed.', skillError: 'The skill catalog could not be read.', loadingSkills: 'Reading the skill catalog…',
|
|
@@ -596,8 +630,7 @@ window.__ModuleLoader__.load({
|
|
|
596
630
|
'bundle.compatibility-rejected': 'Bundle version is incompatible', 'bundle.dependency-invalid': 'Selected dependency is invalid', severityError: 'Error', severityWarning: 'Warning', severityInfo: 'Info', warning: 'Warning', info: 'Info',
|
|
597
631
|
source: 'Configuration source', shadowed: 'Shadowed sources', sourceUnknown: 'Unknown (Host did not provide a source)', bundle: 'Bundle', profile: 'Profile', home: 'Home', invocation: 'This launch',
|
|
598
632
|
save: 'Save', reset: 'Reset to inherited value', saved: 'Saved', revisionConflict: 'Configuration changed elsewhere. Your draft is kept; refresh before retrying.', saveFailed: 'Save failed. Your draft is kept.', invalidNumber: 'Enter a valid number.', loadingForm: 'Loading form…', formUnavailable: 'This configuration form is unavailable.', noSchemaFields: 'No editable schema fields.', secretsHidden: '{count} secret fields are hidden.',
|
|
599
|
-
|
|
600
|
-
changeApplied: 'The change was saved and applied.', restartRequired: 'The change was saved and will apply after restart.', changeOverridden: 'The change was saved but overridden by a higher-priority configuration.', changeFailed: 'The Host could not apply this change.',
|
|
633
|
+
changeApplied: 'The change was saved and applied.', restartRequired: 'The change was saved and will apply after restart.', changeOverridden: 'The change was saved but overridden by a higher-priority configuration.', changeCancelled: 'The Host cancelled this change; nothing was modified.', changeFailed: 'The Host could not apply this change.',
|
|
601
634
|
enable: 'Enable', disable: 'Disable', disabled: 'Disabled', enabledTag: 'Enabled', disabledTag: 'Disabled', active: 'Active', failed: 'Failed', loadingPhase: 'Loading', pending: 'Pending', unloading: 'Unloading', notRunning: 'Not running',
|
|
602
635
|
skillReadOnly: 'Skills are enabled by the profile’s skills directories and instruction files; this Host exposes no toggle, so the catalog is read-only.',
|
|
603
636
|
'management-required': 'Management service is protected', unaddressable: 'This entry cannot be changed by the current profile', activationFailed: 'The plugin did not finish starting.', owner: 'Owner', tools: 'Tool registrations', global: 'Global', scoped: 'Scoped',
|
|
@@ -617,6 +650,24 @@ window.__ModuleLoader__.load({
|
|
|
617
650
|
if (!inventory || typeof inventory.list !== 'function') throw new Error('pluginInventory.list: unavailable')
|
|
618
651
|
return unwrap(await inventory.list(), 'pluginInventory.list')
|
|
619
652
|
}
|
|
653
|
+
// The Host half publishes the tool registry on the shared authenticated `/api` channel:
|
|
654
|
+
// `ctx.remote` carries no tool namespace and a Client plugin cannot add one.
|
|
655
|
+
const loadTools = async () => {
|
|
656
|
+
if (typeof fetch !== 'function') return { kind: 'unavailable' }
|
|
657
|
+
let response
|
|
658
|
+
try {
|
|
659
|
+
response = await fetch(TOOL_INVENTORY_URL, { credentials: 'same-origin', headers: { accept: 'application/json' } })
|
|
660
|
+
} catch (_error) {
|
|
661
|
+
return { kind: 'error' }
|
|
662
|
+
}
|
|
663
|
+
if (!response || response.ok !== true) return { kind: 'unavailable' }
|
|
664
|
+
try {
|
|
665
|
+
const body = await response.json()
|
|
666
|
+
return { kind: 'ready', rows: Array.isArray(body?.tools) ? body.tools : [] }
|
|
667
|
+
} catch (_error) {
|
|
668
|
+
return { kind: 'error' }
|
|
669
|
+
}
|
|
670
|
+
}
|
|
620
671
|
const forms = service('configForms')
|
|
621
672
|
|
|
622
673
|
// The skill catalog is session-scoped (`skills/list`) and optional. Both services are read
|
|
@@ -667,10 +718,10 @@ window.__ModuleLoader__.load({
|
|
|
667
718
|
|
|
668
719
|
// No `mcpClientStatus/list` probe lives here: the MCP settings bundle owns MCP server state
|
|
669
720
|
// and its page, and reading that remote from two pages is what made the two views conflict.
|
|
670
|
-
ctx.slots.inject('
|
|
671
|
-
name: '
|
|
721
|
+
ctx.slots.inject('plugins.tab', () => ctx.slots.register({
|
|
722
|
+
name: 'plugins.tab', id: 'wj-registration-inventory', order: 20,
|
|
672
723
|
label: () => t('tab'), locale: NS,
|
|
673
|
-
inject: () => ({ list, manager: namespace('pluginManager'), forms, loadSkills, readSessionId: activeSessionId, watchSessions }),
|
|
724
|
+
inject: () => ({ list, manager: namespace('pluginManager'), forms, loadSkills, loadTools, readSessionId: activeSessionId, watchSessions }),
|
|
674
725
|
}, ManagerPage))
|
|
675
726
|
},
|
|
676
727
|
}
|
package/index.js
CHANGED
|
@@ -1,3 +1,294 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Host half: serve the runtime tool registry the Web Client cannot read directly.
|
|
4
|
+
*
|
|
5
|
+
* The Client half lives in `client.js` and runs in the browser. It can only read the Host through
|
|
6
|
+
* Remote namespaces, and the official Host exposes no tool registry there: `ctx.tools` is a Host
|
|
7
|
+
* service, and a third-party package cannot add a Remote namespace (the Client's `ctx.remote`
|
|
8
|
+
* table is a compiled allowlist). A plain authenticated Fetch route on the shared `/api` channel
|
|
9
|
+
* is the supported way for a package to hand its own Host-side data to its own Client half.
|
|
10
|
+
*
|
|
11
|
+
* Ownership is the one fact no Host service records: `ctx.tools` keeps definitions keyed by name
|
|
12
|
+
* and discards the registering context. The route therefore reports `owner.kind === 'mcp'` for
|
|
13
|
+
* MCP tool names (their names carry the server) and falls back to a package-source scan, which is
|
|
14
|
+
* marked `inferred` so the page never presents a guess as a Host fact.
|
|
15
|
+
*/
|
|
16
|
+
import { readFileSync } from 'node:fs'
|
|
17
|
+
import { dirname, isAbsolute, join } from 'node:path'
|
|
18
|
+
|
|
19
|
+
/** Absolute path below the shared `/api` channel. */
|
|
20
|
+
export const TOOL_INVENTORY_PATH = '/api/wj/tool-inventory'
|
|
21
|
+
|
|
22
|
+
/** Do not read a single package bundle larger than this; a minified bundle above it is not scanned. */
|
|
23
|
+
const FILE_LIMIT_BYTES = 4 * 1024 * 1024
|
|
24
|
+
|
|
25
|
+
/** Total bytes the source scan may read for one snapshot. */
|
|
26
|
+
const TOTAL_LIMIT_BYTES = 64 * 1024 * 1024
|
|
27
|
+
|
|
28
|
+
/** Total package files the source scan may open for one snapshot. */
|
|
29
|
+
const FILE_BUDGET = 240
|
|
30
|
+
|
|
31
|
+
/** How long one computed snapshot is reused; the page refreshes on demand, not per keystroke. */
|
|
32
|
+
const CACHE_TTL_MS = 30_000
|
|
33
|
+
|
|
34
|
+
/** Keys in a package bundle that make a tool-name literal worth scanning for. */
|
|
35
|
+
const REGISTRATION_MARKERS = /tools\s*\.\s*register|defineTool|registerTool/
|
|
36
|
+
|
|
37
|
+
const TOOL_NAME_LITERAL = /\bname\s*:\s*(['"])([A-Za-z0-9_$.:-]{1,120})\1/g
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Serve tool registrations over one authenticated GET route.
|
|
41
|
+
* @param ctx - Host context; `connection` is requested optionally so a Host without the shared
|
|
42
|
+
* channel keeps the plugin active and the page degrades to its own explanation.
|
|
43
|
+
*/
|
|
44
|
+
export function apply(ctx) {
|
|
45
|
+
let cache
|
|
46
|
+
|
|
47
|
+
const snapshot = async () => {
|
|
48
|
+
const now = Date.now()
|
|
49
|
+
if (cache !== undefined && now - cache.at < CACHE_TTL_MS) return cache.value
|
|
50
|
+
const value = buildSnapshot(ctx)
|
|
51
|
+
cache = { at: now, value }
|
|
52
|
+
return value
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// A Host that mounts no shared channel, or a route the channel refuses, must not fail this
|
|
56
|
+
// plugin's activation: the page already explains a missing route on its own.
|
|
57
|
+
try {
|
|
58
|
+
ctx.inject(['connection'], injected => {
|
|
59
|
+
if (typeof injected.connection?.fetch?.register !== 'function') return
|
|
60
|
+
injected.effect(() => {
|
|
61
|
+
try {
|
|
62
|
+
const dispose = injected.connection.fetch.register({
|
|
63
|
+
path: TOOL_INVENTORY_PATH,
|
|
64
|
+
methods: ['GET'],
|
|
65
|
+
requestBody: 'buffered',
|
|
66
|
+
fetch: async () => jsonResponse(await snapshot()),
|
|
67
|
+
})
|
|
68
|
+
return () => { void Promise.resolve(dispose).catch(() => {}) }
|
|
69
|
+
} catch (error) {
|
|
70
|
+
warn(injected, 'tool inventory route registration failed', error)
|
|
71
|
+
return undefined
|
|
72
|
+
}
|
|
73
|
+
}, 'plugin-manager-wj: tool inventory route')
|
|
74
|
+
})
|
|
75
|
+
} catch (error) {
|
|
76
|
+
warn(ctx, 'tool inventory route unavailable', error)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Build one snapshot of the live registry.
|
|
82
|
+
* @param ctx - Host context.
|
|
83
|
+
* @param options - test seams: `readFile`, `maxFiles`, `maxBytes`.
|
|
84
|
+
* @returns Tool rows with scope and best-effort owner, plus the scan limit that applied.
|
|
85
|
+
*/
|
|
86
|
+
export function buildSnapshot(ctx, options = {}) {
|
|
87
|
+
const rows = collectTools(ctx)
|
|
88
|
+
const owners = ownersOf(ctx, rows.map(row => row.name), options)
|
|
89
|
+
const tools = rows.map(row => {
|
|
90
|
+
const owner = owners.get(row.name)
|
|
91
|
+
return owner === undefined ? row : { ...row, owner }
|
|
92
|
+
})
|
|
93
|
+
return {
|
|
94
|
+
version: 1,
|
|
95
|
+
generatedAt: new Date().toISOString(),
|
|
96
|
+
tools,
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Read every Tool schema visible to this Host, globally and in each live Agent scope.
|
|
102
|
+
* @param ctx - Host context with the `tools` service.
|
|
103
|
+
* @returns Rows in name order; a scoped registration that shadows a global one keeps both rows.
|
|
104
|
+
*/
|
|
105
|
+
export function collectTools(ctx) {
|
|
106
|
+
const tools = optional(ctx, 'tools')
|
|
107
|
+
const rows = []
|
|
108
|
+
const seen = new Set()
|
|
109
|
+
const add = (schema, scope, agentId) => {
|
|
110
|
+
const toolName = schema?.name
|
|
111
|
+
if (typeof toolName !== 'string' || toolName.length === 0) return
|
|
112
|
+
const key = `${scope}:${agentId ?? ''}:${toolName}`
|
|
113
|
+
if (seen.has(key)) return
|
|
114
|
+
seen.add(key)
|
|
115
|
+
const base = { name: toolName, scope, ...(agentId === undefined ? {} : { agentId }) }
|
|
116
|
+
const description = typeof schema?.description === 'string' ? schema.description : undefined
|
|
117
|
+
rows.push(description === undefined ? base : { ...base, description })
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
for (const schema of schemasOf(tools, undefined)) add(schema, 'global')
|
|
121
|
+
|
|
122
|
+
for (const agent of listAgents(ctx)) {
|
|
123
|
+
const agentId = agentIdentity(agent)
|
|
124
|
+
if (agentId === undefined) continue
|
|
125
|
+
for (const schema of schemasOf(tools, agent)) add(schema, 'agent', agentId)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return rows.sort((left, right) => left.name.localeCompare(right.name))
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Attribute each tool name to a provider where the Host makes that knowable.
|
|
133
|
+
* @param ctx - Host context.
|
|
134
|
+
* @param names - Live tool names.
|
|
135
|
+
* @param options - test seams for the package-source scan.
|
|
136
|
+
* @returns Name to owner map; absent names stay unattributed rather than guessed.
|
|
137
|
+
*/
|
|
138
|
+
export function ownersOf(ctx, names, options = {}) {
|
|
139
|
+
const owners = new Map()
|
|
140
|
+
for (const toolName of names) {
|
|
141
|
+
const mcp = mcpOwner(toolName)
|
|
142
|
+
if (mcp !== undefined) owners.set(toolName, mcp)
|
|
143
|
+
}
|
|
144
|
+
const pending = names.filter(toolName => !owners.has(toolName))
|
|
145
|
+
if (pending.length === 0) return owners
|
|
146
|
+
|
|
147
|
+
for (const source of readPackageSources(ctx, options)) {
|
|
148
|
+
const declared = declaredToolNames(source.text)
|
|
149
|
+
if (declared.size === 0) continue
|
|
150
|
+
for (const toolName of pending) {
|
|
151
|
+
if (owners.has(toolName)) continue
|
|
152
|
+
if (!declared.has(toolName)) continue
|
|
153
|
+
owners.set(toolName, {
|
|
154
|
+
kind: 'package',
|
|
155
|
+
moduleName: source.moduleName,
|
|
156
|
+
...(source.entryId === undefined ? {} : { entryId: source.entryId }),
|
|
157
|
+
inferred: true,
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return owners
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Recognize the MCP naming convention `mcp__<server>__<tool>`.
|
|
166
|
+
* @param toolName - Public tool name.
|
|
167
|
+
* @returns The MCP server owner, or undefined for a non-MCP name.
|
|
168
|
+
*/
|
|
169
|
+
export function mcpOwner(toolName) {
|
|
170
|
+
const match = /^mcp__(.+?)__[A-Za-z0-9_]/.exec(toolName)
|
|
171
|
+
return match === null ? undefined : { kind: 'mcp', serverName: match[1] }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Collect every `name: '…'` literal from a bundle that registers tools.
|
|
176
|
+
* @param text - Package bundle source.
|
|
177
|
+
* @returns Declared names; empty when the bundle registers no tools at all.
|
|
178
|
+
*/
|
|
179
|
+
export function declaredToolNames(text) {
|
|
180
|
+
const names = new Set()
|
|
181
|
+
if (typeof text !== 'string' || !REGISTRATION_MARKERS.test(text)) return names
|
|
182
|
+
TOOL_NAME_LITERAL.lastIndex = 0
|
|
183
|
+
let match
|
|
184
|
+
while ((match = TOOL_NAME_LITERAL.exec(text)) !== null) names.add(match[2])
|
|
185
|
+
return names
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Read the entrypoint bundle of each loaded plugin package, within a fixed budget.
|
|
190
|
+
* @param ctx - Host context with `loader` and the optional `pluginPackages` service.
|
|
191
|
+
* @param options - test seams: `readFile`, `maxFiles`, `maxBytes`.
|
|
192
|
+
* @returns Entry id, module name and bundle text for every readable package.
|
|
193
|
+
*/
|
|
194
|
+
export function readPackageSources(ctx, options = {}) {
|
|
195
|
+
const loader = optional(ctx, 'loader')
|
|
196
|
+
const packages = optional(ctx, 'pluginPackages')
|
|
197
|
+
const entries = typeof loader?.entries === 'function' ? loader.entries() : []
|
|
198
|
+
const readFile = options.readFile ?? readFileSync
|
|
199
|
+
const maxFiles = options.maxFiles ?? FILE_BUDGET
|
|
200
|
+
const maxBytes = options.maxBytes ?? TOTAL_LIMIT_BYTES
|
|
201
|
+
|
|
202
|
+
const sources = []
|
|
203
|
+
let files = 0
|
|
204
|
+
let bytes = 0
|
|
205
|
+
|
|
206
|
+
for (const entry of entries) {
|
|
207
|
+
if (files >= maxFiles || bytes >= maxBytes) break
|
|
208
|
+
const moduleName = entry?.options?.name
|
|
209
|
+
if (typeof moduleName !== 'string' || moduleName.length === 0) continue
|
|
210
|
+
const base = entry?.parent?.tree?.ctx?.baseUrl
|
|
211
|
+
let manifestPath
|
|
212
|
+
try {
|
|
213
|
+
manifestPath = packages?.packageOf?.(moduleName, base)?.manifestPath
|
|
214
|
+
} catch (_error) {
|
|
215
|
+
manifestPath = undefined
|
|
216
|
+
}
|
|
217
|
+
if (typeof manifestPath !== 'string') continue
|
|
218
|
+
try {
|
|
219
|
+
const manifest = JSON.parse(readFile(manifestPath, 'utf8'))
|
|
220
|
+
const main = typeof manifest?.main === 'string' && manifest.main.length > 0 ? manifest.main : 'index.js'
|
|
221
|
+
const file = isAbsolute(main) ? main : join(dirname(manifestPath), main)
|
|
222
|
+
const text = readFile(file, 'utf8')
|
|
223
|
+
if (typeof text !== 'string' || text.length === 0 || text.length > FILE_LIMIT_BYTES) continue
|
|
224
|
+
files += 1
|
|
225
|
+
bytes += text.length
|
|
226
|
+
sources.push({ entryId: entry.id, moduleName, text })
|
|
227
|
+
} catch (_error) {
|
|
228
|
+
// A package with an unreadable manifest or missing entrypoint simply cannot be scanned.
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return sources
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Read the Tool schemas for one scope; a Host without the service yields none. */
|
|
236
|
+
function schemasOf(tools, scope) {
|
|
237
|
+
if (typeof tools?.schemas !== 'function') return []
|
|
238
|
+
try {
|
|
239
|
+
const schemas = tools.schemas(scope)
|
|
240
|
+
return Array.isArray(schemas) ? schemas : []
|
|
241
|
+
} catch (_error) {
|
|
242
|
+
return []
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** Read the live Agents; a Host without the service yields none. */
|
|
247
|
+
function listAgents(ctx) {
|
|
248
|
+
const agents = optional(ctx, 'agents')
|
|
249
|
+
if (typeof agents?.list !== 'function') return []
|
|
250
|
+
try {
|
|
251
|
+
const rows = agents.list()
|
|
252
|
+
return Array.isArray(rows) ? rows : []
|
|
253
|
+
} catch (_error) {
|
|
254
|
+
return []
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** The stable identity of one live Agent, however that Agent object spells it. */
|
|
259
|
+
function agentIdentity(agent) {
|
|
260
|
+
const candidates = [agent?.id, agent?.session?.id, agent?.sessionId]
|
|
261
|
+
for (const candidate of candidates) {
|
|
262
|
+
if (typeof candidate === 'string' && candidate.length > 0) return candidate
|
|
263
|
+
}
|
|
264
|
+
return undefined
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Read one optional Cordis service without turning a missing service into an activation failure. */
|
|
268
|
+
function optional(ctx, serviceName) {
|
|
269
|
+
try {
|
|
270
|
+
return ctx.get(serviceName)
|
|
271
|
+
} catch (_error) {
|
|
272
|
+
return undefined
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** Log through the Host logger when it is available; diagnostics never throw. */
|
|
277
|
+
function warn(ctx, message, error) {
|
|
278
|
+
try {
|
|
279
|
+
ctx.logger?.warn?.(`plugin-manager-wj: ${message}`, error)
|
|
280
|
+
} catch (_error) {
|
|
281
|
+
// A Host without a logger keeps the failure silent rather than failing activation.
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** One JSON response for the shared Fetch channel. */
|
|
286
|
+
function jsonResponse(value) {
|
|
287
|
+
return new Response(JSON.stringify(value), {
|
|
288
|
+
status: 200,
|
|
289
|
+
headers: {
|
|
290
|
+
'content-type': 'application/json; charset=utf-8',
|
|
291
|
+
'cache-control': 'no-store',
|
|
292
|
+
},
|
|
293
|
+
})
|
|
294
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinyforge/dsh-plugin-manager-wj",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Switchable plugin, configuration, skill and tool-ownership views with health diagnostics, configuration provenance, and tool inventory for DeepSeek Harness.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|