@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.
Files changed (94) hide show
  1. package/README.md +30 -2
  2. package/bin/pls.tsx +153 -35
  3. package/dist/bin/pls.js +126 -23
  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 +6 -3
  37. package/dist/src/multi-step.js +6 -3
  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 +13 -0
  43. package/dist/src/shell-hook.js +163 -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 +5 -0
  47. package/dist/src/system-history.js +64 -18
  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 +8 -3
  81. package/src/multi-step.ts +7 -2
  82. package/src/project-context.ts +191 -0
  83. package/src/prompts.ts +26 -5
  84. package/src/shell-hook.ts +179 -33
  85. package/src/sysinfo.ts +326 -25
  86. package/src/system-history.ts +67 -14
  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
@@ -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 = process.env.SHELL || '';
13
- const home = os.homedir();
14
- let historyFile;
15
- let parser;
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 命令本身
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 主题系统测试
3
+ * 测试主题读取、验证、自定义主题加载等功能
4
+ */
5
+ export {};