dsh-ops-kit 0.3.6 → 0.3.8

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 CHANGED
@@ -1,10 +1,32 @@
1
1
  # dsh-ops-kit
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/dsh-ops-kit)](https://www.npmjs.com/package/dsh-ops-kit)
4
+ [![npm downloads](https://img.shields.io/npm/dm/dsh-ops-kit)](https://www.npmjs.com/package/dsh-ops-kit)
5
+ [![DSH plugin market](https://img.shields.io/badge/market-awesome--dsh--plugin-4c8dff)](https://awesome-dsh-plugin.com/p/shenlongze/dsh-ops-kit/)
6
+ [![license](https://img.shields.io/npm/l/dsh-ops-kit)](LICENSE)
7
+
3
8
  **English** | [简体中文](README.zh-CN.md)
4
9
 
5
10
  Server operations from a DeepSeek Harness chat: **34 tools plus a sidebar panel**,
6
11
  no SDK, and no credentials stored by the plugin.
7
12
 
13
+ ## Install
14
+
15
+ ```bash
16
+ dsh plugin --profile <profile> add dsh-ops-kit
17
+ ```
18
+
19
+ `<profile>` is the profile you run (`desktop`, `web`, `tui`, …). The panel appears
20
+ as **运维** in the sidebar; the tools are available to every agent in that profile.
21
+
22
+ Requirements: DSH `>=0.2.1-rc.4`, Node `^22.19.0 || >=24.0.0`. Nothing is installed
23
+ on the servers you manage — the plugin works over SSH.
24
+
25
+ Upgrading: `dsh plugin --profile <profile> add dsh-ops-kit@latest`, or use the
26
+ plugin market's update button.
27
+
28
+ no SDK, and no credentials stored by the plugin.
29
+
8
30
  🔒 marks an action that needs `confirm: true` — the tool fails closed instead of
9
31
  asking in a second turn.
10
32
 
package/README.zh-CN.md CHANGED
@@ -1,10 +1,28 @@
1
1
  # dsh-ops-kit
2
2
 
3
+ [![npm 版本](https://img.shields.io/npm/v/dsh-ops-kit)](https://www.npmjs.com/package/dsh-ops-kit)
4
+ [![npm 下载量](https://img.shields.io/npm/dm/dsh-ops-kit)](https://www.npmjs.com/package/dsh-ops-kit)
5
+ [![插件市场](https://img.shields.io/badge/市场-awesome--dsh--plugin-4c8dff)](https://awesome-dsh-plugin.com/p/shenlongze/dsh-ops-kit/)
6
+ [![许可证](https://img.shields.io/npm/l/dsh-ops-kit)](LICENSE)
7
+
3
8
  [English](README.md) | **简体中文**
4
9
 
5
10
  在 DeepSeek Harness 的对话里做服务器运维:**34 个工具 + 一个侧栏面板**,无需安装 SDK,
6
11
  插件默认不保存任何凭据。
7
12
 
13
+ ## 安装
14
+
15
+ ```bash
16
+ dsh plugin --profile <你的 profile> add dsh-ops-kit
17
+ ```
18
+
19
+ `<profile>` 填你正在跑的 profile(`desktop`、`web`、`tui` 等)。装好后侧栏出现
20
+ **运维** 面板,同时该 profile 里的所有 agent 都能调用这些工具。
21
+
22
+ 要求:DSH `>=0.2.1-rc.4`、Node `^22.19.0 || >=24.0.0`。**被管理的服务器上不用装任何东西**——插件走 SSH。
23
+
24
+ 升级:`dsh plugin --profile <你的 profile> add dsh-ops-kit@latest`,或在插件市场里点更新。
25
+
8
26
  > **完整使用说明见 [docs/USAGE.zh-CN.md](docs/USAGE.zh-CN.md)** —— 前置条件怎么验、面板十个子页各干什么、
9
27
  > 设置项默认值、数据放在哪有多敏感、以及连不上时怎么排障。(英文版:[docs/USAGE.md](docs/USAGE.md))
10
28
 
package/client.js CHANGED
@@ -81,6 +81,8 @@ window.__ModuleLoader__.load({
81
81
  monInterval: '间隔(分钟)', monAdd: '添加并检查', monCheck: '检查', monRemove: '删除', monEmpty: '还没有监控项,可以加一个心跳检查',
82
82
  monHttpHint: 'http:填 URL,如 https://example.com;port:填 host:port;process:填进程关键字;service:填 systemd 单元名',
83
83
  monLast: '最近', monNever: '未检查', monEdit: '编辑', monSave: '保存修改', monCancel: '取消',
84
+ monOk: '服务正常', monBad: '检查失败', monHint: '排查方向', monDiag: '一键排查', monDiaging: '排查中…',
85
+ monResult: '这次检查结果', monClose: '关闭', monDiagTitle: '排查结果', monChecked: '检查于',
84
86
  monPreset: '一键模板', monScript: '脚本(退出码 0 = 正常)', monLanguage: '语言',
85
87
  monScriptHint: '脚本在服务器上用对应解释器执行,退出码 0 视为正常;python 需要 python3,js 需要 node。',
86
88
  monTypes: [['http', '网站能不能打开'], ['port', '端口通不通'], ['process', '程序还在不在'], ['service', '系统服务在不在'], ['script', '自己写检查脚本']],
@@ -164,6 +166,8 @@ window.__ModuleLoader__.load({
164
166
  monInterval: 'Interval (min)', monAdd: 'Add and check', monCheck: 'Check', monRemove: 'Remove', monEmpty: 'No monitors yet — add a heartbeat check',
165
167
  monHttpHint: 'http: URL like https://example.com; port: host:port; process: pattern; service: systemd unit',
166
168
  monLast: 'last', monNever: 'never', monEdit: 'Edit', monSave: 'Save', monCancel: 'Cancel',
169
+ monOk: 'Healthy', monBad: 'Check failed', monHint: 'Where to look', monDiag: 'Diagnose', monDiaging: 'Diagnosing…',
170
+ monResult: 'Result', monClose: 'Close', monDiagTitle: 'Diagnosis', monChecked: 'checked at',
167
171
  monPreset: 'Presets', monScript: 'Script (exit 0 = healthy)', monLanguage: 'Language',
168
172
  monScriptHint: 'Runs on the host with the chosen interpreter; exit code 0 means healthy. python needs python3, js needs node.',
169
173
  monTypes: [['http', 'Website reachable'], ['port', 'Port open'], ['process', 'Process alive'], ['service', 'System service active'], ['script', 'Custom script']],
@@ -250,6 +254,15 @@ window.__ModuleLoader__.load({
250
254
  .ops-meta{display:flex;gap:8px;align-items:center;font-size:11px;color:var(--dsw-alias-text-secondary,#9aa0a6)}
251
255
  .ops-copy{border:0;background:transparent;color:var(--dsw-alias-text-secondary,#9aa0a6);font-size:11px;cursor:pointer;padding:0}
252
256
  .ops-copy:hover{color:var(--dsw-alias-text-primary,#e6e6e6)}
257
+ .ops-modal-mask{position:fixed;inset:0;background:rgba(0,0,0,.55);display:flex;align-items:center;justify-content:center;z-index:60;padding:20px}
258
+ .ops-modal{width:min(720px,100%);max-height:82vh;overflow:auto;background:var(--dsw-alias-bg,#16191d);border:1px solid var(--dsw-alias-border,#3a3f45);border-radius:12px;padding:18px 20px}
259
+ .ops-modal-h{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:10px}
260
+ .ops-modal-title{font-size:15px;font-weight:600}
261
+ .ops-modal-x{border:0;background:transparent;color:var(--dsw-alias-text-secondary,#9aa0a6);font-size:18px;cursor:pointer;line-height:1}
262
+ .ops-modal-row{display:flex;gap:10px;font-size:13px;line-height:1.7;padding:3px 0}
263
+ .ops-modal-row b{min-width:64px;color:var(--dsw-alias-text-secondary,#9aa0a6);font-weight:500}
264
+ .ops-result-ok{color:#3fbf7f;font-weight:600}
265
+ .ops-result-bad{color:#ff6b6b;font-weight:600}
253
266
  .ops-composer{display:flex;gap:8px;align-items:flex-end;padding:10px 14px;border-top:1px solid var(--dsw-alias-border,#3a3f45)}
254
267
  `
255
268
 
@@ -429,6 +442,7 @@ window.__ModuleLoader__.load({
429
442
  const [monitors, setMonitors] = React.useState([])
430
443
  const [monForm, setMonForm] = React.useState({ type: 'http', target: '', label: '', intervalMinutes: 5, language: 'shell', script: '' })
431
444
  const [monEditId, setMonEditId] = React.useState('')
445
+ const [monDialog, setMonDialog] = React.useState(null)
432
446
  const [monBusy, setMonBusy] = React.useState('')
433
447
  const [health, setHealth] = React.useState(null)
434
448
  const [certs, setCerts] = React.useState([])
@@ -1460,13 +1474,23 @@ window.__ModuleLoader__.load({
1460
1474
  }
1461
1475
 
1462
1476
  const testMonitor = async (id) => {
1477
+ const monitor = monitors.find(item => item.id === id) || { id }
1463
1478
  setMonBusy('test:' + id)
1464
1479
  try {
1465
- await api('monitors', { method: 'POST', body: JSON.stringify({ host: detailHost || cHost, action: 'test', id }) }, 30_000)
1480
+ const data = await api('monitors', { method: 'POST', body: JSON.stringify({ host: detailHost || cHost, action: 'test', id }) }, 45_000)
1481
+ setMonDialog({ monitor, result: data.result, hints: data.hints || [], diag: null })
1466
1482
  await loadMonitors(detailHost || cHost)
1467
1483
  } catch (e) { setError(String(e.message || e)) } finally { setMonBusy('') }
1468
1484
  }
1469
1485
 
1486
+ const diagnoseMonitorUi = async (id) => {
1487
+ setMonBusy('diag:' + id)
1488
+ try {
1489
+ const data = await api('monitors', { method: 'POST', body: JSON.stringify({ host: detailHost || cHost, action: 'diagnose', id }) }, 60_000)
1490
+ setMonDialog(current => (current ? { ...current, diag: data } : current))
1491
+ } catch (e) { setError(String(e.message || e)) } finally { setMonBusy('') }
1492
+ }
1493
+
1470
1494
  const removeMonitor = async (id) => {
1471
1495
  if (!window.confirm(T.monRemove + '?')) return
1472
1496
  try {
@@ -2090,12 +2114,52 @@ window.__ModuleLoader__.load({
2090
2114
  : h('div', { className: 'ops-tabs' }, ...topTabs.map(([index, label]) =>
2091
2115
  h('button', { key: label, className: `ops-tab${tab === index ? ' on' : ''}`, onClick: () => setTab(index) }, label)))
2092
2116
 
2117
+ const monitorDialogView = monDialog ? h('div', {
2118
+ className: 'ops-modal-mask',
2119
+ onClick: () => setMonDialog(null),
2120
+ },
2121
+ h('div', { className: 'ops-modal', onClick: event => event.stopPropagation() },
2122
+ h('div', { className: 'ops-modal-h' },
2123
+ h('span', { className: 'ops-modal-title' }, monDialog.monitor.label || `${monDialog.monitor.type} ${monDialog.monitor.target || ''}`),
2124
+ h('button', { className: 'ops-modal-x', onClick: () => setMonDialog(null) }, '✕')),
2125
+ h('div', {
2126
+ className: monDialog.result?.ok ? 'ops-result-ok' : 'ops-result-bad',
2127
+ style: { fontSize: '15px', marginBottom: '10px' },
2128
+ }, monDialog.result?.ok ? `✓ ${T.monOk}` : `✕ ${T.monBad}`),
2129
+ h('div', { className: 'ops-modal-row' }, h('b', null, '目标'), h('span', { className: 'ops-mono' }, monDialog.monitor.target || '—')),
2130
+ h('div', { className: 'ops-modal-row' }, h('b', null, '详情'), h('span', null, monDialog.result?.detail || '—')),
2131
+ h('div', { className: 'ops-modal-row' }, h('b', null, T.monResult), h('span', null,
2132
+ `${monDialog.result?.ms ?? '—'}ms · ${T.monChecked} ${monDialog.result?.at ? fmt(monDialog.result.at) : '—'}`)),
2133
+ !monDialog.result?.ok && monDialog.hints.length
2134
+ ? h('div', { style: { marginTop: '12px' } },
2135
+ h('div', { className: 'ops-sub', style: { marginBottom: '6px' } }, T.monHint),
2136
+ ...monDialog.hints.map((hint, index) => h('div', { key: index, style: { fontSize: '13px', lineHeight: 1.8 } }, `· ${hint}`)))
2137
+ : null,
2138
+ !monDialog.result?.ok
2139
+ ? h('div', { className: 'ops-chips', style: { marginTop: '12px' } },
2140
+ h('button', {
2141
+ className: 'ops-btn ops-btn-primary ops-btn-sm',
2142
+ disabled: monBusy === 'diag:' + monDialog.monitor.id,
2143
+ onClick: () => { void diagnoseMonitorUi(monDialog.monitor.id) },
2144
+ }, monBusy === 'diag:' + monDialog.monitor.id ? T.monDiaging : T.monDiag))
2145
+ : null,
2146
+ monDialog.diag
2147
+ ? h('div', { style: { marginTop: '14px' } },
2148
+ h('div', { className: 'ops-sub', style: { marginBottom: '6px' } }, T.monDiagTitle),
2149
+ ...monDialog.diag.checks.map((check, index) => h('div', { key: index, style: { marginBottom: '10px' } },
2150
+ h('div', { className: check.ok ? 'ops-ok' : 'ops-warn', style: { fontSize: '12.5px' } }, `${check.ok ? '✓' : '·'} ${check.label}`),
2151
+ h('pre', { className: 'ops-pre', style: { maxHeight: '180px', marginTop: '4px' } }, check.output))))
2152
+ : null,
2153
+ h('div', { className: 'ops-chips', style: { marginTop: '14px', justifyContent: 'flex-end' } },
2154
+ h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setMonDialog(null) }, T.monClose)))) : null
2155
+
2093
2156
  return h('div', { className: 'ops-page' },
2094
2157
  h('style', null, CSS),
2095
2158
  header,
2096
2159
  nav,
2097
2160
  error ? h('p', { className: 'ops-err' }, error) : null,
2098
- body)
2161
+ body,
2162
+ monitorDialogView)
2099
2163
  }
2100
2164
 
2101
2165
  /** Keeps a render error visible instead of leaving an empty page. */
package/index.js CHANGED
@@ -816,7 +816,16 @@ function createApiHandler({ connection } = {}) {
816
816
  monitor.last = result
817
817
  monitor.lastOk = result.ok
818
818
  await saveMonitors(all)
819
- sendJson(res, 200, { host: cfg.name, id: monitor.id, result })
819
+ sendJson(res, 200, {
820
+ host: cfg.name, id: monitor.id, label: monitor.label, type: monitor.type, target: monitor.target,
821
+ result, hints: result.ok ? [] : monitorHints(monitor, result),
822
+ })
823
+ return
824
+ }
825
+ if (body.action === 'diagnose' && body.id) {
826
+ const monitor = list.find(item => item.id === body.id)
827
+ if (!monitor) { sendJson(res, 404, { error: 'monitor not found' }); return }
828
+ sendJson(res, 200, await diagnoseMonitor(cfg, monitor))
820
829
  return
821
830
  }
822
831
  const monitor = {
@@ -2820,6 +2829,102 @@ async function releaseLock(name) {
2820
2829
  try { await rm(join(kitDir(), name), { recursive: true, force: true }) } catch { /* ignore */ }
2821
2830
  }
2822
2831
 
2832
+
2833
+ /** Plain-language hints for a failing monitor, per type. */
2834
+ function monitorHints(monitor, result) {
2835
+ const type = monitor.type
2836
+ if (type === 'http') {
2837
+ return [
2838
+ '先在浏览器或 curl 打开这个地址,确认返回码',
2839
+ '检查证书是否过期(本面板「证书」卡片会显示剩余天数)',
2840
+ '确认 nginx/应用本身在跑(「应用」页看服务状态)',
2841
+ '如果是 127.0.0.1 地址,说明只有本机能访问,检查端口是否监听',
2842
+ ]
2843
+ }
2844
+ if (type === 'port') {
2845
+ return [
2846
+ '确认对应服务在运行(systemctl status 服务名)',
2847
+ '检查端口是否在监听(ss -ltnp | grep 端口号)',
2848
+ '如果服务在跑但端口不通,看是不是只绑定了 127.0.0.1',
2849
+ '云服务器还要确认安全组/防火墙放行了该端口',
2850
+ ]
2851
+ }
2852
+ if (type === 'process') {
2853
+ return [
2854
+ '进程可能已退出或被杀,先看日志和 dmesg 有没有 OOM',
2855
+ '确认启动命令和用户是否正确(有的进程只能以特定用户启动)',
2856
+ '如果是 Java 进程,检查堆内存是否不足',
2857
+ ]
2858
+ }
2859
+ if (type === 'service') {
2860
+ return [
2861
+ 'systemctl status 看具体报错',
2862
+ 'journalctl -u 服务名 -n 50 看最近日志',
2863
+ '常见原因:配置写错、端口被占用、依赖服务未启动',
2864
+ ]
2865
+ }
2866
+ if (type === 'script') {
2867
+ return [
2868
+ '看脚本的退出码和输出(面板会显示最后一行输出)',
2869
+ '确认解释器存在:python 需要 python3,js 需要 node',
2870
+ '脚本里不要依赖交互式命令,非 0 退出即视为异常',
2871
+ ]
2872
+ }
2873
+ return ['检查目标配置是否正确']
2874
+ }
2875
+
2876
+ /** Targeted checks when a monitor fails, so the user has somewhere to look. */
2877
+ async function diagnoseMonitor(cfg, monitor) {
2878
+ const type = monitor.type
2879
+ const target = String(monitor.target || '')
2880
+ const checks = []
2881
+ const run = async (label, command, options = {}) => {
2882
+ const result = await ssh(cfg, command, options.timeoutMs || 25_000)
2883
+ const output = clip(`${result.stdout || ''}${cleanStderr(result.stderr)}`.trim(), 1200) || '(无输出)'
2884
+ const ok = typeof options.judge === 'function' ? options.judge(output, result) : result.ok
2885
+ checks.push({ label, ok, output })
2886
+ }
2887
+
2888
+ if (type === 'port') {
2889
+ const [host, port] = target.split(':')
2890
+ await run('端口是否监听', `ss -ltnp 2>/dev/null | grep -E ':${Number(port) || port}\\b' || echo '没有进程监听该端口'`,
2891
+ { judge: output => !/没有进程监听/.test(output) })
2892
+ await run('本机连通性', `timeout 4 bash -c '</dev/tcp/${String(host).replace(/[^A-Za-z0-9.-]/g, '')}/${Number(port)}' 2>/dev/null && echo 可连接 || echo 连接失败`,
2893
+ { judge: output => /可连接/.test(output) })
2894
+ await run('防火墙状态', `systemctl is-active firewalld 2>/dev/null; iptables -S 2>/dev/null | head -15 || true`,
2895
+ { judge: () => true })
2896
+ } else if (type === 'process') {
2897
+ await run('匹配的进程', `pgrep -af ${q(target)} || echo '没有匹配的进程'`,
2898
+ { judge: output => !/没有匹配的进程/.test(output) })
2899
+ await run('最近的核心报错', `dmesg 2>/dev/null | grep -iE 'oom|killed process' | tail -5 || echo '(无)'`,
2900
+ { judge: output => /^\(无\)$/.test(output.trim()) })
2901
+ } else if (type === 'service') {
2902
+ const unit = target.replace(/[^A-Za-z0-9@._-]/g, '')
2903
+ await run('服务状态', `systemctl status ${unit} --no-pager 2>&1 | head -20`,
2904
+ { judge: output => /Active:\s*active/.test(output) })
2905
+ await run('最近日志', `journalctl -u ${unit} -n 30 --no-pager 2>&1 | tail -30`,
2906
+ { judge: () => true })
2907
+ } else if (type === 'http') {
2908
+ await run('HTTP 响应头', `curl -sS -I --max-time 10 ${q(target)} 2>&1 | head -20`,
2909
+ { judge: output => /HTTP\/\d\.\d 2\d\d|HTTP\/\d\.\d 3\d\d/.test(output) })
2910
+ await run('本机到目标', `curl -sS -o /dev/null -w 'code=%{http_code} time=%{time_total}s\\n' --max-time 10 ${q(target)} 2>&1`,
2911
+ { judge: output => /code=(2|3)\d\d/.test(output) })
2912
+ await run('监听端口', `nginx -T 2>/dev/null | grep -E 'listen|server_name' | head -10 || echo '(未检测到 nginx 配置)'`,
2913
+ { judge: () => true })
2914
+ } else {
2915
+ await run('脚本解释器', `command -v bash; command -v python3; command -v node; true`)
2916
+ }
2917
+
2918
+ return {
2919
+ host: cfg.name,
2920
+ id: monitor.id,
2921
+ target,
2922
+ type,
2923
+ checks,
2924
+ hints: monitorHints(monitor, { ok: false }),
2925
+ }
2926
+ }
2927
+
2823
2928
  export function apply(ctx) {
2824
2929
  hostCtx = ctx
2825
2930
  const tools = [
@@ -3202,7 +3307,7 @@ export function apply(ctx) {
3202
3307
  + 'process (command pattern), service (systemd unit).',
3203
3308
  parameters: {
3204
3309
  host: { type: 'string', description: 'host name from ops_hosts' },
3205
- action: { type: 'string', enum: ['list', 'add', 'remove', 'test'], description: 'defaults to list' },
3310
+ action: { type: 'string', enum: ['list', 'add', 'remove', 'test', 'diagnose'], description: 'defaults to list' },
3206
3311
  type: { type: 'string', enum: ['http', 'port', 'process', 'service', 'script'], description: 'with action=add' },
3207
3312
  language: { type: 'string', enum: ['shell', 'python', 'js'], description: 'with type=script' },
3208
3313
  script: { type: 'string', description: 'with type=script: the script body' },
@@ -3225,7 +3330,12 @@ export function apply(ctx) {
3225
3330
  const monitor = list.find(item => item.id === args.id)
3226
3331
  if (!monitor) throw new Error('monitor not found')
3227
3332
  const result = await runMonitor(cfg, monitor)
3228
- return { host: cfg.name, id: monitor.id, result }
3333
+ return { host: cfg.name, id: monitor.id, result, hints: result.ok ? [] : monitorHints(monitor, result) }
3334
+ }
3335
+ if (args.action === 'diagnose') {
3336
+ const monitor = list.find(item => item.id === args.id)
3337
+ if (!monitor) throw new Error('monitor not found')
3338
+ return diagnoseMonitor(cfg, monitor)
3229
3339
  }
3230
3340
  const monitor = {
3231
3341
  id: `m${Date.now().toString(36)}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ops-kit",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "Server operations kit for DeepSeek Harness: server cards, health charts, config browser, app manager and plain-language AI diagnosis — over SSH, no agent install.",
5
5
  "license": "MIT",
6
6
  "type": "module",