@hua-ri/dsh-ops 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +60 -2
- package/client.js +183 -0
- package/cordis.patch.yml +3 -0
- package/index.js +1079 -0
- package/lib/argocd/instances.mjs +50 -0
- package/lib/argocd/mod.mjs +221 -0
- package/lib/argowf/instances.mjs +52 -0
- package/lib/argowf/mod.mjs +219 -0
- package/lib/cli.mjs +95 -0
- package/lib/client.js +56 -0
- package/lib/helm/mod.mjs +281 -0
- package/lib/k8s/context.mjs +179 -0
- package/lib/k8s/mod.mjs +347 -0
- package/lib/ssh/config.mjs +53 -0
- package/lib/ssh/hosts.mjs +94 -0
- package/lib/ssh/keys.mjs +76 -0
- package/lib/ssh/mod.mjs +476 -0
- package/lib/ssh/snippet-vars.mjs +22 -0
- package/lib/ssh/tunnels.mjs +97 -0
- package/package.json +60 -4
- package/scripts/doctor.mjs +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 hua-ri
|
|
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,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @hua-ri/dsh-ops
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
DSH 一体化运维插件 — 在 DeepSeek Harness 中管理 SSH 主机、Kubernetes 集群、Helm Chart、ArgoCD 和 Argo Workflows。
|
|
4
|
+
|
|
5
|
+
## 功能
|
|
6
|
+
|
|
7
|
+
- **SSH 远程运维** — 主机管理、命令执行、文件浏览、隧道、密钥管理、命令片段、批量操作
|
|
8
|
+
- **Kubernetes 集群管理** — 多集群上下文、资源浏览(get/describe/logs/exec)、apply/delete/scale/rollout
|
|
9
|
+
- **Helm Chart 管理** — Release 管理、仓库 CRUD、Chart 搜索与详情、安装/升级/卸载
|
|
10
|
+
- **ArgoCD 部署管理** — 应用列表与状态、同步、回滚、日志
|
|
11
|
+
- **Argo Workflows** — 工作流列表、提交、重试、日志
|
|
12
|
+
|
|
13
|
+
共 49 个 DSH Tools,AI agent 可直接调用所有运维能力。
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @hua-ri/dsh-ops
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
在 DSH profile 的 `package.json` 中添加依赖,并在 bundles 中启用:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@hua-ri/dsh-ops": "^0.2.0"
|
|
27
|
+
},
|
|
28
|
+
"dsh": {
|
|
29
|
+
"bundles": ["@hua-ri/dsh-ops"]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 系统依赖
|
|
35
|
+
|
|
36
|
+
| CLI 工具 | 模块 | 安装方式 |
|
|
37
|
+
|----------|------|----------|
|
|
38
|
+
| ssh | SSH(必需) | macOS 自带 |
|
|
39
|
+
| kubectl | K8s(必需) | `brew install kubectl` |
|
|
40
|
+
| helm | Helm | `brew install helm` |
|
|
41
|
+
| argocd | ArgoCD | `brew install argocd` |
|
|
42
|
+
| argo | Argo Workflows | `brew install argo` |
|
|
43
|
+
|
|
44
|
+
运行 `node scripts/doctor.mjs` 检查依赖状态。
|
|
45
|
+
|
|
46
|
+
## 配置
|
|
47
|
+
|
|
48
|
+
插件安装后各模块可独立启停(SSH 和 K8s 默认启用):
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"ssh": { "enabled": true },
|
|
53
|
+
"k8s": { "enabled": true },
|
|
54
|
+
"argocd": { "enabled": false },
|
|
55
|
+
"argowf": { "enabled": false }
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
MIT
|
package/client.js
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-ops —— 浏览器端:设置页面板
|
|
3
|
+
*
|
|
4
|
+
* 挂载点:settings.section(左侧导航出现「运维工具」)
|
|
5
|
+
* 读后端 /api/dsh-ops/status 获取模块状态和依赖检查结果。
|
|
6
|
+
*/
|
|
7
|
+
;(function() {
|
|
8
|
+
|
|
9
|
+
window.__ModuleLoader__.load({
|
|
10
|
+
id: 'dsh-ops',
|
|
11
|
+
factory: (require) => {
|
|
12
|
+
const React = require('react')
|
|
13
|
+
const h = React.createElement
|
|
14
|
+
|
|
15
|
+
const API = '/api/dsh-ops'
|
|
16
|
+
|
|
17
|
+
const asJson = async (res) => {
|
|
18
|
+
if (res.ok) return res.json()
|
|
19
|
+
throw new Error('HTTP ' + res.status)
|
|
20
|
+
}
|
|
21
|
+
const jget = async (p) => asJson(await fetch(API + p, { credentials: 'same-origin' }))
|
|
22
|
+
const jpost = async (p, body) => asJson(await fetch(API + p, {
|
|
23
|
+
method: 'POST', credentials: 'same-origin',
|
|
24
|
+
headers: { 'content-type': 'application/json' },
|
|
25
|
+
body: JSON.stringify(body || {}),
|
|
26
|
+
}))
|
|
27
|
+
|
|
28
|
+
const CSS = `
|
|
29
|
+
[data-ops-page]{font-size:14px;padding:0 4px;}
|
|
30
|
+
[data-ops-title]{font-size:18px;font-weight:600;margin-bottom:16px;}
|
|
31
|
+
[data-ops-section]{margin-bottom:20px;}
|
|
32
|
+
[data-ops-section-title]{font-size:15px;font-weight:600;margin-bottom:8px;display:flex;align-items:center;gap:8px;}
|
|
33
|
+
[data-ops-card]{display:flex;align-items:center;justify-content:space-between;padding:12px 16px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.18));border-radius:8px;margin-bottom:8px;background:var(--dsw-alias-bg2,rgba(255,255,255,.04));}
|
|
34
|
+
[data-ops-card-info]{flex:1;}
|
|
35
|
+
[data-ops-card-name]{font-weight:600;font-size:14px;}
|
|
36
|
+
[data-ops-card-desc]{font-size:12px;color:var(--dsw-alias-fg3,#999);margin-top:2px;}
|
|
37
|
+
[data-ops-card-dep]{font-size:11px;margin-top:4px;display:flex;align-items:center;gap:6px;}
|
|
38
|
+
[data-ops-badge]{display:inline-block;padding:1px 6px;border-radius:4px;font-size:11px;font-weight:500;}
|
|
39
|
+
[data-ops-badge-ok]{background:#dcfce7;color:#166534;}
|
|
40
|
+
[data-ops-badge-miss]{background:#fee2e2;color:#991b1b;}
|
|
41
|
+
[data-ops-badge-off]{background:#f3f4f6;color:#6b7280;}
|
|
42
|
+
[data-ops-toggle]{position:relative;display:inline-flex;align-items:center;width:40px;height:22px;border-radius:11px;cursor:pointer;transition:background .2s;border:none;padding:0;}
|
|
43
|
+
[data-ops-toggle][data-on="true"]{background:#3b82f6;}
|
|
44
|
+
[data-ops-toggle][data-on="false"]{background:#d1d5db;}
|
|
45
|
+
[data-ops-toggle-dot]{position:absolute;width:18px;height:18px;border-radius:50%;background:#fff;transition:left .2s;top:2px;}
|
|
46
|
+
[data-ops-toggle][data-on="true"] [data-ops-toggle-dot]{left:20px;}
|
|
47
|
+
[data-ops-toggle][data-on="false"] [data-ops-toggle-dot]{left:2px;}
|
|
48
|
+
[data-ops-hint]{font-size:12px;color:var(--dsw-alias-fg3,#999);margin-top:12px;padding:8px 12px;background:var(--dsw-alias-bg2,rgba(255,255,255,.04));border-radius:6px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.12));}
|
|
49
|
+
[data-ops-stats]{display:flex;gap:16px;margin-bottom:16px;flex-wrap:wrap;}
|
|
50
|
+
[data-ops-stat]{padding:8px 16px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.18));background:var(--dsw-alias-bg2,rgba(255,255,255,.04));text-align:center;min-width:80px;}
|
|
51
|
+
[data-ops-stat-num]{font-size:20px;font-weight:700;color:var(--dsw-alias-fg1,#111);}
|
|
52
|
+
[data-ops-stat-label]{font-size:11px;color:var(--dsw-alias-fg3,#999);margin-top:2px;}
|
|
53
|
+
`
|
|
54
|
+
|
|
55
|
+
const MODULES = [
|
|
56
|
+
{ key: 'ssh', label: 'SSH', desc: '远程主机管理与命令执行', bin: 'ssh', defaultOn: true },
|
|
57
|
+
{ key: 'k8s', label: 'Kubernetes', desc: 'kubectl 集群管理', bin: 'kubectl', defaultOn: true },
|
|
58
|
+
{ key: 'argocd', label: 'Argo CD', desc: 'GitOps 持续部署', bin: 'argocd', defaultOn: false },
|
|
59
|
+
{ key: 'argowf', label: 'Argo Workflows', desc: '工作流引擎管理', bin: 'argo', defaultOn: false },
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
function Icon({ size = 16 }) {
|
|
63
|
+
return h('svg', {
|
|
64
|
+
width: size, height: size, viewBox: '0 0 24 24', fill: 'none',
|
|
65
|
+
stroke: 'currentColor', strokeWidth: 1.5, 'aria-hidden': true,
|
|
66
|
+
},
|
|
67
|
+
h('rect', { x: 3, y: 3, width: 18, height: 18, rx: 2 }),
|
|
68
|
+
h('path', { d: 'M7 8h4M7 12h6M7 16h3' }),
|
|
69
|
+
h('circle', { cx: 17, cy: 12, r: 2 }),
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function Toggle({ on, onChange }) {
|
|
74
|
+
return h('button', {
|
|
75
|
+
'data-ops-toggle': true, 'data-on': String(!!on),
|
|
76
|
+
onClick: () => onChange(!on),
|
|
77
|
+
}, h('span', { 'data-ops-toggle-dot': true }))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function ModuleCard({ mod, status, onToggle }) {
|
|
81
|
+
const dep = status?.deps?.[mod.bin]
|
|
82
|
+
const enabled = status?.config?.[mod.key]?.enabled ?? mod.defaultOn
|
|
83
|
+
return h('div', { 'data-ops-card': true }, [
|
|
84
|
+
h('div', { 'data-ops-card-info': true }, [
|
|
85
|
+
h('div', { 'data-ops-card-name': true }, mod.label),
|
|
86
|
+
h('div', { 'data-ops-card-desc': true }, mod.desc),
|
|
87
|
+
h('div', { 'data-ops-card-dep': true }, [
|
|
88
|
+
h('code', { style: { fontSize: '11px' } }, mod.bin),
|
|
89
|
+
dep?.ok
|
|
90
|
+
? h('span', { 'data-ops-badge': true, 'data-ops-badge-ok': true }, dep.path || 'OK')
|
|
91
|
+
: !enabled
|
|
92
|
+
? h('span', { 'data-ops-badge': true, 'data-ops-badge-off': true }, '未启用')
|
|
93
|
+
: h('span', { 'data-ops-badge': true, 'data-ops-badge-miss': true }, '未安装'),
|
|
94
|
+
]),
|
|
95
|
+
]),
|
|
96
|
+
h(Toggle, { on: enabled, onChange: (v) => onToggle(mod.key, v) }),
|
|
97
|
+
])
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function Panel() {
|
|
101
|
+
const [status, setStatus] = React.useState(null)
|
|
102
|
+
const [saving, setSaving] = React.useState(false)
|
|
103
|
+
|
|
104
|
+
const refresh = React.useCallback(() => {
|
|
105
|
+
jget('/status').then(setStatus).catch(() => setStatus({ error: true }))
|
|
106
|
+
}, [])
|
|
107
|
+
|
|
108
|
+
React.useEffect(() => { refresh() }, [refresh])
|
|
109
|
+
|
|
110
|
+
const toggleModule = React.useCallback(async (key, on) => {
|
|
111
|
+
setSaving(true)
|
|
112
|
+
try {
|
|
113
|
+
await jpost('/config', { module: key, enabled: on })
|
|
114
|
+
refresh()
|
|
115
|
+
} catch {}
|
|
116
|
+
setSaving(false)
|
|
117
|
+
}, [refresh])
|
|
118
|
+
|
|
119
|
+
if (!status) return h('div', { 'data-ops-page': true }, '加载中…')
|
|
120
|
+
if (status.error) return h('div', { 'data-ops-page': true }, '无法连接后端。请确认 dsh-ops 插件已启用。')
|
|
121
|
+
|
|
122
|
+
const enabledCount = MODULES.filter((m) => status.config?.[m.key]?.enabled ?? m.defaultOn).length
|
|
123
|
+
const depOkCount = Object.values(status.deps || {}).filter((d) => d.ok).length
|
|
124
|
+
|
|
125
|
+
return h('div', { 'data-ops-page': true }, [
|
|
126
|
+
h('div', { 'data-ops-title': true }, '运维工具'),
|
|
127
|
+
|
|
128
|
+
h('div', { 'data-ops-stats': true }, [
|
|
129
|
+
h('div', { 'data-ops-stat': true }, [
|
|
130
|
+
h('div', { 'data-ops-stat-num': true }, String(enabledCount)),
|
|
131
|
+
h('div', { 'data-ops-stat-label': true }, '已启用模块'),
|
|
132
|
+
]),
|
|
133
|
+
h('div', { 'data-ops-stat': true }, [
|
|
134
|
+
h('div', { 'data-ops-stat-num': true }, String(depOkCount) + '/' + String(MODULES.length)),
|
|
135
|
+
h('div', { 'data-ops-stat-label': true }, 'CLI 就绪'),
|
|
136
|
+
]),
|
|
137
|
+
h('div', { 'data-ops-stat': true }, [
|
|
138
|
+
h('div', { 'data-ops-stat-num': true }, String(status.toolCount || 0)),
|
|
139
|
+
h('div', { 'data-ops-stat-label': true }, '已注册工具'),
|
|
140
|
+
]),
|
|
141
|
+
]),
|
|
142
|
+
|
|
143
|
+
h('div', { 'data-ops-section': true }, [
|
|
144
|
+
h('div', { 'data-ops-section-title': true }, '模块管理'),
|
|
145
|
+
...MODULES.map((m) => h(ModuleCard, {
|
|
146
|
+
key: m.key, mod: m, status, onToggle: toggleModule,
|
|
147
|
+
})),
|
|
148
|
+
]),
|
|
149
|
+
|
|
150
|
+
h('div', { 'data-ops-hint': true }, [
|
|
151
|
+
'开关切换后需要重启 DSH 才生效。数据目录:~/.dsh/dsh-ops/',
|
|
152
|
+
]),
|
|
153
|
+
])
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
inject: ['slots'],
|
|
158
|
+
apply(ctx) {
|
|
159
|
+
const style = document.createElement('style')
|
|
160
|
+
style.setAttribute('data-plugin-css', 'dsh-ops')
|
|
161
|
+
style.textContent = CSS
|
|
162
|
+
document.head.appendChild(style)
|
|
163
|
+
if (typeof ctx.effect === 'function') ctx.effect(() => () => style.remove(), 'dsh-ops: 面板样式')
|
|
164
|
+
|
|
165
|
+
const slots = (typeof ctx.get === 'function' ? ctx.get('slots') : undefined) || ctx.slots
|
|
166
|
+
if (!slots) return
|
|
167
|
+
|
|
168
|
+
slots.inject('sidebar.panellist', () => {
|
|
169
|
+
slots.register(
|
|
170
|
+
{ name: 'sidebar.panellist', id: 'dsh-ops', order: 25, label: '运维工具' },
|
|
171
|
+
Icon,
|
|
172
|
+
)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
slots.inject('main', () => {
|
|
176
|
+
slots.register({ name: 'main', key: 'dsh-ops' }, Panel)
|
|
177
|
+
})
|
|
178
|
+
},
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
})();
|
package/cordis.patch.yml
ADDED