@yivan-lab/pretty-please 1.3.1 → 1.5.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.
Files changed (94) hide show
  1. package/README.md +250 -620
  2. package/bin/pls.tsx +178 -40
  3. package/dist/bin/pls.js +149 -27
  4. package/dist/package.json +10 -2
  5. package/dist/src/__integration__/command-generation.test.d.ts +5 -0
  6. package/dist/src/__integration__/command-generation.test.js +508 -0
  7. package/dist/src/__integration__/error-recovery.test.d.ts +5 -0
  8. package/dist/src/__integration__/error-recovery.test.js +511 -0
  9. package/dist/src/__integration__/shell-hook-workflow.test.d.ts +5 -0
  10. package/dist/src/__integration__/shell-hook-workflow.test.js +375 -0
  11. package/dist/src/__tests__/alias.test.d.ts +5 -0
  12. package/dist/src/__tests__/alias.test.js +421 -0
  13. package/dist/src/__tests__/chat-history.test.d.ts +5 -0
  14. package/dist/src/__tests__/chat-history.test.js +372 -0
  15. package/dist/src/__tests__/config.test.d.ts +5 -0
  16. package/dist/src/__tests__/config.test.js +822 -0
  17. package/dist/src/__tests__/history.test.d.ts +5 -0
  18. package/dist/src/__tests__/history.test.js +439 -0
  19. package/dist/src/__tests__/remote-history.test.d.ts +5 -0
  20. package/dist/src/__tests__/remote-history.test.js +641 -0
  21. package/dist/src/__tests__/remote.test.d.ts +5 -0
  22. package/dist/src/__tests__/remote.test.js +689 -0
  23. package/dist/src/__tests__/shell-hook-install.test.d.ts +5 -0
  24. package/dist/src/__tests__/shell-hook-install.test.js +413 -0
  25. package/dist/src/__tests__/shell-hook-remote.test.d.ts +5 -0
  26. package/dist/src/__tests__/shell-hook-remote.test.js +507 -0
  27. package/dist/src/__tests__/shell-hook.test.d.ts +5 -0
  28. package/dist/src/__tests__/shell-hook.test.js +440 -0
  29. package/dist/src/__tests__/sysinfo.test.d.ts +5 -0
  30. package/dist/src/__tests__/sysinfo.test.js +572 -0
  31. package/dist/src/__tests__/system-history.test.d.ts +5 -0
  32. package/dist/src/__tests__/system-history.test.js +457 -0
  33. package/dist/src/components/Chat.js +9 -28
  34. package/dist/src/config.d.ts +2 -0
  35. package/dist/src/config.js +30 -2
  36. package/dist/src/mastra-chat.js +10 -6
  37. package/dist/src/multi-step.js +10 -8
  38. package/dist/src/project-context.d.ts +22 -0
  39. package/dist/src/project-context.js +168 -0
  40. package/dist/src/prompts.d.ts +4 -4
  41. package/dist/src/prompts.js +23 -6
  42. package/dist/src/shell-hook.d.ts +32 -0
  43. package/dist/src/shell-hook.js +226 -33
  44. package/dist/src/sysinfo.d.ts +38 -9
  45. package/dist/src/sysinfo.js +245 -21
  46. package/dist/src/system-history.d.ts +18 -0
  47. package/dist/src/system-history.js +151 -0
  48. package/dist/src/ui/__tests__/theme.test.d.ts +5 -0
  49. package/dist/src/ui/__tests__/theme.test.js +688 -0
  50. package/dist/src/upgrade.js +3 -0
  51. package/dist/src/user-preferences.d.ts +44 -0
  52. package/dist/src/user-preferences.js +147 -0
  53. package/dist/src/utils/__tests__/platform-capabilities.test.d.ts +5 -0
  54. package/dist/src/utils/__tests__/platform-capabilities.test.js +214 -0
  55. package/dist/src/utils/__tests__/platform-exec.test.d.ts +5 -0
  56. package/dist/src/utils/__tests__/platform-exec.test.js +212 -0
  57. package/dist/src/utils/__tests__/platform-shell.test.d.ts +5 -0
  58. package/dist/src/utils/__tests__/platform-shell.test.js +300 -0
  59. package/dist/src/utils/__tests__/platform.test.d.ts +5 -0
  60. package/dist/src/utils/__tests__/platform.test.js +137 -0
  61. package/dist/src/utils/platform.d.ts +88 -0
  62. package/dist/src/utils/platform.js +331 -0
  63. package/package.json +10 -2
  64. package/src/__integration__/command-generation.test.ts +602 -0
  65. package/src/__integration__/error-recovery.test.ts +620 -0
  66. package/src/__integration__/shell-hook-workflow.test.ts +457 -0
  67. package/src/__tests__/alias.test.ts +545 -0
  68. package/src/__tests__/chat-history.test.ts +462 -0
  69. package/src/__tests__/config.test.ts +1043 -0
  70. package/src/__tests__/history.test.ts +538 -0
  71. package/src/__tests__/remote-history.test.ts +791 -0
  72. package/src/__tests__/remote.test.ts +866 -0
  73. package/src/__tests__/shell-hook-install.test.ts +510 -0
  74. package/src/__tests__/shell-hook-remote.test.ts +679 -0
  75. package/src/__tests__/shell-hook.test.ts +564 -0
  76. package/src/__tests__/sysinfo.test.ts +718 -0
  77. package/src/__tests__/system-history.test.ts +608 -0
  78. package/src/components/Chat.tsx +10 -37
  79. package/src/config.ts +29 -2
  80. package/src/mastra-chat.ts +12 -5
  81. package/src/multi-step.ts +11 -5
  82. package/src/project-context.ts +191 -0
  83. package/src/prompts.ts +26 -5
  84. package/src/shell-hook.ts +254 -32
  85. package/src/sysinfo.ts +326 -25
  86. package/src/system-history.ts +170 -0
  87. package/src/ui/__tests__/theme.test.ts +869 -0
  88. package/src/upgrade.ts +5 -0
  89. package/src/user-preferences.ts +178 -0
  90. package/src/utils/__tests__/platform-capabilities.test.ts +265 -0
  91. package/src/utils/__tests__/platform-exec.test.ts +278 -0
  92. package/src/utils/__tests__/platform-shell.test.ts +353 -0
  93. package/src/utils/__tests__/platform.test.ts +170 -0
  94. package/src/utils/platform.ts +431 -0
package/README.md CHANGED
@@ -1,187 +1,181 @@
1
1
  # Pretty Please (pls)
2
2
 
3
- > 让 AI 把自然语言变成 Shell 命令
3
+ <p align="center">
4
+ <strong>"Pretty please?" — 用最礼貌的方式,让 AI 帮你干活</strong>
5
+ </p>
4
6
 
5
- 一个 AI 驱动的命令行工具,用自然语言描述你想做什么,AI 帮你生成并执行对应的 Shell 命令。
7
+ > `please 查看当前目录` 就像在跟电脑说话一样自然
6
8
 
7
- ## ✨ 特性
9
+ <p align="center">
10
+ <img src="https://github.com/user-attachments/assets/aeebcac4-ee52-4b9d-b2c9-77c2930e7454" alt="Pretty Please Demo" width="800">
11
+ </p>
8
12
 
9
- - 🤖 **自然语言转命令** - 用人话说你想干什么,AI 自动生成命令
10
- - 🔄 **多步骤命令** - AI 自动规划多个步骤,后续命令依赖前面的执行结果
11
- - 🛡️ **智能错误恢复** - 命令失败时 AI 自动分析并调整策略
12
- - ✏️ **命令编辑** - 执行前可编辑 AI 生成的命令,支持 manual/auto 两种模式
13
- - 💬 **AI 对话模式** - 随时问 AI 命令怎么用
14
- - 🌐 **远程执行** - 通过 SSH 在远程服务器执行命令,支持密码/密钥认证
15
- - 📜 **三种历史记录** - 命令历史、对话历史、Shell 历史统一管理
16
- - 🎨 **精美界面** - 基于 React + Ink 的终端 UI,Markdown 渲染
17
- - 🌗 **主题切换** - 支持 dark/light 主题,适配不同终端背景
18
- - 🏷️ **命令别名** - 常用操作一键触发,支持参数模板
19
- - 🔧 **多 Provider 支持** - 支持 OpenAI、DeepSeek、Anthropic 等多种 AI
20
- - 🚀 **一键升级** - 内置 `pls upgrade` 命令,自动更新到最新版本
13
+ ## 这是啥?
21
14
 
22
- ## 📦 安装
15
+ 忘了 Shell 命令怎么写?没关系,用人话告诉 `pls` 你想干嘛就行。
23
16
 
24
- ### 方式一:npm/pnpm 全局安装(推荐)
17
+ **pretty please** 是英语里"拜托了"的意思,而我们的命令就叫 `pls` / `please`,所以每次执行命令都像是在礼貌地请求:
25
18
 
26
19
  ```bash
27
- # 使用 npm
28
- npm install -g @yivan-lab/pretty-please
29
-
30
- # 或使用 pnpm
31
- pnpm add -g @yivan-lab/pretty-please
32
-
33
- # 或使用 yarn
34
- yarn global add @yivan-lab/pretty-please
20
+ please 帮我压缩这个文件夹
21
+ pls 找出占用 8080 端口的进程
22
+ pls 在服务器上重启 nginx
35
23
  ```
36
24
 
37
- 安装完成后,你可以在任何目录使用 `pls` `please` 命令了!
25
+ AI 生成命令 你确认 → 执行 → 搞定。
26
+
27
+ ## ✨ 命令打错了?直接 `pls` 就行
38
28
 
39
- ### 方式二:从源码安装
29
+ [thefuck](https://github.com/nvbn/thefuck) 一样,命令执行失败后,直接输入 `pls` 让 AI 自动修复:
40
30
 
41
31
  ```bash
42
- # 克隆项目
43
- git clone https://github.com/IvanLark/pretty-please.git
44
- cd pretty-please
32
+ python --version
33
+ zsh: command not found: python
45
34
 
46
- # 安装依赖
47
- pnpm install
35
+ ❯ pls # ← 就这么简单!
36
+ 生成命令: python3 --version
37
+ Python 3.9.6
38
+ ```
48
39
 
49
- # 构建
50
- pnpm build
40
+ ```bash
41
+ git pus origin main
42
+ git: 'pus' is not a git command. See 'git --help'.
51
43
 
52
- # 全局链接
53
- pnpm link --global
44
+ pls
45
+ 生成命令: git push origin main
46
+ Enumerating objects: 5, done.
47
+ ...
54
48
  ```
55
49
 
56
- 安装完成后,你可以在任何目录使用 `pls` 或 `please` 命令了!
50
+ 不用说"修复上一条命令",不用重新输入,**直接 `pls`,AI 自动检测失败的命令并生成正确版本**。
51
+
52
+ ## 为什么用这个?
57
53
 
58
- ### 方式三:一键安装(无需 Node.js)
54
+ - **命令打错了?** 直接 `pls` 自动修复,像 thefuck 一样方便,但更智能
55
+ - 记不住 `tar` 的一堆参数
56
+ - 想批量处理文件但懒得写脚本
57
+ - 想问问某个命令怎么用
59
58
 
60
- 适用于云服务器、DevOps 场景,无需 Node.js 环境:
59
+ ## 能干啥?
60
+
61
+ **核心特性:**
62
+ - **自动修复错误** - 命令失败后直接 `pls`,AI 自动检测并生成正确命令(像 thefuck,但更智能)
63
+ - **自然语言转命令** - 生成前让你确认或编辑
64
+ - **智能多步任务** - 复杂任务自动拆分,每步基于上一步的结果
65
+ - **错误恢复重试** - 命令失败了 AI 会分析原因并调整策略
66
+
67
+ **高级功能:**
68
+ - **学习你的习惯** - 开启 Shell Hook 后,AI 会记住你常用的命令,下次优先用你习惯的工具
69
+ - **远程执行** - 通过 SSH 在服务器上跑命令,支持批量(`-r server1,server2,server3`)
70
+ - **对话模式** - `pls chat grep 怎么用`,随时问问题
71
+ - **命令别名** - 把常用操作存成快捷方式
72
+ - **主题系统** - 7 个内置主题 + 自定义主题
73
+ - **自动升级** - `pls upgrade` 一键更新
74
+
75
+ ## 安装
76
+
77
+ 注意:目前 pls 在 windows 端可能会有不兼容导致的 bug,如果遇到可以发 issue 反馈,谢谢
78
+
79
+ **方式一:npm(推荐)**
61
80
 
62
- **Linux / macOS:**
63
81
  ```bash
64
- curl -fsSL https://raw.githubusercontent.com/IvanLark/pretty-please/main/install.sh | bash
82
+ npm i -g @yivan-lab/pretty-please
65
83
  ```
66
84
 
67
- **Windows (PowerShell):**
68
- ```powershell
85
+ **方式二:一键脚本(无需 Node.js)**
86
+
87
+ ```bash
88
+ # Linux / macOS
89
+ curl -fsSL https://raw.githubusercontent.com/IvanLark/pretty-please/main/install.sh | bash
90
+
91
+ # Linux / macOS(国内加速)
92
+ curl -fsSL https://gh-proxy.org/https://raw.githubusercontent.com/IvanLark/pretty-please/main/install.sh | bash
93
+
94
+ # Windows PowerShell
69
95
  irm https://raw.githubusercontent.com/IvanLark/pretty-please/main/install.ps1 | iex
70
- ```
71
96
 
72
- 支持的平台:
73
- - Linux x64 / arm64
74
- - macOS Intel / Apple Silicon
75
- - Windows x64
97
+ # Windows PowerShell(国内加速)
98
+ irm https://gh-proxy.org/https://raw.githubusercontent.com/IvanLark/pretty-please/main/install.ps1 | iex
99
+ ```
76
100
 
77
- ## 🚀 快速开始
101
+ 支持平台:Linux (x64/arm64) / macOS (Intel/Apple Silicon) / Windows x64
78
102
 
79
- ### 1. 配置 API
103
+ ## 快速开始
80
104
 
81
- 首次使用需要配置 AI API
105
+ **第一步:配置 API**
82
106
 
83
107
  ```bash
84
108
  pls config
85
109
  ```
86
110
 
87
- 会启动交互式配置向导,按提示输入:
88
- - **Provider**: openai / deepseek / anthropic 等(默认 openai)
89
- - **Base URL**: API 地址
90
- - **API Key**: 你的 API 密钥
91
- - **Model**: 模型名称(如 gpt-4-turbo / deepseek-chat)
92
- - **Shell Hook**: 是否启用Shell Hook(Shell Hook 可以记录你在终端执行的历史命令,让 AI 更智能地理解上下文,推荐启用)
111
+ 按提示输入你的 AI API 信息(支持 OpenAI、DeepSeek、Claude 等)
93
112
 
94
- ### 2. 开始使用
113
+ **第二步:开始用**
95
114
 
96
115
  ```bash
97
- # 生成并执行命令
98
116
  pls 查看当前目录
99
-
100
- # 复杂任务(多步骤)
101
- pls 查找大于100MB的日志文件并压缩
102
-
103
- # AI 对话模式
104
- pls chat grep 命令怎么用
117
+ pls 找出大于100MB的文件
118
+ pls chat grep 怎么用
105
119
  ```
106
120
 
107
- ## 📖 使用示例
121
+ ## 使用示例
108
122
 
109
- ### 单步命令
123
+ ### 基础用法
110
124
 
111
- 最基础的用法,用自然语言描述你想做什么:
125
+ 最简单的方式,直接说你想干啥:
112
126
 
113
127
  ```bash
114
128
  pls 查看当前目录
115
129
  pls 安装 git
116
- pls 查看当前 IP 地址
130
+ pls 找出占用 8080 端口的进程
117
131
  pls 删除所有 .DS_Store 文件
118
132
  ```
119
133
 
120
- AI 会生成对应的命令,你确认后执行。
134
+ AI 生成命令,你确认后执行。
121
135
 
122
- ### 多步骤命令
136
+ ### 多步骤任务
123
137
 
124
- 对于需要多个步骤的复杂任务,AI 会自动规划并逐步执行:
138
+ 复杂的任务 AI 会自动拆分,每步基于上一步的结果:
125
139
 
126
140
  ```bash
127
- pls 查找大于100MB的日志文件并压缩
141
+ pls 找出大于100MB的日志文件并压缩
128
142
  ```
129
143
 
130
- 执行过程:
131
- 1. **步骤 1**: AI 生成 `find . -name '*.log' -size +100M` 查找大文件
132
- 2. 你确认后执行,找到了 `app.log` 和 `system.log`
133
- 3. **步骤 2**: AI 根据上一步的输出,生成 `tar -czf logs.tar.gz app.log system.log` 压缩命令
134
- 4. 完成!
135
-
136
- 每步执行后,AI 会根据实际输出结果智能地决定下一步怎么做。
144
+ **执行流程:**
145
+ 1. 步骤 1:`find . -name '*.log' -size +100M` 找到了 `app.log` 和 `system.log`
146
+ 2. 步骤 2:根据上一步的结果,生成 `tar -czf logs.tar.gz app.log system.log`
147
+ 3. 完成!
137
148
 
138
- ### 智能引用历史
149
+ ### 引用历史
139
150
 
140
- AI 能记住你执行过的命令,支持引用之前的操作:
151
+ AI 记得你之前干了啥:
141
152
 
142
153
  ```bash
143
- # 第一步:创建文件
144
- pls 创建一个名为 test.txt 的文件
154
+ pls 创建一个 test.txt
155
+ pls 删除刚才的文件 # AI 知道你说的是 test.txt
145
156
 
146
- # 第二步:引用刚才的操作
147
- pls 删除刚才创建的文件
148
- # AI 会知道你说的是 test.txt
149
-
150
- # 或者手动执行了某个命令
157
+ # 或者
151
158
  mkdir my-project
152
159
  cd my-project
153
-
154
- # 然后让 AI 基于当前上下文工作
155
- pls 在这个目录初始化 git 仓库
160
+ pls 在这个目录初始化 git 仓库 # AI 知道当前上下文
156
161
  ```
157
162
 
158
- 支持的引用方式:
159
- - "刚才的文件"
160
- - "上一个命令"
161
- - "刚创建的目录"
162
- - AI 会自动从历史记录中提取相关信息
163
-
164
163
  ### 错误恢复
165
164
 
166
- 命令执行失败?AI 会自动分析并调整策略:
165
+ 命令失败了 AI 会分析并重试:
167
166
 
168
167
  ```bash
169
- pls test.zip 移动到 a、b、c 三个文件夹
168
+ pls test.zip 移动到 a、b、c 三个文件夹
170
169
  ```
171
170
 
172
- 执行过程:
173
- 1. **步骤 1**: `mv test.zip a/` ✓ 成功
174
- 2. **步骤 2**: `mv test.zip b/` ✗ 失败(文件已被移走)
175
- 3. AI 分析错误,调整策略
176
- 4. **步骤 3**: `cp a/test.zip b/ && cp a/test.zip c/` ✓ 改用复制
177
-
178
- AI 不会因为一次失败就放弃,而是理解错误原因并找到解决方案。
179
-
180
- ### 命令编辑
171
+ **执行过程:**
172
+ 1. `mv test.zip a/` ✓ 成功
173
+ 2. `mv test.zip b/` ✗ 失败(文件已被移走)
174
+ 3. AI 分析错误,改用复制:`cp a/test.zip b/ && cp a/test.zip c/` ✓ 成功
181
175
 
182
- AI 生成的命令可能不完全符合你的需求,你可以在执行前编辑它:
176
+ ### 编辑命令
183
177
 
184
- **manual 模式(默认)**:
178
+ 生成的命令不满意?按 `E` 编辑:
185
179
 
186
180
  ```
187
181
  ┌─ 生成命令 ───────┐
@@ -190,266 +184,76 @@ AI 生成的命令可能不完全符合你的需求,你可以在执行前编
190
184
 
191
185
  执行? [回车执行 / E 编辑 / Esc 取消]
192
186
 
193
- # 按 E 进入编辑
194
- ┌─ 生成命令 ───────┐
195
- │ ls -la │ ← AI 建议
196
- └──────────────────┘
197
- > ls -l█ ← 可编辑
187
+ # 按 E 后进入编辑
188
+ > ls -l█ ← 可以修改
198
189
 
199
190
  [回车执行 / Esc 返回]
200
191
  ```
201
192
 
202
- **auto 模式**:自动进入编辑,直接修改后执行
193
+ 或者用 `auto` 模式,自动进入编辑:
203
194
 
204
195
  ```bash
205
- # 切换到 auto 模式
206
196
  pls config set editMode auto
207
197
  ```
208
198
 
209
- 编辑后的命令会被记录到历史中,并标注修改前后的对比。
210
-
211
- ### 对话模式:命令讲解和问答
199
+ ### 对话模式
212
200
 
213
- 想了解某个命令怎么用?用 `pls chat` 开启对话模式:
201
+ 想问问命令怎么用:
214
202
 
215
203
  ```bash
216
- # 询问命令用法
217
204
  pls chat tar 命令怎么用
218
-
219
- # 解释刚才执行的命令
220
- pls 找到所有 node_modules 目录并计算大小
221
- pls chat 刚才那个命令是干嘛的?
222
- # AI 会详细解释刚才生成的命令的含义和参数
223
-
224
- # 提问题
225
- pls chat 如何批量重命名文件
226
205
  pls chat grep 和 awk 有什么区别
227
- pls chat 如何在 Linux 下挂载硬盘
228
-
229
- # 清空对话历史
230
- pls chat clear
206
+ pls chat 刚才那个命令是干嘛的? # 会解释你最近执行的命令
231
207
  ```
232
208
 
233
- `pls chat` 的特点:
234
- - 📖 **命令讲解** - 解释命令的含义、参数、用法
235
- - 💡 **问题解答** - 回答 Shell、Linux、命令行相关问题
236
- - 🎯 **上下文感知** - 能引用你刚才执行的命令
237
- - 📝 **Markdown 渲染** - 支持代码高亮、表格、列表等精美格式
238
- - 💬 **连续对话** - 保留历史,可以追问和深入讨论
209
+ ### 远程执行
239
210
 
240
- ### 查看历史记录
211
+ 在服务器上跑命令:
241
212
 
242
213
  ```bash
243
- # 查看命令历史
244
- pls history
245
-
246
- # 查看对话历史
247
- pls history chat
248
-
249
- # 查看 Shell 历史(需要启用 Shell Hook)
250
- pls history shell
251
-
252
- # 清空各种历史
253
- pls history clear # 清空命令历史
254
- pls history chat clear # 清空对话历史
255
- pls history shell clear # 清空 Shell 历史
256
- ```
257
-
258
- 历史记录包含:
259
- - 你的原始需求(自然语言)
260
- - AI 生成的命令
261
- - 用户修改后的命令(如有修改)
262
- - 执行状态(成功/失败/退出码)
263
- - 执行时间
264
-
265
- ## ⚙️ 配置管理
266
-
267
- ```bash
268
- pls config # 交互式配置向导
269
- pls config list # 查看当前配置
270
- pls config show # 同上
271
- pls config set <key> <value> # 设置单个配置项
272
- ```
273
-
274
- ### 配置项说明
275
-
276
- | 配置项 | 说明 | 默认值 |
277
- |--------|------|--------|
278
- | `apiKey` | AI API 密钥 | - |
279
- | `baseUrl` | API 基础 URL | `https://api.openai.com/v1` |
280
- | `provider` | AI Provider | `openai` |
281
- | `model` | 模型名称 | `gpt-4-turbo` |
282
- | `shellHook` | 启用终端历史记录 | `false` |
283
- | `editMode` | 命令编辑模式(manual/auto) | `manual` |
284
- | `chatHistoryLimit` | 对话历史保留轮数 | `10` |
285
- | `commandHistoryLimit` | 命令历史保留条数 | `10` |
286
- | `shellHistoryLimit` | Shell 历史保留条数 | `15` |
287
- | `theme` | 界面主题(dark/light) | `dark` |
288
- | `aliases` | 命令别名配置 | `{}` |
289
-
290
- ### 支持的 Provider
291
-
292
- - `openai` - OpenAI GPT 系列
293
- - `deepseek` - DeepSeek
294
- - `anthropic` - Claude
295
- - `google` - Gemini
296
- - `groq` - Groq
297
- - `mistral` - Mistral AI
298
- - `cohere` - Cohere
299
- - `fireworks` - Fireworks AI
300
- - `together` - Together AI
301
-
302
- ## 🌐 远程执行
303
-
304
- 通过 SSH 在远程服务器上执行 AI 生成的命令,支持密码/密钥认证。
305
-
306
- ### 添加远程服务器
307
-
308
- ```bash
309
- # 使用默认密钥(~/.ssh/id_rsa)
214
+ # 添加服务器
310
215
  pls remote add myserver root@192.168.1.100
311
216
 
312
- # 指定端口
313
- pls remote add myserver root@192.168.1.100:2222
314
-
315
- # 使用指定密钥
316
- pls remote add myserver root@192.168.1.100 --key ~/.ssh/my_key
317
-
318
- # 使用密码认证(每次执行时输入密码)
319
- pls remote add myserver root@192.168.1.100 --password
320
- ```
321
-
322
- ### 管理远程服务器
323
-
324
- ```bash
325
- pls remote # 查看所有服务器
326
- pls remote list # 同上
327
- pls remote test myserver # 测试连接并采集系统信息
328
- pls remote remove myserver # 删除服务器
329
- ```
330
-
331
- ### 设置默认服务器
332
-
333
- ```bash
334
- pls remote default myserver # 设置默认服务器
335
- pls remote default # 查看当前默认服务器
336
- pls remote default --clear # 清除默认服务器
337
- ```
338
-
339
- 设置默认服务器后,使用 `-r` 参数时可以省略服务器名:
340
-
341
- ```bash
342
- pls -r 查看磁盘使用情况 # 使用默认服务器
343
- ```
344
-
345
- ### 设置工作目录
346
-
347
- ```bash
348
- pls remote workdir myserver /var/www # 设置工作目录
349
- pls remote workdir myserver # 查看当前工作目录
350
- pls remote workdir myserver --clear # 清除工作目录
351
- ```
352
-
353
- 设置工作目录后,所有命令会自动在该目录下执行。
354
-
355
- ### 远程执行命令
356
-
357
- ```bash
358
- # 指定服务器执行
217
+ # 远程执行
359
218
  pls -r myserver 查看磁盘使用情况
360
- pls -r myserver 查找大于 100MB 的日志文件
361
-
362
- # 使用默认服务器(需先设置)
363
- pls -r 查看当前目录的文件
364
- ```
365
-
366
- ### 批量远程执行 ⭐
367
-
368
- 在多台服务器上并发执行同一个任务,每个服务器自动生成适配其环境的命令:
219
+ pls -r myserver 重启 nginx
369
220
 
370
- ```bash
371
- # 批量执行(逗号分隔服务器名)
221
+ # 批量执行(在多台服务器上同时跑)
372
222
  pls -r web1,web2,web3 查看 nginx 状态
373
- pls -r server1,server2 查看磁盘使用情况
374
- pls -r prod1,prod2,prod3 重启应用服务
375
223
  ```
376
224
 
377
- **特点:**
378
- - 🚀 **并发执行** - 所有服务器同时生成命令和执行,速度快
379
- - 🔧 **自动适配** - 每个服务器根据其系统环境生成独立命令(支持异构环境)
380
- - 📊 **清晰展示** - 显示每个服务器的命令和执行结果
381
- - 📝 **历史记录** - 自动记录到每个服务器的历史
225
+ ### 命令别名
382
226
 
383
- **执行流程示例:**
227
+ 把常用操作存成快捷方式:
384
228
 
385
229
  ```bash
386
- $ pls -r web1,web2,web3 查看 nginx 状态
387
-
388
- 正在为 3 台服务器生成命令...
389
-
390
- ✓ 命令生成完成
391
-
392
- web1 (linux):
393
- systemctl status nginx | grep Active
394
-
395
- web2 (linux):
396
- systemctl status nginx | grep Active
397
-
398
- web3 (linux):
399
- systemctl status nginx | grep Active
400
-
401
- 将在 3 台服务器执行以上命令
402
- 执行? [回车执行 / Ctrl+C 取消]
403
-
404
- 正在执行...
405
-
406
- 执行完成:
407
-
408
- ✓ web1 (退出码: 0)
409
- ✓ web2 (退出码: 0)
410
- ✗ web3 (退出码: 3)
411
-
412
- ─── web1 ───
413
- Active: active (running)
230
+ # 添加别名
231
+ pls alias add disk "查看磁盘使用情况,按使用率排序"
414
232
 
415
- ─── web2 ───
416
- Active: active (running)
233
+ # 使用
234
+ pls disk
417
235
 
418
- ─── web3 ───
419
- Active: inactive (dead)
236
+ # 带参数的别名
237
+ pls alias add taillog "查看 {{file}} 的最后 {{lines:20}} 行"
238
+ pls taillog --file=/var/log/system.log --lines=50
420
239
  ```
421
240
 
422
- **退出码:**
423
- - `0` - 全部成功
424
- - `1` - 部分失败
425
- - `2` - 全部失败
426
-
427
- **限制:**
428
- - 批量执行模式不支持多步骤命令(只生成单个命令)
429
- - 不支持命令编辑(直接执行生成的命令)
241
+ ## 更多功能
430
242
 
431
- ### 远程 Shell Hook
432
-
433
- 在远程服务器上安装 Shell Hook,让 AI 了解你在远程服务器上的操作历史:
243
+ ### 历史记录
434
244
 
435
245
  ```bash
436
- pls remote hook install myserver # 安装远程 Hook
437
- pls remote hook status myserver # 查看状态
438
- pls remote hook uninstall myserver # 卸载 Hook
439
- ```
440
-
441
- ### 远程历史记录
246
+ pls history # 命令历史
247
+ pls history chat # 对话历史
248
+ pls history shell # Shell 历史(需要启用 Shell Hook
442
249
 
443
- ```bash
444
- pls remote history show myserver # 查看远程命令历史
445
- pls remote history clear myserver # 清空远程命令历史
446
- pls remote history shell myserver # 查看远程 Shell 历史
447
- pls remote history shell-clear myserver # 清空远程 Shell 历史
250
+ pls history clear # 清空命令历史
251
+ pls history chat clear # 清空对话历史
448
252
  ```
449
253
 
450
- ## 🔧 Shell Hook(可选)
254
+ ### Shell Hook
451
255
 
452
- Shell Hook 可以记录你在终端执行的所有命令,让 AI 更智能地理解上下文。
256
+ 记录你在终端执行的所有命令,让 AI 更了解上下文:
453
257
 
454
258
  ```bash
455
259
  pls hook install # 安装 hook
@@ -457,381 +261,207 @@ pls hook status # 查看状态
457
261
  pls hook uninstall # 卸载 hook
458
262
  ```
459
263
 
460
- 支持的 Shell:
461
- - zsh
462
- - bash
463
- - PowerShell
464
-
465
- ## 🌗 主题系统
466
-
467
- 支持多种内置主题和自定义主题,适配不同终端背景和个人喜好:
264
+ 支持 zsh / bash / PowerShell。
468
265
 
469
- ### 内置主题
266
+ **开了 Hook 后,pls 会学习你的命令习惯。** 比如你平时用 `eza` 而不是 `ls`,用 `bat` 而不是 `cat`,AI 生成命令时会优先用你习惯的工具。用得越多,AI 越懂你。
470
267
 
471
268
  ```bash
472
- pls theme # 查看当前主题
473
- pls theme list # 查看所有可用主题
474
- pls theme dark # 切换到深色主题
475
- pls theme nord # 切换到 Nord 主题
269
+ pls prefs # 看看 AI 学到了什么
270
+ pls prefs clear # 清空偏好统计
476
271
  ```
477
272
 
478
- **可用的内置主题:**
479
- - **dark(深色)** - 明亮的颜色,适合深色终端背景(默认)
480
- - **light(浅色)** - 较深的颜色,适合浅色终端背景
481
- - **nord(北欧冷色)** - 冷色调护眼主题,适合长时间使用
482
- - **dracula(德古拉暗色)** - 高对比暗色主题,色彩丰富但不刺眼
483
- - **retro(复古终端绿)** - 经典终端荧光绿,致敬老派 hacker 风格
484
- - **contrast(高对比度)** - 极高对比度,适合视力辅助和强光环境
485
- - **monokai(经典编辑器)** - Monokai 经典配色,开发者熟悉的选择
273
+ ### 系统信息
486
274
 
487
- 也可以通过配置命令切换:
275
+ 查看当前系统信息(AI 生成命令时会参考这些):
488
276
 
489
277
  ```bash
490
- pls config set theme nord
278
+ pls sysinfo # 查看系统信息
279
+ pls sysinfo refresh # 刷新缓存
491
280
  ```
492
281
 
493
- ### 自定义主题
494
-
495
- 创建你自己的主题配色方案:
282
+ ### 主题
496
283
 
497
- #### 1. 创建主题模板
284
+ 7 个内置主题 + 自定义主题:
498
285
 
499
286
  ```bash
500
- # 创建深色主题
501
- pls theme create my-ocean --display-name "我的海洋主题"
502
-
503
- # 创建浅色主题
504
- pls theme create my-light --display-name "我的浅色" --category light
287
+ pls theme # 查看当前主题
288
+ pls theme list # 查看所有主题
289
+ pls theme nord # 切换主题
505
290
  ```
506
291
 
507
- 这会在 `~/.please/themes/` 目录下生成一个 JSON 模板文件。
508
-
509
- #### 2. 编辑主题文件
292
+ **内置主题:** dark、light、nord、dracula、retro、contrast、monokai
510
293
 
511
- ```bash
512
- vim ~/.please/themes/my-ocean.json
513
- ```
514
-
515
- 主题文件格式:
516
-
517
- ```json
518
- {
519
- "metadata": {
520
- "name": "my-ocean",
521
- "displayName": "我的海洋主题",
522
- "description": "深邃的海洋蓝配色",
523
- "category": "dark",
524
- "author": "Your Name"
525
- },
526
- "colors": {
527
- "primary": "#0077BE",
528
- "secondary": "#5DADE2",
529
- "accent": "#48C9B0",
530
- "success": "#2ECC71",
531
- "error": "#E74C3C",
532
- "warning": "#F39C12",
533
- "info": "#3498DB",
534
- "text": {
535
- "primary": "#ECF0F1",
536
- "secondary": "#BDC3C7",
537
- "muted": "#95A5A6",
538
- "dim": "#7F8C8D"
539
- },
540
- "border": "#34495E",
541
- "divider": "#2C3E50",
542
- "code": {
543
- "background": "#1C2833",
544
- "text": "#ECF0F1",
545
- "keyword": "#C678DD",
546
- "string": "#98C379",
547
- "function": "#61AFEF",
548
- "comment": "#5C6370"
549
- }
550
- }
551
- }
552
- ```
553
-
554
- #### 3. 验证主题
294
+ **自定义主题:**
555
295
 
556
296
  ```bash
557
- pls theme validate ~/.please/themes/my-ocean.json
297
+ pls theme create my-theme --display-name "我的主题"
298
+ vim ~/.please/themes/my-theme.json # 编辑主题配置
299
+ pls theme validate ~/.please/themes/my-theme.json # 验证
300
+ pls theme my-theme # 应用
558
301
  ```
559
302
 
560
- 验证通过后会显示主题信息,失败会给出详细的错误提示。
303
+ ### 远程执行详细说明
561
304
 
562
- #### 4. 应用自定义主题
305
+ **添加服务器:**
563
306
 
564
307
  ```bash
565
- pls theme my-ocean
308
+ pls remote add myserver root@192.168.1.100
309
+ pls remote add myserver root@192.168.1.100 --key ~/.ssh/my_key
310
+ pls remote add myserver root@192.168.1.100 --password # 密码认证
566
311
  ```
567
312
 
568
- #### 5. 管理自定义主题
313
+ **管理服务器:**
569
314
 
570
315
  ```bash
571
- # 查看所有主题(内置 + 自定义)
572
- pls theme list
573
-
574
- # 只查看自定义主题
575
- pls theme list --custom
576
-
577
- # 只查看内置主题
578
- pls theme list --builtin
316
+ pls remote # 查看所有服务器
317
+ pls remote test myserver # 测试连接
318
+ pls remote remove myserver # 删除
319
+ pls remote default myserver # 设置默认服务器
320
+ pls remote workdir myserver /var/www # 设置工作目录
579
321
  ```
580
322
 
581
- 自定义主题在列表中会显示 ✨ 标记。
582
-
583
- **主题文件位置:** `~/.please/themes/`
584
-
585
- **颜色格式:** 所有颜色必须使用十六进制格式(如 `#00D9FF`)
586
-
587
- ## 🏷️ 命令别名
588
-
589
- 将常用的操作保存为别名,一键触发:
590
-
591
- ### 基本使用
323
+ **远程执行:**
592
324
 
593
325
  ```bash
594
- # 添加简单别名
595
- pls alias add disk "查看磁盘使用情况,按使用率排序"
596
- pls alias add mem "查看内存使用最高的 10 个进程"
597
-
598
- # 使用别名(两种格式都支持)
599
- pls disk
600
- pls @disk
601
-
602
- # 查看所有别名
603
- pls alias
604
- pls alias list
326
+ pls -r myserver 查看磁盘使用情况
327
+ pls -r 查看当前目录 # 使用默认服务器
605
328
 
606
- # 删除别名
607
- pls alias remove disk
329
+ # 批量执行
330
+ pls -r web1,web2,web3 重启 nginx
608
331
  ```
609
332
 
610
- ### 参数模板
333
+ 批量执行会为每个服务器生成适配其环境的命令,并发执行。
611
334
 
612
- 支持动态参数,让别名更灵活:
335
+ **远程历史:**
613
336
 
614
337
  ```bash
615
- # 添加带参数的别名
616
- pls alias add taillog "查看 {{file}} 的最后 {{lines:20}} 行日志"
617
-
618
- # 使用时传参
619
- pls taillog --file=/var/log/system.log # lines 使用默认值 20
620
- pls taillog --file=/var/log/system.log --lines=50 # 自定义 lines
621
- pls taillog file=/var/log/nginx.log lines=100 # 不带 -- 也可以
338
+ pls remote history show myserver # 查看
339
+ pls remote history clear myserver # 清空
340
+ pls remote hook install myserver # 安装远程 Hook
622
341
  ```
623
342
 
624
- 参数格式说明:
625
- - `{{param}}` - 必填参数,不提供会报错
626
- - `{{param:default}}` - 可选参数,有默认值
343
+ ### 配置
627
344
 
628
- ### 别名 + 额外描述
629
-
630
- 别名后可以追加额外的描述:
345
+ 查看和修改配置:
631
346
 
632
347
  ```bash
633
- pls disk 显示详情 # 等同于 pls 查看磁盘使用情况,按使用率排序 显示详情
348
+ pls config # 交互式配置
349
+ pls config list # 查看配置
350
+ pls config set <key> <value> # 修改单项
634
351
  ```
635
352
 
636
- ## 🚀 版本升级
637
-
638
- ### 自动更新提示
639
-
640
- 程序会每 24 小时检查一次新版本,发现更新时在命令结束后提示:
353
+ 主要配置项:
354
+ - `apiKey` / `baseUrl` / `provider` / `model` - AI API 配置
355
+ - `editMode` - 命令编辑模式(manual / auto)
356
+ - `theme` - 界面主题
357
+ - `shellHook` - 是否启用 Shell Hook
358
+ - `chatHistoryLimit` / `commandHistoryLimit` - 历史条数限制
641
359
 
642
- ```
643
- ⚠ 发现新版本: 1.1.0 → 1.2.0,运行 pls upgrade 更新
644
- ```
360
+ 支持的 Provider:openai、deepseek、anthropic、google、groq、mistral、cohere、fireworks、together
645
361
 
646
- ### 升级命令
362
+ ### 升级
647
363
 
648
364
  ```bash
649
- # 升级到最新版本
650
- pls upgrade
365
+ pls upgrade # 升级到最新版本
651
366
  ```
652
367
 
653
- 升级方式:
654
- - **二进制安装**(curl/irm):自动下载并替换
655
- - **npm 安装**:提示使用 `npm update -g @yivan-lab/pretty-please`
656
-
657
- ## 🎯 命令参考
368
+ 程序每 24 小时自动检查更新,发现新版本会提示。
658
369
 
659
- ### 基础命令
370
+ ## 命令速查
660
371
 
661
372
  ```bash
662
- pls <自然语言描述> # 生成并执行命令
663
- pls -d <描述> # Debug 模式(显示完整提示词)
664
- pls --debug <描述> # 同上
665
- pls -v # 查看版本
666
- pls -h # 查看帮助
667
- ```
668
-
669
- ### 子命令
373
+ # 基础
374
+ pls <需求> # 生成并执行命令
375
+ pls -d <需求> # Debug 模式
376
+ pls -v # 查看版本
670
377
 
671
- ```bash
672
378
  # 配置
673
- pls config
674
- pls config list
675
- pls config set <key> <value>
379
+ pls config # 交互式配置
380
+ pls config list # 查看配置
381
+ pls config set <key> <val> # 修改配置
676
382
 
677
383
  # 历史
678
- pls history # 命令历史
679
- pls history clear # 清空命令历史
680
- pls history chat # 对话历史
681
- pls history chat clear # 清空对话历史
682
- pls history shell # Shell 历史
683
- pls history shell clear # 清空 Shell 历史
384
+ pls history # 命令历史
385
+ pls history chat # 对话历史
386
+ pls history shell # Shell 历史
387
+ pls history clear # 清空历史
684
388
 
685
389
  # 对话
686
- pls chat <问题>
687
- pls chat clear
390
+ pls chat <问题> # 问问题
391
+ pls history chat clear # 清空对话
688
392
 
689
- # Shell Hook
690
- pls hook
691
- pls hook install
692
- pls hook uninstall
693
- pls hook status
393
+ # Hook
394
+ pls hook install # 安装
395
+ pls hook status # 状态
396
+ pls hook uninstall # 卸载
694
397
 
695
- # 主题
696
- pls theme # 查看当前主题
697
- pls theme list # 查看所有主题
698
- pls theme <name> # 切换主题(dark/light/nord/dracula/retro/contrast/monokai)
398
+ # 偏好 & 系统
399
+ pls prefs # 查看命令偏好
400
+ pls sysinfo # 查看系统信息
699
401
 
700
- # 自定义主题
701
- pls theme create <name> --display-name "名称" # 创建主题模板
702
- pls theme validate <file> # 验证主题文件
703
- pls theme list --custom # 只显示自定义主题
704
- pls theme list --builtin # 只显示内置主题
402
+ # 主题
403
+ pls theme # 当前主题
404
+ pls theme list # 所有主题
405
+ pls theme <name> # 切换
705
406
 
706
407
  # 别名
707
- pls alias # 查看所有别名
708
- pls alias list # 同上
709
- pls alias add <name> "<prompt>" # 添加别名
710
- pls alias remove <name> # 删除别名
408
+ pls alias # 查看
409
+ pls alias add <name> "<prompt>" # 添加
410
+ pls alias remove <name> # 删除
711
411
 
712
- # 升级
713
- pls upgrade # 升级到最新版本
714
- ```
715
-
716
- ## 🏗️ 技术架构
717
-
718
- ### 核心技术栈
719
-
720
- - **React 19 + Ink 6** - 终端 UI 组件化框架
721
- - **Mastra 0.24** - AI Agent 框架,支持 Structured Output
722
- - **TypeScript 5.9** - 100% TypeScript,完整类型安全
723
- - **Zod 3.25** - Schema 验证
724
- - **Commander 14** - CLI 参数解析
725
-
726
- ## 📁 目录结构
727
-
728
- ```
729
- pretty-please/
730
- ├── bin/
731
- │ └── pls.tsx # 主入口
732
- ├── src/
733
- │ ├── prompts.ts # 统一 AI 提示词管理
734
- │ ├── mastra-agent.ts # Mastra Agent(命令生成)
735
- │ ├── mastra-chat.ts # Mastra Chat Agent(对话模式)
736
- │ ├── multi-step.ts # 多步骤命令核心
737
- │ ├── config.ts # 配置管理
738
- │ ├── history.ts # 命令历史
739
- │ ├── chat-history.ts # 对话历史
740
- │ ├── shell-hook.ts # Shell 集成
741
- │ ├── builtin-detector.ts # Shell builtin 检测
742
- │ ├── sysinfo.ts # 系统信息采集
743
- │ ├── upgrade.ts # 版本升级模块
744
- │ ├── alias.ts # 命令别名管理
745
- │ ├── components/ # React Ink 组件
746
- │ │ ├── MultiStepCommandGenerator.tsx
747
- │ │ ├── Chat.tsx
748
- │ │ ├── MarkdownDisplay.tsx
749
- │ │ └── ...
750
- │ ├── ui/
751
- │ │ └── theme.ts # 主题系统
752
- │ └── utils/
753
- │ └── console.ts # 原生输出工具
754
- ├── package.json
755
- └── tsconfig.json
756
- ```
757
-
758
- ## 🔨 开发指南
759
-
760
- ### 命令版本
761
-
762
- | 命令 | 类型 | 说明 |
763
- |------|------|------|
764
- | `pls` / `please` | 生产版本 | 编译后的 JS |
765
- | `pls-dev` | 开发版本 | 热重载,代码修改立即生效 |
766
-
767
- ### 首次设置
412
+ # 远程
413
+ pls remote add <name> <user@host> # 添加服务器
414
+ pls remote list # 查看
415
+ pls -r <name> <需求> # 远程执行
416
+ pls -r <n1,n2,n3> <需求> # 批量执行
768
417
 
769
- ```bash
770
- # 1. 安装依赖
771
- pnpm install
772
-
773
- # 2. 构建并链接生产版本
774
- pnpm build
775
- pnpm link --global
776
-
777
- # 3. 创建开发版本链接(需要全局安装 tsx)
778
- pnpm add -g tsx
779
- pnpm link:dev
418
+ # 升级
419
+ pls upgrade # 升级到最新版本
780
420
  ```
781
421
 
782
- ### 开发模式
422
+ ## 技术栈
783
423
 
784
- ```bash
785
- # 使用开发命令(推荐,热重载)
786
- pls-dev <命令>
787
-
788
- # 或使用 dev 脚本
789
- pnpm dev <参数>
790
- ```
424
+ - **React + Ink** - 终端 UI 组件化
425
+ - **Mastra** - AI Agent 框架
426
+ - **TypeScript** - 100% 类型安全
427
+ - **Commander** - CLI 参数解析
791
428
 
792
- 代码修改会立即生效,无需重新编译。
793
-
794
- ### 构建和发布
429
+ ## 开发
795
430
 
796
431
  ```bash
797
- # 构建
432
+ git clone https://github.com/IvanLark/pretty-please.git
433
+ cd pretty-please
434
+ pnpm install
798
435
  pnpm build
799
-
800
- # 发布到 npm(会自动先执行 build)
801
- npm publish
436
+ pnpm link --global
802
437
  ```
803
438
 
804
- ### 目录说明
805
-
806
- - 配置文件:`~/.please/config.json`
807
- - 命令历史:`~/.please/history.json`
808
- - 对话历史:`~/.please/chat_history.json`
809
- - Shell 历史:`~/.please/shell_history.jsonl`
439
+ 开发模式(热重载):
810
440
 
811
- ## 🐛 常见问题
812
-
813
- ### 为什么 Chat 会清空终端历史?
441
+ ```bash
442
+ pnpm add -g tsx
443
+ pnpm link:dev
444
+ pls-dev <命令> # 代码修改立即生效
445
+ ```
814
446
 
815
- 这是 Ink 的设计局限。我们采用了混合渲染模式,命令执行使用原生输出来保留历史,只有 Chat 模式会清空。
447
+ ## 常见问题
816
448
 
817
- ### AI 返回的命令格式不对?
449
+ **为什么 Chat 会清空终端历史?**
818
450
 
819
- 如果遇到 AI 不遵守格式的情况,可以:
820
- 1. 使用 `--debug` 查看完整提示词
821
- 2. 检查 provider 和 model 配置是否正确
822
- 3. 某些模型需要 `jsonPromptInjection`(代码已自动处理)
451
+ 这是 Ink 的设计局限。命令执行使用原生输出保留历史,只有 Chat 模式会清空。
823
452
 
824
- ### 为什么要用 Zod 3.x?
453
+ **支持哪些 AI?**
825
454
 
826
- AI SDK Mastra 依赖 Zod 3.23.8+,Zod 4.x 有 breaking changes 不兼容。
455
+ 支持 OpenAI、DeepSeek、Claude、Gemini、Groq、Mistral、Cohere 等,只要兼容 OpenAI API 格式就行。
827
456
 
828
- ## 📄 许可证
457
+ ## 许可证
829
458
 
830
459
  MIT
831
460
 
832
- ## 🙏 致谢
461
+ ## 致谢
833
462
 
834
- - [fuckit.sh](https://github.com/faithleysath/fuckit.sh) - 提供了最初的灵感和思路,一个优雅的 AI 命令行工具
463
+ - [thefuck](https://github.com/nvbn/thefuck) - 启发了自动修复功能,一个超火的命令纠错工具
464
+ - [fuckit.sh](https://github.com/faithleysath/fuckit.sh) - 提供了灵感,一个优雅的 AI 命令行工具
835
465
  - [Ink](https://github.com/vadimdemedes/ink) - 终端 React 渲染器
836
466
  - [Mastra](https://mastra.ai) - AI Agent 框架
837
467