dsh-toolview-kit 0.0.0-stage → 0.3.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/CHANGELOG.md +36 -0
- package/LICENSE +21 -0
- package/README.md +133 -2
- package/assets/dsh-toolview-kit-diff.png +0 -0
- package/assets/dsh-toolview-kit-shell.png +0 -0
- package/config/tools.json +116 -0
- package/cordis.patch.yml +4 -0
- package/docs/cards.md +70 -0
- package/docs/development.md +52 -0
- package/docs/installation.md +93 -0
- package/lib/client.js +823 -0
- package/lib/index.js +12 -0
- package/package.json +80 -4
- package/screenshots.json +4 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.2 - 2026-12-01
|
|
4
|
+
|
|
5
|
+
- Added `assets/` screenshots of the shell card and the `ops_edit_file` Diff card, plus a `screenshots.json` manifest that plugin storefronts read.
|
|
6
|
+
- Declared optional `dsh.catalog` metadata (category, bilingual summary, capability tags) so catalogs can list the plugin without scraping.
|
|
7
|
+
- Fixed a doubled `github.com` prefix in the README clone URL.
|
|
8
|
+
|
|
9
|
+
## 0.3.1 - 2026-12-01
|
|
10
|
+
|
|
11
|
+
- Refined the public README with direct installation steps, clearer coverage, configuration, limits, and troubleshooting.
|
|
12
|
+
|
|
13
|
+
## 0.3.0 - 2026-11-30
|
|
14
|
+
|
|
15
|
+
- Renamed the package and repository to `dsh-toolview-kit` for shell, file, and MCP cards.
|
|
16
|
+
- Added a readable themed Diff card for `ops_edit_file` and other `file-write` tools.
|
|
17
|
+
- Added `expectedRevision` metadata and documented the Windows `mtime` limitation of `ops_edit_file`.
|
|
18
|
+
|
|
19
|
+
## 0.2.0 - 2026-11-30
|
|
20
|
+
|
|
21
|
+
- Rendered JumpServer MCP receipts as readable host output instead of raw JSON.
|
|
22
|
+
- Added per-host output, job/state metadata, and exit-code extraction for remote command results.
|
|
23
|
+
- Switched card surfaces, borders, text, status colors, and code font to DSH `--dsw-*` theme tokens so dark skins apply automatically.
|
|
24
|
+
- Added regression coverage for single-host and multi-host JumpServer receipts and host theme token usage.
|
|
25
|
+
|
|
26
|
+
## 0.1.1 - 2026-11-30
|
|
27
|
+
|
|
28
|
+
- Added `npm run verify` for profile dependency, bundle, junction, and payload checks.
|
|
29
|
+
- Documented local installation verification and clarified that the verifier is read-only.
|
|
30
|
+
|
|
31
|
+
## 0.1.0 - 2026-11-30
|
|
32
|
+
|
|
33
|
+
- Initial data-driven DSH toolview plugin.
|
|
34
|
+
- Added readable shell cards for `ops_bash` and JumpServer command tools.
|
|
35
|
+
- Added file-read and file-write cards for the complete dsh-ops file-tool set.
|
|
36
|
+
- Added local build, loader, mapping, and registration tests.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
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
CHANGED
|
@@ -1,3 +1,134 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-toolview-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
给 DSH 的工具调用换上可读卡片。
|
|
4
|
+
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](package.json)
|
|
7
|
+
[](package.json)
|
|
8
|
+
|
|
9
|
+
DSH 的对话界面按工具名挑卡片视图:`bash`、`read`、`grep` 有专属样式,其它名字落到通用 JSON 渲染器。`dsh-ops` 发布的是 `ops_*`,JumpServer MCP 发布的是 `mcp__*`,两边都不在名单里,于是命令、文件读写和远程执行都以原始 JSON 出现。
|
|
10
|
+
|
|
11
|
+
这个插件给这些名字注册卡片:命令显示成终端块,文件操作显示路径和逐行 Diff,JumpServer 回执按资产拆成文本。
|
|
12
|
+
|
|
13
|
+
## 界面
|
|
14
|
+
|
|
15
|
+
实机截图,Bash 命令卡片把命令、输出和退出码放在同一张卡里。
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
`ops_edit_file` 的 Diff 卡片直接给出逐行改动和 `expectedRevision`。
|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
截图里的本机路径已遮盖。
|
|
24
|
+
|
|
25
|
+
## 安装
|
|
26
|
+
|
|
27
|
+
目前从源码装:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
git clone https://github.com/ViCrack/dsh-toolview-kit.git
|
|
31
|
+
cd dsh-toolview-kit
|
|
32
|
+
npm test
|
|
33
|
+
dsh plugin --profile desktop add file://$PWD
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`npm test` 会先构建再跑 13 个用例,覆盖工具映射、loader 形状、注册数量、卡片渲染、Diff 和 JumpServer 回执。测试不需要 DSH 运行时:用 `node:vm` 模拟 `window.__ModuleLoader__`,配一个极小的 React stub 渲染并断言文本。
|
|
37
|
+
|
|
38
|
+
装完重开 DSH Desktop。客户端 bundle 在启动时加载,热装不会立刻出现卡片。
|
|
39
|
+
|
|
40
|
+
包已按 npm 发布的形式打包(`npm pack` 产出 11 个文件),但还没发布到 registry。等发布后可改用:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
dsh plugin --profile desktop add dsh-toolview-kit
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
手工登记、junction 接入、回滚和排障写在 [docs/installation.md](docs/installation.md)。
|
|
47
|
+
|
|
48
|
+
## 覆盖范围
|
|
49
|
+
|
|
50
|
+
| 卡片族 | 工具 |
|
|
51
|
+
| --- | --- |
|
|
52
|
+
| shell | `ops_bash` |
|
|
53
|
+
| shell(远程) | `mcp__jumpserver__execute_command`、`mcp__jumpserver-prod__execute_command`、`mcp__jumpserver__submit_command`、`mcp__jumpserver-prod__submit_command` |
|
|
54
|
+
| file-read | `ops_inspect_local_file`、`ops_grep`、`ops_glob`、`ops_stat`、`ops_diff`、`ops_read_files`、`ops_read_table`、`ops_read_docx`、`ops_read_pdf` |
|
|
55
|
+
| file-write | `ops_replace`、`ops_write_file`、`ops_edit_file`、`ops_copy`、`ops_move`、`ops_remove` |
|
|
56
|
+
|
|
57
|
+
共 20 个工具名,全部来自 `config/tools.json`。要加新工具,改映射表再构建,不用写组件。
|
|
58
|
+
|
|
59
|
+
## 卡片内容
|
|
60
|
+
|
|
61
|
+
折叠行给出状态点(运行中、成功、失败、取消)、标题、命令首行或目标路径、MCP 的目标资产、非零退出码。展开后是命令块、输出块、路径与查询条件、CWD 和状态,每块都能一键复制。
|
|
62
|
+
|
|
63
|
+
几处取数细节:
|
|
64
|
+
|
|
65
|
+
- 退出码取结果尾部的 `[exit code: N]`,展示时从正文剥离;`interrupted` 单独标成取消。
|
|
66
|
+
- JumpServer 返回的是 `{ok, state, job_id, out, results[]}` 这种作业回执。卡片会取出 `results[].ip` 和 `out`、`state`、`job_id`,把 `host | CHANGED | rc=0 >>` 这类 Ansible 包头换成小标题并折成 `exit N`,多台资产各占一段。
|
|
67
|
+
- `ops_edit_file` 不是 DSH 内置的 `edit`,拿不到官方 diff 视图。插件读 `edits[].oldText` / `newText`(兼容 `old_string` / `new_string`)画逐行 Diff,并显示 `expectedRevision`。
|
|
68
|
+
|
|
69
|
+
## 主题
|
|
70
|
+
|
|
71
|
+
卡片不定义配色,只读 DSH 的主题令牌:`--dsw-alias-bg-layer-2`(卡片面)、`--dsw-alias-markdown-code-block(-banner)`(代码区)、`--dsw-alias-label-primary/secondary/tertiary/caption`、`--dsw-alias-border-l1/l2/l4`、`--dsw-alias-state-success/error/warn/business-primary`、`--ds-font-family-code`。
|
|
72
|
+
|
|
73
|
+
宿主在 `body`(浅色)与 `body[data-ds-dark-theme]`(深色)上分别给出这些值。皮肤插件覆盖的也是同一批名字,比如 `dsh-bloom-theme` 通过 `ctx.theme.overrideTokens` 把它们写成 `body` 行内变量。所以切换皮肤后卡片自动跟着变色,不需要插件之间互相感知。
|
|
74
|
+
|
|
75
|
+
兜底值选 `inherit` 和 `transparent`,不写死颜色。就算宿主一个令牌都没定义,卡片也只是继承周围的文字和底色,不会在深色会话里闪出白块。
|
|
76
|
+
|
|
77
|
+
## 配置
|
|
78
|
+
|
|
79
|
+
`config/tools.json` 是唯一数据源:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"ops_bash": {
|
|
84
|
+
"kind": "shell",
|
|
85
|
+
"label": "Bash",
|
|
86
|
+
"commandKeys": ["command", "cmd", "script"],
|
|
87
|
+
"targetKeys": ["ips", "hosts", "targets"]
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
| 字段 | 说明 |
|
|
93
|
+
| --- | --- |
|
|
94
|
+
| key | DSH 线上工具名,必须精确匹配,不支持通配 |
|
|
95
|
+
| `kind` | `shell`、`mcp-shell`、`file-read`、`file-write`、`mcp` |
|
|
96
|
+
| `label` | 折叠行标题;`mcp__*` 自动加 `MCP · ` 前缀,省略时由工具名推导 |
|
|
97
|
+
| `commandKeys` | 依次尝试的参数名,取第一个非空值当命令 |
|
|
98
|
+
| `pathKeys` | 文件类工具的目标路径参数名,支持数组值(如 `files`) |
|
|
99
|
+
| `queryKeys` | 搜索或匹配条件的参数名 |
|
|
100
|
+
| `targetKeys` | 目标资产参数名(JumpServer 的 `ips`) |
|
|
101
|
+
|
|
102
|
+
改完跑 `npm run build`。DSH 只加载单文件 bundle,映射表会被内联进 `lib/client.js`,不能在运行时读 JSON。
|
|
103
|
+
|
|
104
|
+
## 开发
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npm run build # src/client-template.js + config/tools.json → lib/client.js
|
|
108
|
+
npm test # 构建 + 13 个用例
|
|
109
|
+
npm run verify # 检查本机 desktop profile 的依赖、bundle 和 junction
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`src/client-template.js` 是真正的源码,`lib/client.js` 是构建产物,不要手改。实现细节和调试方法见 [docs/development.md](docs/development.md),卡片字段与渲染逻辑见 [docs/cards.md](docs/cards.md)。
|
|
113
|
+
|
|
114
|
+
## 已知限制
|
|
115
|
+
|
|
116
|
+
- 只能按精确工具名注册。`tool.call.toolview` 是 keyed 座位,没有前缀或通配匹配,所谓“通用”靠映射表覆盖。
|
|
117
|
+
- 卡片只在浏览器侧生效,不改变工具的执行、权限或输出。宿主半边 `lib/index.js` 是空实现,只为让 bundle 能正常加载。
|
|
118
|
+
- 不接管 DSH 内置的 `bash` 和 `pwsh`。若另一个插件已占用同名 key,同时加载会冲突。
|
|
119
|
+
- Windows 下 `ops_edit_file` 可能保留目标文件原来的 `mtime`,内容变了时间没变,这是 dsh-ops 宿主侧行为。编辑后要靠 mtime 做增量扫描或判断 Git 状态时,先 `touch` 文件。
|
|
120
|
+
- DSH 升到高于 `0.2.3-alpha.3` 的契约版本时,先跑 `npm test` 再重装。
|
|
121
|
+
|
|
122
|
+
## 常见问题
|
|
123
|
+
|
|
124
|
+
**卡片还是 JSON。** 先确认 `dsh.profile.bundles` 里有 `dsh-toolview-kit`,再比对 `config/tools.json` 的 key 和线上工具名。已存在的会话保留原来的视图绑定,新会话里最先可见。
|
|
125
|
+
|
|
126
|
+
**只有部分工具变了。** 没列在映射表里的工具继续走默认渲染。加一行、构建、重开。
|
|
127
|
+
|
|
128
|
+
**卡片颜色不跟随皮肤。** 重开 DSH Desktop;仍不对就检查皮肤是否覆盖宿主 `--dsw-*` 令牌。
|
|
129
|
+
|
|
130
|
+
**和改过的 `app.asar` 冲突吗。** 不冲突。本仓库是可升级方案;直接改 `app.asar` 是另一条路,补丁让官方终端卡片接住 `ops_bash`,插件再补官方没有的文件工具和 MCP 命令。要回到纯净安装,从备份恢复 `app.asar` 即可,插件不受影响。
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
MIT
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"description": "Maps DSH wire tool names to card families. Add a tool here and rebuild.",
|
|
4
|
+
"tools": {
|
|
5
|
+
"ops_bash": {
|
|
6
|
+
"kind": "shell",
|
|
7
|
+
"label": "Bash",
|
|
8
|
+
"commandKeys": ["command", "cmd", "script", "shellCommand"],
|
|
9
|
+
"targetKeys": ["ips", "hosts", "targets"]
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
"ops_inspect_local_file": {
|
|
13
|
+
"kind": "file-read",
|
|
14
|
+
"label": "Inspect file",
|
|
15
|
+
"pathKeys": ["path", "filePath"]
|
|
16
|
+
},
|
|
17
|
+
"ops_grep": {
|
|
18
|
+
"kind": "file-read",
|
|
19
|
+
"label": "Search files",
|
|
20
|
+
"pathKeys": ["path"],
|
|
21
|
+
"queryKeys": ["pattern"]
|
|
22
|
+
},
|
|
23
|
+
"ops_glob": {
|
|
24
|
+
"kind": "file-read",
|
|
25
|
+
"label": "Find files",
|
|
26
|
+
"pathKeys": ["path"],
|
|
27
|
+
"queryKeys": ["pattern"]
|
|
28
|
+
},
|
|
29
|
+
"ops_stat": {
|
|
30
|
+
"kind": "file-read",
|
|
31
|
+
"label": "Inspect metadata",
|
|
32
|
+
"pathKeys": ["path"]
|
|
33
|
+
},
|
|
34
|
+
"ops_diff": {
|
|
35
|
+
"kind": "file-read",
|
|
36
|
+
"label": "Preview diff",
|
|
37
|
+
"pathKeys": ["path"]
|
|
38
|
+
},
|
|
39
|
+
"ops_read_files": {
|
|
40
|
+
"kind": "file-read",
|
|
41
|
+
"label": "Read files",
|
|
42
|
+
"pathKeys": ["path", "files"]
|
|
43
|
+
},
|
|
44
|
+
"ops_read_table": {
|
|
45
|
+
"kind": "file-read",
|
|
46
|
+
"label": "Read table",
|
|
47
|
+
"pathKeys": ["path", "filePath"]
|
|
48
|
+
},
|
|
49
|
+
"ops_read_docx": {
|
|
50
|
+
"kind": "file-read",
|
|
51
|
+
"label": "Read document",
|
|
52
|
+
"pathKeys": ["path", "filePath"]
|
|
53
|
+
},
|
|
54
|
+
"ops_read_pdf": {
|
|
55
|
+
"kind": "file-read",
|
|
56
|
+
"label": "Read PDF",
|
|
57
|
+
"pathKeys": ["path", "filePath"]
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
"ops_replace": {
|
|
61
|
+
"kind": "file-write",
|
|
62
|
+
"label": "Replace text",
|
|
63
|
+
"pathKeys": ["path", "filePath"]
|
|
64
|
+
},
|
|
65
|
+
"ops_write_file": {
|
|
66
|
+
"kind": "file-write",
|
|
67
|
+
"label": "Write file",
|
|
68
|
+
"pathKeys": ["path", "filePath"]
|
|
69
|
+
},
|
|
70
|
+
"ops_edit_file": {
|
|
71
|
+
"kind": "file-write",
|
|
72
|
+
"label": "Edit file",
|
|
73
|
+
"pathKeys": ["path", "filePath"]
|
|
74
|
+
},
|
|
75
|
+
"ops_copy": {
|
|
76
|
+
"kind": "file-write",
|
|
77
|
+
"label": "Copy file",
|
|
78
|
+
"pathKeys": ["source", "destination"]
|
|
79
|
+
},
|
|
80
|
+
"ops_move": {
|
|
81
|
+
"kind": "file-write",
|
|
82
|
+
"label": "Move file",
|
|
83
|
+
"pathKeys": ["source", "destination"]
|
|
84
|
+
},
|
|
85
|
+
"ops_remove": {
|
|
86
|
+
"kind": "file-write",
|
|
87
|
+
"label": "Remove file",
|
|
88
|
+
"pathKeys": ["path", "filePath"]
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
"mcp__jumpserver__execute_command": {
|
|
92
|
+
"kind": "mcp-shell",
|
|
93
|
+
"label": "JumpServer",
|
|
94
|
+
"commandKeys": ["command", "cmd", "script"],
|
|
95
|
+
"targetKeys": ["ips", "hosts", "targets"]
|
|
96
|
+
},
|
|
97
|
+
"mcp__jumpserver-prod__execute_command": {
|
|
98
|
+
"kind": "mcp-shell",
|
|
99
|
+
"label": "JumpServer Prod",
|
|
100
|
+
"commandKeys": ["command", "cmd", "script"],
|
|
101
|
+
"targetKeys": ["ips", "hosts", "targets"]
|
|
102
|
+
},
|
|
103
|
+
"mcp__jumpserver__submit_command": {
|
|
104
|
+
"kind": "mcp-shell",
|
|
105
|
+
"label": "JumpServer (async)",
|
|
106
|
+
"commandKeys": ["command", "cmd", "script"],
|
|
107
|
+
"targetKeys": ["ips", "hosts", "targets"]
|
|
108
|
+
},
|
|
109
|
+
"mcp__jumpserver-prod__submit_command": {
|
|
110
|
+
"kind": "mcp-shell",
|
|
111
|
+
"label": "JumpServer Prod (async)",
|
|
112
|
+
"commandKeys": ["command", "cmd", "script"],
|
|
113
|
+
"targetKeys": ["ips", "hosts", "targets"]
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
package/cordis.patch.yml
ADDED
package/docs/cards.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# 卡片与数据来源
|
|
2
|
+
|
|
3
|
+
## 卡片族
|
|
4
|
+
|
|
5
|
+
| kind | 折叠行主信息 | 展开区 |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| `shell` | `$ command` 首行 | 命令块、输出块、CWD、退出码 |
|
|
8
|
+
| `mcp-shell` | 命令首行 + 目标资产 | 同上,另加 `MCP · <label>` 标题 |
|
|
9
|
+
| `file-read` | 目标路径或查询条件 | 路径、查询条件、输出 |
|
|
10
|
+
| `file-write` | 目标路径 | 路径、写入内容、输出 |
|
|
11
|
+
| `mcp` | 工具名 | 参数 JSON 与输出 |
|
|
12
|
+
|
|
13
|
+
## 数据从哪来
|
|
14
|
+
|
|
15
|
+
DSH 把一次工具调用分成三个阶段交给视图组件:`preparing` → `start` → `result`。
|
|
16
|
+
|
|
17
|
+
| 阶段 | 可取字段 | 本插件的用法 |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| `preparing` | 无参数 | 显示 `Queued` 与工具名 |
|
|
20
|
+
| `start` | `block.argsRaw` | 解析出命令 / 路径 / 目标 |
|
|
21
|
+
| `result` | `block.call.argsRaw`、`block.content`、`block.error`、`block.isError` | 解析参数与输出,判定成功 / 失败 / 取消 |
|
|
22
|
+
|
|
23
|
+
要点:
|
|
24
|
+
|
|
25
|
+
- `block.args` 是惰性对象,不能直接 `JSON.parse`;一律读 `argsRaw`。
|
|
26
|
+
- `result` 阶段的 `block.call` 可能为 `null`,此时只显示输出。
|
|
27
|
+
- 输出既可能是 `{ type: 'text', text }` 数组,也可能是纯字符串或对象;解析器逐层取 `text` / `output` / `content` / `result` / `json`。
|
|
28
|
+
- JumpServer MCP 的对象回执会识别 `ok`、`state`、`job_id`、`out` 和 `results[]`:输出只展示每个资产的 `out`,保留资产 IP、作业号和状态;`host | CHANGED | rc=N >>` / `host | FAILED | rc=N >>` 包头会被移除,`rc` 转成退出码。
|
|
29
|
+
- 退出码优先取结构化字段 `exitCode`,其次取 JumpServer 每个结果的 `rc`,最后从正文尾部的 `[exit code: N]` 提取,并在展示前剥离该标记。
|
|
30
|
+
|
|
31
|
+
## 文件写入 Diff
|
|
32
|
+
|
|
33
|
+
对 `ops_edit_file`、`ops_replace`、`ops_write_file` 等 `file-write` 工具,卡片会优先展示自绘 Diff:删除行用危险色、增加行用成功色、`@@ edit N @@` 用次要文字色,并展示 `expectedRevision` 供 CAS 排障。它不替代执行器的原子校验,也不修改请求参数。
|
|
34
|
+
|
|
35
|
+
Windows 下 `ops_edit_file` 由 dsh-ops 宿主执行时可能保留目标文件原 `mtime`。这属于执行层行为,toolview 无法修复;编辑后若依赖时间戳或 Git stat,需显式 `touch` 目标文件。
|
|
36
|
+
|
|
37
|
+
## 主题令牌
|
|
38
|
+
|
|
39
|
+
卡片使用宿主 `dsh-client-ui-theme` 的 `--dsw-alias-*` 令牌,而不是插件自造的 `--dsh-*` 变量:
|
|
40
|
+
|
|
41
|
+
- 文本:`--dsw-alias-label-primary/secondary/tertiary/caption`
|
|
42
|
+
- 面与边框:`--dsw-alias-bg-layer-2`(卡片面)、`--dsw-alias-markdown-code-block(-banner)`、`--dsw-alias-border-l1/l2/l4`
|
|
43
|
+
- 状态:`--dsw-alias-state-success-primary`、`--dsw-alias-state-error-primary`、`--dsw-alias-state-warn-label`、`--dsw-alias-state-business-primary`
|
|
44
|
+
|
|
45
|
+
这些值由宿主按浅色 / 深色写到 `body`,皮肤插件也覆盖同一层令牌,因此卡片会随皮肤变化。旧宿主没有令牌时只继承周围颜色,不使用固定白色背景。
|
|
46
|
+
|
|
47
|
+
## 状态判定
|
|
48
|
+
|
|
49
|
+
| 条件 | 展示 |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| `preparing` | Queued(黄) |
|
|
52
|
+
| `start` 且无结果 | Running(蓝) |
|
|
53
|
+
| `error.code === 'interrupted'` | Cancelled(黄) |
|
|
54
|
+
| `isError`、`error` 存在,或退出码非 0 | Failed(红) |
|
|
55
|
+
| 其余 `result` | Done(绿) |
|
|
56
|
+
|
|
57
|
+
## 扩展一个新工具
|
|
58
|
+
|
|
59
|
+
1. 在 `config/tools.json` 的 `tools` 里加一项,key 必须是线上工具名。
|
|
60
|
+
2. 选 `kind`,补 `commandKeys` / `pathKeys` / `queryKeys` / `targetKeys`。
|
|
61
|
+
3. `npm run build && npm test`。
|
|
62
|
+
4. 重开 DSH Desktop;主题令牌在宿主启动时注入,旧会话不会热替换客户端 bundle。
|
|
63
|
+
|
|
64
|
+
若新工具的参数结构特殊(例如一次操作多个目标),优先通过 `pathKeys` 的数组值或 `targetKeys` 复用现有渲染,不必新增组件。
|
|
65
|
+
|
|
66
|
+
## 刻意不做的事
|
|
67
|
+
|
|
68
|
+
- 不接管 DSH 内置的 `bash`、`pwsh`、`read`、`write` 等名字,避免与官方卡片或其它插件抢同一个 key。
|
|
69
|
+
- 不在运行时探测工具名单:DSH 只加载单文件 bundle,运行时读 `node_modules` 里的 JSON 不可靠,映射表在构建期内联。
|
|
70
|
+
- 不改变执行语义:卡片只做展示,不重试、不改参、不代理权限。
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# 开发说明
|
|
2
|
+
|
|
3
|
+
## 结构
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
dsh-toolview-kit/
|
|
7
|
+
├── config/tools.json # 唯一数据源:工具名 → 卡片族
|
|
8
|
+
├── src/client-template.js # 手写模板,含 __TOOL_MAP_JSON__ 占位符
|
|
9
|
+
├── scripts/build.mjs # 校验映射 + 内联 + 产出 lib/client.js + 语法检查
|
|
10
|
+
├── lib/index.js # 宿主半:空实现
|
|
11
|
+
├── lib/client.js # 构建产物(勿手改)
|
|
12
|
+
├── test/plugin.test.mjs # 13 个用例
|
|
13
|
+
└── docs/ # 安装、卡片说明
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## 为什么是手写模板
|
|
17
|
+
|
|
18
|
+
DSH 的浏览器插件必须是**单文件 CJS handoff**:包入口调用 `window.__ModuleLoader__.load({ id, factory })`,`id` 必须等于包名,`factory(require)` 返回插件对象。仓库里没有 `esbuild`/`typescript` 依赖,也不引入打包器:模板本身就是合法 JS,构建只做一次字符串替换 + `node --check`。
|
|
19
|
+
|
|
20
|
+
`require` 只允许解析 DSH 内部包(`react`、`react/jsx-runtime`、`@deepseek-ai/dsh-client-ui-primitives`)。本插件只用 `react`,因此构建产物在宿主版本间最稳。
|
|
21
|
+
|
|
22
|
+
## 注册方式
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
function register(ctx, key) {
|
|
26
|
+
ctx.slots.inject('tool.call.toolview', () => ctx.slots.register({ name: 'tool.call.toolview', key }, ToolCard));
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
- 座位是 `kind: 'keyed', scope: 'session'`,`key` 必须等于线上工具名,没有通配。
|
|
31
|
+
- `inject` 的回调在座位声明后执行,返回值是注销函数;每个 key 单独注册一次。
|
|
32
|
+
- 同一 key 同优先级重复注册会抛错,所以本插件不碰官方已占用的名字。
|
|
33
|
+
|
|
34
|
+
## 测试策略
|
|
35
|
+
|
|
36
|
+
`test/plugin.test.mjs` 不依赖 DSH:
|
|
37
|
+
|
|
38
|
+
1. **映射覆盖**:断言 15 个 `ops_*` 文件工具、`ops_bash`、4 个 JumpServer 命令都在表里,且写操作归到 `file-write`。
|
|
39
|
+
2. **loader 形状**:`vm` 里跑 `lib/client.js`,断言调用 `load`、`id` 等于包名、`require('react')` 可解析。
|
|
40
|
+
3. **注册**:用假 `ctx.slots` 收集注册,断言 20 个 key 与映射表一一对应。
|
|
41
|
+
4. **渲染**:极小 React stub(`createElement` + `useState`)直接调用视图,把元素树拍平成文本,断言命令、输出、退出码、路径、目标资产、取消态与 file-write Diff。
|
|
42
|
+
|
|
43
|
+
新增交互(例如折叠记忆)时,优先给 stub 加能力,而不是把组件改成不可测的副作用代码。
|
|
44
|
+
|
|
45
|
+
## 发布清单
|
|
46
|
+
|
|
47
|
+
- [ ] `npm test` 全绿
|
|
48
|
+
- [ ] `CHANGELOG.md` 写清变更
|
|
49
|
+
- [ ] `version` 与 `package.json` 的 `dsh.version` 同步
|
|
50
|
+
- [ ] `repository` 指向真实仓库
|
|
51
|
+
- [ ] `git tag vX.Y.Z` 并推送
|
|
52
|
+
- [ ] npm 公开发布前确认包名可用(`npm view dsh-toolview-kit`)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# 安装与回滚
|
|
2
|
+
|
|
3
|
+
## 前置条件
|
|
4
|
+
|
|
5
|
+
| 项 | 要求 |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| DSH | `0.1.0-rc.5` 或更高(`tool.call.toolview` keyed 座位) |
|
|
8
|
+
| Node | `>=22.19.0`(构建与测试用) |
|
|
9
|
+
| OS | 任意;Windows 只是本插件的重点使用场景 |
|
|
10
|
+
|
|
11
|
+
## 安装方式
|
|
12
|
+
|
|
13
|
+
### 1. 插件命令(推荐)
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
dsh plugin --profile desktop add file:///path/to/dsh-toolview-kit
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
DSH 会同时写入 `dependencies` 与 `dsh.profile.bundles`,并执行一次安装。完成后重开 DSH Desktop。
|
|
20
|
+
|
|
21
|
+
在源码 checkout 中可用以下命令验证当前 `desktop` profile 的接入状态:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm run verify
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
它会检查 profile 登记、`node_modules` junction 的真实目标、客户端 bundle、patch 文件和工具映射;不会删除或修改 profile。
|
|
28
|
+
|
|
29
|
+
### 2. 手工登记
|
|
30
|
+
|
|
31
|
+
编辑 `~/.dsh/profiles/<profile>/package.json`:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"dsh-toolview-kit": "file:../../plugins/dsh-toolview-kit"
|
|
37
|
+
},
|
|
38
|
+
"dsh": {
|
|
39
|
+
"profile": {
|
|
40
|
+
"bundles": ["dsh-toolview-kit"]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
两处都写才会生效:`dependencies` 让 Node 能解析包,`dsh.profile.bundles` 决定是否加载它的 `cordis.patch.yml`。
|
|
47
|
+
|
|
48
|
+
### 3. 源码目录 + junction(不跑包管理器时)
|
|
49
|
+
|
|
50
|
+
```cmd
|
|
51
|
+
mklink /J "%USERPROFILE%\.dsh\profiles\desktop\node_modules\dsh-toolview-kit" "C:\path\to\dsh-toolview-kit"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
junction 不需要管理员权限,也不会改动 lockfile。
|
|
55
|
+
|
|
56
|
+
## 生效条件
|
|
57
|
+
|
|
58
|
+
- 客户端 bundle 在 DSH 启动时加载;安装或更新后必须**重开 DSH Desktop**。
|
|
59
|
+
- 已存在的会话保留原有工具视图绑定;卡片在新会话中最先可见,必要时右键 Agent 刷新。
|
|
60
|
+
- 插件只为映射表里的名字注册 key;未列出的工具继续走 DSH 默认渲染,不会报错。
|
|
61
|
+
|
|
62
|
+
## 回滚
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# 1. 从 bundles 与 dependencies 中删掉 dsh-toolview-kit
|
|
66
|
+
# 2. 删除 node_modules 里的入口
|
|
67
|
+
rm "%USERPROFILE%\.dsh\profiles\desktop\node_modules\dsh-toolview-kit"
|
|
68
|
+
# 3. 重开 DSH Desktop
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
若是 junction,用 `rmdir`(不要用 `rmdir /s`,避免删到源码目录):
|
|
72
|
+
|
|
73
|
+
```cmd
|
|
74
|
+
rmdir "%USERPROFILE%\.dsh\profiles\desktop\node_modules\dsh-toolview-kit"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 故障排查
|
|
78
|
+
|
|
79
|
+
| 现象 | 原因 | 处理 |
|
|
80
|
+
| --- | --- | --- |
|
|
81
|
+
| 卡片仍是 JSON | 包没被加载,或 key 与工具名不一致 | 确认 `dsh.profile.bundles` 有条目;比对 `config/tools.json` 的 key 与线上工具名 |
|
|
82
|
+
| 控制台出现 `failed to register` | 客户端 bundle 抛错 | 跑 `npm test`,再 `node --check lib/client.js` |
|
|
83
|
+
| 只有部分工具变卡片 | 该工具名不在映射表 | 在 `config/tools.json` 加一行,`npm run build`,重开 DSH |
|
|
84
|
+
| 卡片样式发灰 / 对比度低 | 宿主未提供对应 `--dsw-*` 主题令牌,或旧会话没有重新加载 bundle | 重开 DSH Desktop;检查主题插件是否覆盖宿主 `--dsw-*` 令牌 |
|
|
85
|
+
|
|
86
|
+
## 升级
|
|
87
|
+
|
|
88
|
+
1. `git pull`(或安装新版本)。
|
|
89
|
+
2. `npm ci --omit=dev || true`(本包无运行时依赖,可跳过)。
|
|
90
|
+
3. `npm run build && npm test`。
|
|
91
|
+
4. 重开 DSH Desktop。
|
|
92
|
+
|
|
93
|
+
DSH 大版本升级后,若 `tool.call.toolview` 的 props 契约变化,测试会首先失败——优先看 `test/plugin.test.mjs` 里的 loader 与渲染用例。
|