dsh-ops-kit 0.0.0-stage → 0.3.1
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 +168 -2
- package/README.zh-CN.md +154 -0
- package/client.js +2094 -0
- package/cordis.patch.yml +4 -0
- package/docs/DETAIL.md +71 -0
- package/docs/USAGE.zh-CN.md +192 -0
- package/icon.svg +9 -0
- package/index.js +3524 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +63 -4
package/cordis.patch.yml
ADDED
package/docs/DETAIL.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Ops kit — server operations from a chat
|
|
2
|
+
|
|
3
|
+
## What it is
|
|
4
|
+
|
|
5
|
+
A DeepSeek Harness bundle for running Linux servers without leaving the
|
|
6
|
+
conversation. It contributes **34 agent tools and a sidebar panel**, and it
|
|
7
|
+
never needs an agent installed on the target host.
|
|
8
|
+
|
|
9
|
+
Authentication is either your existing SSH key / ssh-agent (through the system
|
|
10
|
+
`ssh` client in `BatchMode`, so the plugin never reads your key files) or a
|
|
11
|
+
password you store per host (through the plugin's own `ssh2` client, the only
|
|
12
|
+
path that keeps a secret on disk).
|
|
13
|
+
|
|
14
|
+
## What it adds
|
|
15
|
+
|
|
16
|
+
- **Inventory and connect** — host list, connectivity/latency test, public-key
|
|
17
|
+
installation, a read-only scan of ports, services, containers, nginx sites,
|
|
18
|
+
java processes, crontab and mounts.
|
|
19
|
+
- **Look at a host, read-only** — status snapshot, parallel check of every host,
|
|
20
|
+
0–100 health score, CPU/memory/disk samples, top processes, directory sizes,
|
|
21
|
+
log tails, file listings, certificate expiry, and a plain-language diagnosis.
|
|
22
|
+
- **Change something, with confirm guards** — one shell command, the same command
|
|
23
|
+
across hosts, systemd start/stop/restart, docker restart, killing a pid,
|
|
24
|
+
journal cleanup, and monitor management. Everything that changes state
|
|
25
|
+
requires `confirm: true` and fails closed instead of asking in a second turn.
|
|
26
|
+
- **Config and files** — read a config file, write one after backing it up, and
|
|
27
|
+
diff or roll back any `.bak.<ts>` version.
|
|
28
|
+
- **Backups, certificates, schedule, deploy** — MySQL dump or directory archive
|
|
29
|
+
with retention and restore, certificate probing with `certbot renew --dry-run`,
|
|
30
|
+
crontab editing, and git pull → build → restart → health check with automatic
|
|
31
|
+
rollback when the health check fails.
|
|
32
|
+
- **Alerts and AI** — delivery to Feishu / DingTalk / WeCom / any webhook with
|
|
33
|
+
per-channel levels and 10-minute dedupe, plus a natural-language `ops_ask` that
|
|
34
|
+
runs read-only commands itself.
|
|
35
|
+
|
|
36
|
+
## Panel
|
|
37
|
+
|
|
38
|
+
A sidebar page with ten sub-pages per host: overview, monitor, config, apps,
|
|
39
|
+
logs, files, terminal (a real PTY), backups, tasks and deploy. The overview runs
|
|
40
|
+
one host or all hosts and records each run in history. Restart, stop, restore and
|
|
41
|
+
rollback all ask for confirmation in the panel first.
|
|
42
|
+
|
|
43
|
+
## Requirements
|
|
44
|
+
|
|
45
|
+
- macOS or Linux host running DSH with `ssh` on `PATH`.
|
|
46
|
+
- Key or ssh-agent authentication already working for each host (`ssh -o
|
|
47
|
+
BatchMode=yes user@host true` must succeed) — or `ssh2` present in the profile
|
|
48
|
+
if you use stored passwords.
|
|
49
|
+
- Remote Linux with `systemctl` for the service tools; Docker is optional and
|
|
50
|
+
detected per call. Privileged actions need the host configured with
|
|
51
|
+
`sudo: true` and `sudo -n` allowed on the target.
|
|
52
|
+
|
|
53
|
+
## Data and safety
|
|
54
|
+
|
|
55
|
+
State lives in `$DSH_HOME/ops-kit/` (default `~/.dsh/ops-kit/`), deliberately
|
|
56
|
+
outside the profile so upgrading or removing the bundle never loses the
|
|
57
|
+
inventory: `hosts.json`, `config.json`, `history.json`, `state.json`,
|
|
58
|
+
`alerts.json`, `channels.json`, and — only when passwords are used —
|
|
59
|
+
`secrets.json`.
|
|
60
|
+
|
|
61
|
+
`secrets.json` and `channels.json` are mode 0600. Passwords in `secrets.json`
|
|
62
|
+
are **base64-encoded, not encrypted**; treat that file as a secret. Webhook URLs
|
|
63
|
+
are secrets too, which is why `channels.json` is 0600.
|
|
64
|
+
|
|
65
|
+
Tool output is clipped at 8 KB with an explicit truncation marker.
|
|
66
|
+
|
|
67
|
+
## Limitations
|
|
68
|
+
|
|
69
|
+
- SSH only: no cloud provider APIs, no Docker Compose or k8s orchestration.
|
|
70
|
+
- Metric retention is a bounded row cap, not a time-series database.
|
|
71
|
+
- Windows targets need an SSH server with a POSIX-like shell.
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# dsh-ops-kit 使用说明
|
|
2
|
+
|
|
3
|
+
面向「第一次装上、想把一台服务器管起来」的人。
|
|
4
|
+
工具参数不在这里罗列 —— 那是模型读的 schema,会随版本变;这里只写**前置条件、典型流程、设置项和排障**。
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 1. 前置条件(先看这条,能省掉一半排障)
|
|
9
|
+
|
|
10
|
+
插件连服务器有两条路径,先确定你走哪条:
|
|
11
|
+
|
|
12
|
+
| 路径 | 需要什么 | 适合 |
|
|
13
|
+
|---|---|---|
|
|
14
|
+
| **密钥 / ssh-agent**(默认) | 本机系统 `ssh` 能免密登录目标机(`ssh 用户@IP` 直接进去) | 大多数情况,推荐 |
|
|
15
|
+
| **密码** | 该 profile 里已装有 `ssh2` 包 | 临时机器、还没配密钥 |
|
|
16
|
+
|
|
17
|
+
先在**自己终端**里验一下,这一步过了插件才可能通:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
ssh -o BatchMode=yes 用户@IP 'echo ok' # 输出 ok 才算通
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`BatchMode=yes` 很关键 —— 插件就是用这个模式跑的,凡是会弹交互提示(比如首次连接确认主机指纹、或要求输密码)的情况,插件会**直接失败**。
|
|
24
|
+
|
|
25
|
+
### 还要满足
|
|
26
|
+
|
|
27
|
+
- **目标机有 POSIX shell**:Windows 机器只有当它自己跑了 SSH 服务且带类 POSIX shell 时才行。
|
|
28
|
+
- **需要 root 的操作要免密 sudo**:在主机配置里打开 `sudo: true`,且目标机允许 `sudo -n`(NOPASSWD)。否则「重启服务」这类动作会以权限错误失败,读操作不受影响。
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 2. 五分钟跑通
|
|
33
|
+
|
|
34
|
+
### 第一步:加主机
|
|
35
|
+
|
|
36
|
+
```text
|
|
37
|
+
ops_hosts action=add name=web-1 host=10.0.0.11 user=deploy key=~/.ssh/id_ed25519 defaultHost=true
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
只填 IP + 用户 + 密码也能加(会存进 `secrets.json`),但建议走密钥。
|
|
41
|
+
|
|
42
|
+
### 第二步:验连通
|
|
43
|
+
|
|
44
|
+
```text
|
|
45
|
+
ops_ssh_test host=web-1
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
返回 `ok`、延迟、以及实际用的认证方式。**这一步不通就别往下走**,先回到第 1 节。
|
|
49
|
+
|
|
50
|
+
> 如果加了密码、但连不上并提示 `ssh2 is not installed in this profile`,说明这个 profile 缺 `ssh2`。要么装上它,要么改用密钥(此时可先跑 `ops_ssh_install_key host=web-1`,用已存的密码把本机公钥装上去,之后就不需要密码了)。
|
|
51
|
+
|
|
52
|
+
### 第三步:看一眼
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
ops_status host=web-1
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
一次给出:运行时长与负载、内存、根分区磁盘、失败的 systemd 单元、Docker 容器。
|
|
59
|
+
|
|
60
|
+
想一次看全部主机:
|
|
61
|
+
|
|
62
|
+
```text
|
|
63
|
+
ops_check_all
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 第四步:打开面板
|
|
67
|
+
|
|
68
|
+
侧边栏 **Ops** 页。这里能增删主机、跑单机检查、批量下命令;后面第 3 节细说。
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 3. 面板十个子页
|
|
73
|
+
|
|
74
|
+
从「多机概览」点进某台机器,左侧是十个子页:
|
|
75
|
+
|
|
76
|
+
| 子页 | 干什么 |
|
|
77
|
+
|---|---|
|
|
78
|
+
| **概览** | 健康分、关键指标、证书到期、备份状态 |
|
|
79
|
+
| **监控** | 该机的监控项(http / 端口 / 进程 / 服务 / 脚本),可增删测 |
|
|
80
|
+
| **配置** | 浏览常见配置文件,改之前自动备份 `.bak.<时间戳>`,可看历史并回滚 |
|
|
81
|
+
| **应用** | 正在跑的服务与容器,带 日志 / 重启 / 停止 |
|
|
82
|
+
| **日志** | systemd 单元或任意日志文件的尾部 |
|
|
83
|
+
| **文件** | 目录列表、大小、修改时间 |
|
|
84
|
+
| **终端** | 网页里的 SSH 终端(需要 `ssh2`) |
|
|
85
|
+
| **备份** | 备份列表、一键恢复、删除 |
|
|
86
|
+
| **计划任务** | crontab 可视化增删 |
|
|
87
|
+
| **发布** | 一键发布任务:git pull → 构建 → 重启 → 健康检查 |
|
|
88
|
+
|
|
89
|
+
**重启 / 停止 / 回滚 / 恢复都会先弹确认**,不会点了就执行。
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 4. 常用任务怎么说
|
|
94
|
+
|
|
95
|
+
不需要记工具名,直接说人话:
|
|
96
|
+
|
|
97
|
+
```text
|
|
98
|
+
看一下 web-1 的状态
|
|
99
|
+
web-1 上 nginx 最近 50 行日志
|
|
100
|
+
磁盘满了,看看 / 下面谁占的空间
|
|
101
|
+
把 web-1 上的 my-api 重启一下(我确认)
|
|
102
|
+
所有机器上跑一下 uptime
|
|
103
|
+
web-1 的证书还有几天
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 提问式诊断
|
|
107
|
+
|
|
108
|
+
```text
|
|
109
|
+
ops_ask host=web-1 question="mysql 还活着吗,为什么连不上"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
模型会自己挑**只读**命令去查并给结论;遇到要改状态的命令,它只返回「需要确认」,不会擅自执行。
|
|
113
|
+
|
|
114
|
+
### 批量
|
|
115
|
+
|
|
116
|
+
```text
|
|
117
|
+
ops_batch command="df -h" hosts=[web-1,web-2]
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
不给 `hosts` 就是全部主机。破坏性命令必须带 `confirm`。
|
|
121
|
+
|
|
122
|
+
### 备份
|
|
123
|
+
|
|
124
|
+
```text
|
|
125
|
+
ops_backup host=web-1 action=backup type=mysql database=app
|
|
126
|
+
ops_backup host=web-1 action=list
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
默认存在 `/home/backup`,默认保留 7 份,恢复和删除都要确认。
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## 5. 设置项(`ops_config`)
|
|
134
|
+
|
|
135
|
+
留空调用就是读当前值。默认值如下:
|
|
136
|
+
|
|
137
|
+
| 键 | 默认 | 范围 | 说明 |
|
|
138
|
+
|---|---|---|---|
|
|
139
|
+
| `enabled` | `true` | — | 是否开启后台定时检查 |
|
|
140
|
+
| `intervalMinutes` | `10` | 1–1440 | 后台检查间隔(分钟) |
|
|
141
|
+
| `diskWarnPercent` | `90` | 50–99 | 根分区超过此比例告警 |
|
|
142
|
+
| `metricsMinutes` | `5` | 1–60 | 指标采样间隔(分钟) |
|
|
143
|
+
| `timeoutSec` | `25` | 5–300 | 通用请求超时 |
|
|
144
|
+
| `scanSec` | `90` | 10–600 | 清单扫描超时(主机多或慢时调大) |
|
|
145
|
+
| `actionSec` | `45` | 10–600 | 动作与取日志超时 |
|
|
146
|
+
| `quickCommands` | 6 条常用命令 | 最多 12 条 | 终端下方的快捷键 |
|
|
147
|
+
| `aiEnabled` | `true` | — | 是否启用 `ops_ask` 的 AI 诊断 |
|
|
148
|
+
| `aiProvider` / `aiModel` | 空 = 用 DSH 默认模型 | — | 指定运维 AI 用哪个模型 |
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## 6. 数据存在哪、有多敏感
|
|
153
|
+
|
|
154
|
+
全部在 `$DSH_HOME/ops-kit/`(默认 `~/.dsh/ops-kit/`),**刻意放在 profile 之外**,所以升级或卸载插件都不会丢。
|
|
155
|
+
|
|
156
|
+
| 文件 | 内容 | 敏感度 |
|
|
157
|
+
|---|---|---|
|
|
158
|
+
| `hosts.json` | 主机清单 | 低 |
|
|
159
|
+
| `secrets.json` | 密码,**base64 编码而非加密**,权限 0600 | **高,等同密钥** |
|
|
160
|
+
| `channels.json` | 告警渠道 URL,权限 0600 | **高,URL 本身就是密钥** |
|
|
161
|
+
| `history.json` | 每次检查的历史 | 低 |
|
|
162
|
+
| `config.json` | 上面那张设置表 | 低 |
|
|
163
|
+
| `state.json` / `alerts.json` | 调度状态与告警记录 | 低 |
|
|
164
|
+
|
|
165
|
+
请注意 `secrets.json` 里**不是加密的**:任何能读这个文件的人都能拿到服务器密码。要么改用密钥认证,要么确保这台机器的账户权限是干净的。
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## 7. 排障
|
|
170
|
+
|
|
171
|
+
| 现象 | 原因与处理 |
|
|
172
|
+
|---|---|
|
|
173
|
+
| `ops_ssh_test` 不通,但手敲 `ssh` 能进 | 插件用 `BatchMode`,不处理交互。把主机指纹先加进 `known_hosts`,或改用密钥 |
|
|
174
|
+
| 提示 `ssh2 is not installed in this profile` | 用的是密码路径但 profile 里没 `ssh2`。装 `ssh2`,或改用密钥(`ops_ssh_install_key`) |
|
|
175
|
+
| 重启服务报权限错误 | 主机没开 `sudo: true`,或目标机不允 `sudo -n` |
|
|
176
|
+
| 结果末尾有截断标记 | 输出超 8 KB 被裁掉了。缩小范围(`lines=`、更精确的命令)而不是调大上限 |
|
|
177
|
+
| 定时检查没动静 | `ops_config` 里 `enabled` 是否为 true;`scanSec` 是否太小导致大面积超时 |
|
|
178
|
+
| 告警没到 | 渠道 URL 是否过期(群机器人会重置);级别是否匹配;相同告警 10 分钟内不重发 |
|
|
179
|
+
| 面板打不开有数据但空 | 检查该会话是否加载了本插件,以及 `/ops-kit/api` 是否被反代拦截 |
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## 8. 会改变状态的操作用了会怎样
|
|
184
|
+
|
|
185
|
+
| 操作 | 需要 |
|
|
186
|
+
|---|---|
|
|
187
|
+
| 启停 / 重启服务、重启容器 | `confirm: true` |
|
|
188
|
+
| `ops_run` 执行破坏性命令(`rm -rf /`、`mkfs`、`dd` 写设备、`shutdown`/`reboot`) | `confirm: true`,否则直接拒绝 |
|
|
189
|
+
| 备份恢复与删除、配置回滚、一键发布 | `confirm: true` |
|
|
190
|
+
| 健康检查、`ops_status`、`ops_check_all`、`ops_ssh_test`、`ops_ask` | 只读,不需要确认 |
|
|
191
|
+
|
|
192
|
+
设计原则是**读操作永远可以随便跑,写操作必须有人点头**。
|
package/icon.svg
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Ops kit">
|
|
2
|
+
<rect width="64" height="64" rx="14" fill="#0f2f2a"/>
|
|
3
|
+
<g fill="none" stroke="#5ee0b5" stroke-width="3" stroke-linecap="round">
|
|
4
|
+
<rect x="14" y="12" width="36" height="12" rx="3"/>
|
|
5
|
+
<rect x="14" y="26" width="36" height="12" rx="3"/>
|
|
6
|
+
<path d="M20 18h1M20 32h1"/>
|
|
7
|
+
</g>
|
|
8
|
+
<path d="M22 50l6 6 14-14" fill="none" stroke="#5ee0b5" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
|
|
9
|
+
</svg>
|