pi-ssh-manager 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/CHANGELOG.md +19 -0
- package/LICENSE +21 -0
- package/README.md +90 -2
- package/package.json +52 -4
- package/src/config-reader.ts +824 -0
- package/src/index.ts +209 -0
- package/src/manager.ts +371 -0
- package/src/model.ts +144 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.2.0] - 2026-11-22
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- 将斜杠命令更名为 `/ssh`,支持 `list`、`get`、`import` 子命令及主机别名自动补全。
|
|
8
|
+
- 将工具名称与扩展导出标识规范为 `ssh_manager`(`registerSshManager` / `sshManager`)。
|
|
9
|
+
- 将受管配置目录与 `~/.ssh/config` 区块标记统一为 `~/.ssh/pi-ssh-manager/` 与 `pi-ssh-manager`。
|
|
10
|
+
|
|
11
|
+
## [0.1.0] - 2026-11-22
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- 新增 SSH 主机管理扩展工具与斜杠命令,支持查询、搜索、添加、更新和删除 SSH 主机配置。
|
|
16
|
+
- 支持递归解析 `~/.ssh/config` 及 `Include` 规则中的已有 OpenSSH 主机配置,并生成参数数组与安全连接命令。
|
|
17
|
+
- 支持从外部 OpenSSH 配置文件或目录导入主机记录、引用密钥、公钥及 `known_hosts` 主机指纹。
|
|
18
|
+
- 新增受管配置自动备份、写入失败回滚、符号链接目标防护,以及危险指令隐藏与条件配置告警提示。
|
|
19
|
+
- 支持 Windows、Linux 与 macOS,并作为标准 Pi Package 通过 `pi install` 安装加载。
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 onprs
|
|
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,91 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Pi SSH Manager
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
为 [Pi](https://github.com/earendil-works/pi)(`@earendil-works/pi-coding-agent`)提供本机 SSH 主机查询与 OpenSSH 配置管理扩展,注册 `ssh_manager` 工具与 `/ssh` 交互式斜杠命令。
|
|
4
|
+
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- **主机列表与连接查询**:统一检索已有 OpenSSH 配置与受管主机记录,支持关键词搜索、分页及完整连接参数输出。
|
|
8
|
+
- **主机添加、更新与删除**:新增或增量修改主机别名、地址、端口、用户名、密钥路径、备注与其他 OpenSSH 选项;删除受管主机时保留既有密钥文件。
|
|
9
|
+
- **OpenSSH 配置导入**:支持从外部 OpenSSH 配置文件或目录导入主机,同时复制引用的密钥、相应公钥与 `known_hosts` 指纹记录,保留本机与来源原有记录。
|
|
10
|
+
- **自动备份与安全防护**:受管配置保存在 `~/.ssh/pi-ssh-manager/` 并通过 `Include` 接入 `~/.ssh/config`,修改前自动备份;查询结果不读取密钥内容,导入与解析过程不执行配置内声明的外部命令,遇到符号链接写入目标或无法完整解析的条件规则时自动中止并提示。
|
|
11
|
+
- **交互式管理与 AI 工具协同**:提供 `/ssh` 交互菜单、快捷子命令与主机别名自动补全,并允许 Pi 直接调用 `ssh_manager` 工具完成配置查询与维护。
|
|
12
|
+
- **跨平台支持**:支持 Windows、Linux 与 macOS。
|
|
13
|
+
|
|
14
|
+
## 环境要求
|
|
15
|
+
|
|
16
|
+
- Node.js `>= 22.19.0`
|
|
17
|
+
- 已安装 `@earendil-works/pi-coding-agent`(`pi` 命令可用)
|
|
18
|
+
- 使用生成的连接命令或连接远程主机时,本机需安装 OpenSSH 客户端(`ssh`)
|
|
19
|
+
|
|
20
|
+
## 安装
|
|
21
|
+
|
|
22
|
+
通过 npm 安装:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pi install npm:pi-ssh-manager
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
或通过 GitHub 仓库安装:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pi install https://github.com/onprs/Pi-SSH-Manager.git
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
单次会话临时加载试用:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pi -e npm:pi-ssh-manager
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
升级与卸载:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pi update --extensions
|
|
44
|
+
pi remove npm:pi-ssh-manager
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 快速开始
|
|
48
|
+
|
|
49
|
+
安装后启动 `pi`(或执行 `/reload`):
|
|
50
|
+
|
|
51
|
+
1. 输入 `/ssh` 打开交互式管理菜单,进行查看、编辑、添加或导入操作。
|
|
52
|
+
2. 也可直接向 Pi 描述需求,例如“列出 SSH 主机”“查询某台主机的连接信息”“添加 SSH 主机”或“导入这个目录下的 SSH 配置”,由 Pi 调用 `ssh_manager` 工具处理。
|
|
53
|
+
|
|
54
|
+
## 斜杠命令
|
|
55
|
+
|
|
56
|
+
在 Pi 交互界面中可使用以下命令:
|
|
57
|
+
|
|
58
|
+
| 命令 | 说明 |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `/ssh` | 打开主机查看、编辑、添加与导入交互菜单 |
|
|
61
|
+
| `/ssh list` | 列出本机已有及受管的 SSH 主机 |
|
|
62
|
+
| `/ssh get <主机别名>` | 查看指定主机的地址、密钥状态、连接命令与警告信息 |
|
|
63
|
+
| `/ssh import <配置文件或目录路径>` | 从指定 OpenSSH 配置或目录导入主机与凭据 |
|
|
64
|
+
|
|
65
|
+
## `ssh_manager` 工具说明
|
|
66
|
+
|
|
67
|
+
| 操作 (`action`) | 用途 | 主要参数 |
|
|
68
|
+
| --- | --- | --- |
|
|
69
|
+
| `list` | 列出或搜索主机 | `query`、`offset`、`limit` |
|
|
70
|
+
| `get` | 查询地址、端口、用户、密钥状态和连接参数 | `host` |
|
|
71
|
+
| `upsert` | 添加或更新受管主机 | `host`、`hostname`、`port`、`user`、`identityFiles`、`description`、`options` |
|
|
72
|
+
| `delete` | 删除受管的主机记录 | `host` |
|
|
73
|
+
| `import` | 导入外部 SSH 配置及引用凭据 | `source`、`overwrite` |
|
|
74
|
+
|
|
75
|
+
### 参数与配置规则
|
|
76
|
+
|
|
77
|
+
- 新增主机须提供 `host` 与 `hostname`,`port` 默认为 `22`。
|
|
78
|
+
- 更新已有受管主机时保留未提供的字段;传入空字符串可清除 `user` 或 `description`,传入空数组可清除 `identityFiles`;提供 `options` 时整体替换该主机的其他 OpenSSH 选项。
|
|
79
|
+
- 密钥路径支持绝对路径与 `~/` 路径(清空请传空数组或 `none`)。
|
|
80
|
+
- 导入时遇到同名受管主机默认保留现有记录,设置 `overwrite: true` 可覆盖更新。
|
|
81
|
+
|
|
82
|
+
## 数据目录与安全说明
|
|
83
|
+
|
|
84
|
+
- 受管主机数据、生成配置、导入密钥、受管 `known_hosts` 与配置备份保存在 `~/.ssh/pi-ssh-manager/`,并通过标记区块中的 `Include` 接入 `~/.ssh/config`,修改后可直接在终端使用 `ssh <主机别名>`。
|
|
85
|
+
- 修改受管文件或 `~/.ssh/config` 前会在 `~/.ssh/pi-ssh-manager/backups/` 自动保留备份。
|
|
86
|
+
- 若 `~/.ssh/config` 或受管目标文件为符号链接,写入操作将中止以保护现有链接配置。
|
|
87
|
+
- 本扩展仅作静态配置解析与管理,不主动建立 SSH 连接,不读取私钥文件内容,也不执行配置文件中的 `ProxyCommand`、`RemoteCommand` 或 `Match exec` 等指令。
|
|
88
|
+
|
|
89
|
+
## 开源协议
|
|
90
|
+
|
|
91
|
+
[MIT](./LICENSE)
|
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ssh-manager",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "SSH host query and OpenSSH configuration manager extension for Pi",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22.19.0"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/onprs/Pi-SSH-Manager.git"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/onprs/Pi-SSH-Manager#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/onprs/Pi-SSH-Manager/issues"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"pi-package",
|
|
20
|
+
"pi-extension",
|
|
21
|
+
"ssh",
|
|
22
|
+
"openssh",
|
|
23
|
+
"ssh-config"
|
|
24
|
+
],
|
|
25
|
+
"pi": {
|
|
26
|
+
"extensions": [
|
|
27
|
+
"./src/index.ts"
|
|
28
|
+
],
|
|
29
|
+
"changelogPath": "./CHANGELOG.md"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"src",
|
|
33
|
+
"CHANGELOG.md",
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"typecheck": "node ./node_modules/typescript/bin/tsc --noEmit",
|
|
39
|
+
"test": "node --experimental-strip-types --test",
|
|
40
|
+
"check": "npm run typecheck && npm test"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@earendil-works/pi-ai": "*",
|
|
44
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
45
|
+
"typebox": "*"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@earendil-works/pi-ai": "^1.6.0",
|
|
49
|
+
"@earendil-works/pi-coding-agent": "^1.6.0",
|
|
50
|
+
"@types/node": "^22.19.0",
|
|
51
|
+
"typebox": "^1.3.27",
|
|
52
|
+
"typescript": "^5.8.2"
|
|
53
|
+
}
|
|
54
|
+
}
|