@yivan-lab/pretty-please 1.4.0 → 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.
- package/README.md +30 -2
- package/bin/pls.tsx +153 -35
- package/dist/bin/pls.js +126 -23
- package/dist/package.json +10 -2
- package/dist/src/__integration__/command-generation.test.d.ts +5 -0
- package/dist/src/__integration__/command-generation.test.js +508 -0
- package/dist/src/__integration__/error-recovery.test.d.ts +5 -0
- package/dist/src/__integration__/error-recovery.test.js +511 -0
- package/dist/src/__integration__/shell-hook-workflow.test.d.ts +5 -0
- package/dist/src/__integration__/shell-hook-workflow.test.js +375 -0
- package/dist/src/__tests__/alias.test.d.ts +5 -0
- package/dist/src/__tests__/alias.test.js +421 -0
- package/dist/src/__tests__/chat-history.test.d.ts +5 -0
- package/dist/src/__tests__/chat-history.test.js +372 -0
- package/dist/src/__tests__/config.test.d.ts +5 -0
- package/dist/src/__tests__/config.test.js +822 -0
- package/dist/src/__tests__/history.test.d.ts +5 -0
- package/dist/src/__tests__/history.test.js +439 -0
- package/dist/src/__tests__/remote-history.test.d.ts +5 -0
- package/dist/src/__tests__/remote-history.test.js +641 -0
- package/dist/src/__tests__/remote.test.d.ts +5 -0
- package/dist/src/__tests__/remote.test.js +689 -0
- package/dist/src/__tests__/shell-hook-install.test.d.ts +5 -0
- package/dist/src/__tests__/shell-hook-install.test.js +413 -0
- package/dist/src/__tests__/shell-hook-remote.test.d.ts +5 -0
- package/dist/src/__tests__/shell-hook-remote.test.js +507 -0
- package/dist/src/__tests__/shell-hook.test.d.ts +5 -0
- package/dist/src/__tests__/shell-hook.test.js +440 -0
- package/dist/src/__tests__/sysinfo.test.d.ts +5 -0
- package/dist/src/__tests__/sysinfo.test.js +572 -0
- package/dist/src/__tests__/system-history.test.d.ts +5 -0
- package/dist/src/__tests__/system-history.test.js +457 -0
- package/dist/src/components/Chat.js +9 -28
- package/dist/src/config.d.ts +2 -0
- package/dist/src/config.js +30 -2
- package/dist/src/mastra-chat.js +6 -3
- package/dist/src/multi-step.js +6 -3
- package/dist/src/project-context.d.ts +22 -0
- package/dist/src/project-context.js +168 -0
- package/dist/src/prompts.d.ts +4 -4
- package/dist/src/prompts.js +23 -6
- package/dist/src/shell-hook.d.ts +13 -0
- package/dist/src/shell-hook.js +163 -33
- package/dist/src/sysinfo.d.ts +38 -9
- package/dist/src/sysinfo.js +245 -21
- package/dist/src/system-history.d.ts +5 -0
- package/dist/src/system-history.js +64 -18
- package/dist/src/ui/__tests__/theme.test.d.ts +5 -0
- package/dist/src/ui/__tests__/theme.test.js +688 -0
- package/dist/src/upgrade.js +3 -0
- package/dist/src/user-preferences.d.ts +44 -0
- package/dist/src/user-preferences.js +147 -0
- package/dist/src/utils/__tests__/platform-capabilities.test.d.ts +5 -0
- package/dist/src/utils/__tests__/platform-capabilities.test.js +214 -0
- package/dist/src/utils/__tests__/platform-exec.test.d.ts +5 -0
- package/dist/src/utils/__tests__/platform-exec.test.js +212 -0
- package/dist/src/utils/__tests__/platform-shell.test.d.ts +5 -0
- package/dist/src/utils/__tests__/platform-shell.test.js +300 -0
- package/dist/src/utils/__tests__/platform.test.d.ts +5 -0
- package/dist/src/utils/__tests__/platform.test.js +137 -0
- package/dist/src/utils/platform.d.ts +88 -0
- package/dist/src/utils/platform.js +331 -0
- package/package.json +10 -2
- package/src/__integration__/command-generation.test.ts +602 -0
- package/src/__integration__/error-recovery.test.ts +620 -0
- package/src/__integration__/shell-hook-workflow.test.ts +457 -0
- package/src/__tests__/alias.test.ts +545 -0
- package/src/__tests__/chat-history.test.ts +462 -0
- package/src/__tests__/config.test.ts +1043 -0
- package/src/__tests__/history.test.ts +538 -0
- package/src/__tests__/remote-history.test.ts +791 -0
- package/src/__tests__/remote.test.ts +866 -0
- package/src/__tests__/shell-hook-install.test.ts +510 -0
- package/src/__tests__/shell-hook-remote.test.ts +679 -0
- package/src/__tests__/shell-hook.test.ts +564 -0
- package/src/__tests__/sysinfo.test.ts +718 -0
- package/src/__tests__/system-history.test.ts +608 -0
- package/src/components/Chat.tsx +10 -37
- package/src/config.ts +29 -2
- package/src/mastra-chat.ts +8 -3
- package/src/multi-step.ts +7 -2
- package/src/project-context.ts +191 -0
- package/src/prompts.ts +26 -5
- package/src/shell-hook.ts +179 -33
- package/src/sysinfo.ts +326 -25
- package/src/system-history.ts +67 -14
- package/src/ui/__tests__/theme.test.ts +869 -0
- package/src/upgrade.ts +5 -0
- package/src/user-preferences.ts +178 -0
- package/src/utils/__tests__/platform-capabilities.test.ts +265 -0
- package/src/utils/__tests__/platform-exec.test.ts +278 -0
- package/src/utils/__tests__/platform-shell.test.ts +353 -0
- package/src/utils/__tests__/platform.test.ts +170 -0
- package/src/utils/platform.ts +431 -0
|
@@ -1,32 +1,43 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import os from 'os';
|
|
4
2
|
import { getConfig } from './config.js';
|
|
3
|
+
import { detectShell, getShellCapabilities } from './utils/platform.js';
|
|
5
4
|
/**
|
|
6
5
|
* 直接读取系统 shell 历史文件(类似 thefuck)
|
|
7
6
|
* 用于没有安装 shell hook 的情况
|
|
8
7
|
*
|
|
9
8
|
* 限制:系统历史文件不记录退出码,所以 exit 字段都是 0
|
|
9
|
+
*
|
|
10
|
+
* 支持的 Shell:
|
|
11
|
+
* - Unix: zsh, bash, fish
|
|
12
|
+
* - Windows: PowerShell 5.x, PowerShell 7+ (通过 PSReadLine)
|
|
13
|
+
* - 不支持: CMD (无持久化历史)
|
|
10
14
|
*/
|
|
11
15
|
export function getSystemShellHistory() {
|
|
12
|
-
const shell =
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (shell.includes('zsh')) {
|
|
17
|
-
// zsh 历史文件
|
|
18
|
-
historyFile = process.env.HISTFILE || path.join(home, '.zsh_history');
|
|
19
|
-
parser = parseZshHistoryLine;
|
|
20
|
-
}
|
|
21
|
-
else if (shell.includes('bash')) {
|
|
22
|
-
// bash 历史文件
|
|
23
|
-
historyFile = process.env.HISTFILE || path.join(home, '.bash_history');
|
|
24
|
-
parser = parseBashHistoryLine;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
// 不支持的 shell
|
|
16
|
+
const shell = detectShell();
|
|
17
|
+
const capabilities = getShellCapabilities(shell);
|
|
18
|
+
// 检查是否支持历史读取
|
|
19
|
+
if (!capabilities.supportsHistory || !capabilities.historyPath) {
|
|
28
20
|
return [];
|
|
29
21
|
}
|
|
22
|
+
const historyFile = capabilities.historyPath;
|
|
23
|
+
let parser;
|
|
24
|
+
switch (shell) {
|
|
25
|
+
case 'zsh':
|
|
26
|
+
parser = parseZshHistoryLine;
|
|
27
|
+
break;
|
|
28
|
+
case 'bash':
|
|
29
|
+
parser = parseBashHistoryLine;
|
|
30
|
+
break;
|
|
31
|
+
case 'fish':
|
|
32
|
+
parser = parseFishHistoryLine;
|
|
33
|
+
break;
|
|
34
|
+
case 'powershell5':
|
|
35
|
+
case 'powershell7':
|
|
36
|
+
parser = parsePowerShellHistoryLine;
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
30
41
|
if (!fs.existsSync(historyFile)) {
|
|
31
42
|
return [];
|
|
32
43
|
}
|
|
@@ -88,6 +99,41 @@ function parseBashHistoryLine(line) {
|
|
|
88
99
|
}
|
|
89
100
|
return null;
|
|
90
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* 解析 Fish 历史行
|
|
104
|
+
* Fish 历史文件使用 YAML-like 格式:
|
|
105
|
+
* - cmd: ls -la
|
|
106
|
+
* when: 1234567890
|
|
107
|
+
*/
|
|
108
|
+
function parseFishHistoryLine(line) {
|
|
109
|
+
// Fish 历史格式比较特殊,这里简化处理
|
|
110
|
+
// 实际格式是多行的,这里只处理 cmd 行
|
|
111
|
+
const cmdMatch = line.match(/^- cmd:\s*(.+)$/);
|
|
112
|
+
if (cmdMatch) {
|
|
113
|
+
return {
|
|
114
|
+
cmd: cmdMatch[1].trim(),
|
|
115
|
+
exit: 0,
|
|
116
|
+
time: new Date().toISOString(),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 解析 PowerShell 历史行
|
|
123
|
+
* PSReadLine 历史文件格式: 每行一条命令,纯文本
|
|
124
|
+
* 路径: %APPDATA%\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
|
|
125
|
+
*/
|
|
126
|
+
function parsePowerShellHistoryLine(line) {
|
|
127
|
+
const cmd = line.trim();
|
|
128
|
+
if (cmd) {
|
|
129
|
+
return {
|
|
130
|
+
cmd,
|
|
131
|
+
exit: 0, // 系统历史文件不记录退出码
|
|
132
|
+
time: new Date().toISOString(),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
91
137
|
/**
|
|
92
138
|
* 从系统历史中获取最近一条命令
|
|
93
139
|
* 排除 pls 命令本身
|