@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
@@ -1,10 +1,66 @@
1
1
  import os from 'os';
2
- import { execSync } from 'child_process';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import chalk from 'chalk';
5
+ import { detectProjectContext, formatProjectContext } from './project-context.js';
6
+ import { getConfig, CONFIG_DIR } from './config.js';
7
+ import { getCurrentTheme } from './ui/theme.js';
8
+ import { detectShell, getShellCapabilities, commandExists, batchCommandExists, isWindows, } from './utils/platform.js';
3
9
  /**
4
- * 检测包管理器
10
+ * 要检测的命令列表(45 个)
11
+ */
12
+ const COMMANDS_TO_CHECK = {
13
+ // 现代 CLI 工具(ls/find/grep/cat 等的替代品)
14
+ modern: [
15
+ 'eza', 'lsd', 'exa', // ls 替代
16
+ 'fd', 'fdfind', // find 替代
17
+ 'rg', 'ag', 'ack', // grep 替代
18
+ 'bat', 'batcat', // cat 替代
19
+ 'fzf', 'skim', // 模糊搜索
20
+ 'jq', 'yq', 'fx', // JSON/YAML 处理
21
+ 'delta', 'diff-so-fancy', // diff 替代
22
+ 'zoxide', 'z', 'autojump', // cd 替代
23
+ 'tldr', 'tealdeer', // man 替代
24
+ 'dust', 'duf', 'ncdu', // du 替代
25
+ 'procs', 'bottom', 'htop', // ps/top 替代
26
+ 'sd', // sed 替代
27
+ 'hyperfine', // benchmark
28
+ ],
29
+ // 包管理器
30
+ node: ['pnpm', 'yarn', 'bun', 'npm'],
31
+ python: ['uv', 'rye', 'poetry', 'pipenv', 'pip'],
32
+ rust: ['cargo'],
33
+ go: ['go'],
34
+ ruby: ['gem', 'bundle'],
35
+ php: ['composer'],
36
+ // 容器/云工具
37
+ container: ['docker', 'podman', 'nerdctl'],
38
+ k8s: ['kubectl', 'k9s', 'helm'],
39
+ // 版本控制
40
+ vcs: ['git', 'gh', 'glab', 'hg'],
41
+ // 构建工具
42
+ build: ['make', 'cmake', 'ninja', 'just', 'task'],
43
+ // 其他常用工具
44
+ misc: ['curl', 'wget', 'aria2c', 'rsync', 'ssh', 'tmux', 'screen'],
45
+ };
46
+ // 缓存文件路径
47
+ const CACHE_FILE = path.join(CONFIG_DIR, 'system_cache.json');
48
+ /**
49
+ * 检测系统包管理器
5
50
  */
6
51
  function detectPackageManager() {
7
- const managers = [
52
+ // Windows 包管理器
53
+ if (isWindows()) {
54
+ const windowsManagers = ['winget', 'scoop', 'choco'];
55
+ for (const mgr of windowsManagers) {
56
+ if (commandExists(mgr)) {
57
+ return mgr;
58
+ }
59
+ }
60
+ return 'unknown';
61
+ }
62
+ // Unix 包管理器
63
+ const unixManagers = [
8
64
  { name: 'brew', command: 'brew' },
9
65
  { name: 'apt', command: 'apt-get' },
10
66
  { name: 'dnf', command: 'dnf' },
@@ -13,40 +69,208 @@ function detectPackageManager() {
13
69
  { name: 'zypper', command: 'zypper' },
14
70
  { name: 'apk', command: 'apk' },
15
71
  ];
16
- for (const mgr of managers) {
17
- try {
18
- execSync(`which ${mgr.command}`, { stdio: 'ignore' });
72
+ for (const mgr of unixManagers) {
73
+ if (commandExists(mgr.command)) {
19
74
  return mgr.name;
20
75
  }
21
- catch {
22
- // 继续检测下一个
23
- }
24
76
  }
25
77
  return 'unknown';
26
78
  }
27
79
  /**
28
- * 获取当前 Shell
80
+ * 检测可用命令(跨平台版本)
81
+ * 使用 platform 模块的 batchCommandExists 函数
29
82
  */
30
- function getCurrentShell() {
31
- return process.env.SHELL || 'unknown';
83
+ function detectAvailableCommands() {
84
+ const allCommands = Object.values(COMMANDS_TO_CHECK).flat();
85
+ return batchCommandExists(allCommands);
32
86
  }
33
87
  /**
34
- * 收集系统信息
88
+ * 检测所有静态信息(纯同步,不需要 async)
35
89
  */
36
- export function collectSystemInfo() {
90
+ function detectStaticInfo() {
91
+ // 使用 platform 模块检测 Shell
92
+ const shell = detectShell();
93
+ const capabilities = getShellCapabilities(shell);
37
94
  return {
38
95
  os: os.platform(),
39
96
  arch: os.arch(),
40
- shell: getCurrentShell(),
41
- packageManager: detectPackageManager(),
42
- cwd: process.cwd(),
97
+ shell: capabilities.displayName,
43
98
  user: os.userInfo().username,
99
+ systemPackageManager: detectPackageManager(),
100
+ availableCommands: detectAvailableCommands(),
101
+ };
102
+ }
103
+ /**
104
+ * 获取静态系统信息(带缓存)
105
+ */
106
+ export function getStaticSystemInfo() {
107
+ const config = getConfig();
108
+ // 确保配置目录存在
109
+ if (!fs.existsSync(CONFIG_DIR)) {
110
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
111
+ }
112
+ if (fs.existsSync(CACHE_FILE)) {
113
+ try {
114
+ const cache = JSON.parse(fs.readFileSync(CACHE_FILE, 'utf-8'));
115
+ // 缓存未过期
116
+ const expireDays = config.systemCacheExpireDays || 7;
117
+ const age = Date.now() - new Date(cache.cachedAt).getTime();
118
+ if (age < expireDays * 24 * 60 * 60 * 1000) {
119
+ return cache.static;
120
+ }
121
+ }
122
+ catch {
123
+ // 缓存文件损坏,重新检测
124
+ }
125
+ }
126
+ // 首次或过期,重新检测
127
+ const info = detectStaticInfo();
128
+ // 保存缓存
129
+ const cache = {
130
+ version: 1,
131
+ cachedAt: new Date().toISOString(),
132
+ expiresInDays: config.systemCacheExpireDays || 7,
133
+ static: info,
134
+ };
135
+ fs.writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2));
136
+ return info;
137
+ }
138
+ /**
139
+ * 获取动态系统信息(每次实时)
140
+ */
141
+ export async function getDynamicSystemInfo() {
142
+ return {
143
+ cwd: process.cwd(),
144
+ project: await detectProjectContext(process.cwd()),
145
+ };
146
+ }
147
+ /**
148
+ * 获取完整系统信息(主接口)
149
+ */
150
+ export async function getSystemInfo() {
151
+ return {
152
+ ...getStaticSystemInfo(),
153
+ ...(await getDynamicSystemInfo()),
44
154
  };
45
155
  }
46
156
  /**
47
- * 将系统信息格式化为字符串(供 AI 使用)
157
+ * 辅助函数:分类命令
48
158
  */
49
- export function formatSystemInfo() {
50
- const info = collectSystemInfo();
51
- return `OS: ${info.os}, Arch: ${info.arch}, Shell: ${info.shell}, PkgMgr: ${info.packageManager}, CWD: ${info.cwd}`;
159
+ function categorizeCommands(commands) {
160
+ const modern = ['eza', 'lsd', 'exa', 'fd', 'fdfind', 'rg', 'ag', 'ack', 'bat', 'batcat', 'fzf', 'jq', 'yq', 'delta'];
161
+ const packageManagers = ['pnpm', 'yarn', 'bun', 'npm', 'uv', 'poetry', 'cargo', 'go'];
162
+ const containers = ['docker', 'podman', 'kubectl', 'k9s', 'helm'];
163
+ return {
164
+ modern: commands.filter(cmd => modern.includes(cmd)),
165
+ packageManagers: commands.filter(cmd => packageManagers.includes(cmd)),
166
+ containers: commands.filter(cmd => containers.includes(cmd)),
167
+ others: commands.filter(cmd => !modern.includes(cmd) &&
168
+ !packageManagers.includes(cmd) &&
169
+ !containers.includes(cmd)),
170
+ };
171
+ }
172
+ /**
173
+ * 格式化系统信息为字符串(供 AI 使用)
174
+ */
175
+ export function formatSystemInfo(info) {
176
+ const parts = [];
177
+ // 基础信息
178
+ parts.push(`OS: ${info.os}, Arch: ${info.arch}, Shell: ${info.shell}, User: ${info.user}`);
179
+ parts.push(`Package Manager: ${info.systemPackageManager}, CWD: ${info.cwd}`);
180
+ // 可用工具(分类展示)
181
+ if (info.availableCommands.length > 0) {
182
+ const categorized = categorizeCommands(info.availableCommands);
183
+ const lines = [];
184
+ if (categorized.modern.length > 0) {
185
+ lines.push(`现代工具: ${categorized.modern.join(', ')}`);
186
+ }
187
+ if (categorized.packageManagers.length > 0) {
188
+ lines.push(`包管理器: ${categorized.packageManagers.join(', ')}`);
189
+ }
190
+ if (categorized.containers.length > 0) {
191
+ lines.push(`容器工具: ${categorized.containers.join(', ')}`);
192
+ }
193
+ if (categorized.others.length > 0) {
194
+ lines.push(`其他: ${categorized.others.join(', ')}`);
195
+ }
196
+ if (lines.length > 0) {
197
+ parts.push(`【用户终端可用工具】(非完整列表)`);
198
+ parts.push(...lines);
199
+ //parts.push(`注: 为确保兼容性和输出捕获,建议优先使用标准命令(ls/find/grep/cat/ps)`)
200
+ }
201
+ }
202
+ // 项目上下文
203
+ if (info.project && info.project.types.length > 0) {
204
+ parts.push(formatProjectContext(info.project));
205
+ }
206
+ return parts.join('\n');
207
+ }
208
+ /**
209
+ * 显示系统信息(CLI 美化版)
210
+ */
211
+ export function displaySystemInfo(info) {
212
+ const theme = getCurrentTheme();
213
+ console.log(chalk.bold('\n系统信息:'));
214
+ console.log(chalk.hex(theme.text.muted)('━'.repeat(50)));
215
+ // 基础信息
216
+ console.log(` ${chalk.hex(theme.primary)('操作系统')}: ${info.os}`);
217
+ console.log(` ${chalk.hex(theme.primary)('架构')}: ${info.arch}`);
218
+ console.log(` ${chalk.hex(theme.primary)('Shell')}: ${info.shell}`);
219
+ console.log(` ${chalk.hex(theme.primary)('用户')}: ${info.user}`);
220
+ console.log(` ${chalk.hex(theme.primary)('系统包管理器')}: ${info.systemPackageManager}`);
221
+ console.log(` ${chalk.hex(theme.primary)('当前目录')}: ${chalk.hex(theme.text.secondary)(info.cwd)}`);
222
+ // 可用工具
223
+ if (info.availableCommands.length > 0) {
224
+ console.log(` ${chalk.hex(theme.primary)('可用命令数')}: ${chalk.hex(theme.success)(info.availableCommands.length)}`);
225
+ const categorized = categorizeCommands(info.availableCommands);
226
+ if (categorized.modern.length > 0) {
227
+ console.log(` ${chalk.hex(theme.text.secondary)('现代工具')}: ${categorized.modern.join(', ')}`);
228
+ }
229
+ if (categorized.packageManagers.length > 0) {
230
+ console.log(` ${chalk.hex(theme.text.secondary)('包管理器')}: ${categorized.packageManagers.join(', ')}`);
231
+ }
232
+ if (categorized.containers.length > 0) {
233
+ console.log(` ${chalk.hex(theme.text.secondary)('容器工具')}: ${categorized.containers.join(', ')}`);
234
+ }
235
+ if (categorized.others.length > 0) {
236
+ console.log(` ${chalk.hex(theme.text.secondary)('其他工具')}: ${categorized.others.join(', ')}`);
237
+ }
238
+ }
239
+ // 项目信息
240
+ if (info.project && info.project.types.length > 0) {
241
+ console.log(chalk.hex(theme.text.muted)(' ──────────────────────────────────────────────────'));
242
+ console.log(` ${chalk.hex(theme.primary)('项目类型')}: ${info.project.types.join(', ')}`);
243
+ if (info.project.packageManager) {
244
+ console.log(` ${chalk.hex(theme.primary)('包管理器')}: ${info.project.packageManager}`);
245
+ }
246
+ if (info.project.git) {
247
+ const statusColor = info.project.git.status === 'clean' ? theme.success : theme.warning;
248
+ const statusText = info.project.git.status === 'clean' ? '干净' : info.project.git.status === 'dirty' ? '有改动' : '未知';
249
+ console.log(` ${chalk.hex(theme.primary)('Git 分支')}: ${info.project.git.branch} (${chalk.hex(statusColor)(statusText)})`);
250
+ }
251
+ if (info.project.scripts && info.project.scripts.length > 0) {
252
+ console.log(` ${chalk.hex(theme.primary)('可用脚本')}: ${info.project.scripts.join(', ')}`);
253
+ }
254
+ }
255
+ console.log(chalk.hex(theme.text.muted)('━'.repeat(50)));
256
+ console.log(chalk.hex(theme.text.muted)(`缓存文件: ${CACHE_FILE}\n`));
257
+ }
258
+ /**
259
+ * 强制刷新缓存
260
+ */
261
+ export function refreshSystemCache() {
262
+ const config = getConfig();
263
+ const info = detectStaticInfo();
264
+ const cache = {
265
+ version: 1,
266
+ cachedAt: new Date().toISOString(),
267
+ expiresInDays: config.systemCacheExpireDays || 7,
268
+ static: info,
269
+ };
270
+ // 确保配置目录存在
271
+ if (!fs.existsSync(CONFIG_DIR)) {
272
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
273
+ }
274
+ fs.writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2));
275
+ console.log('✓ 系统信息缓存已刷新');
52
276
  }
@@ -0,0 +1,18 @@
1
+ import type { ShellHistoryItem } from './shell-hook.js';
2
+ /**
3
+ * 直接读取系统 shell 历史文件(类似 thefuck)
4
+ * 用于没有安装 shell hook 的情况
5
+ *
6
+ * 限制:系统历史文件不记录退出码,所以 exit 字段都是 0
7
+ *
8
+ * 支持的 Shell:
9
+ * - Unix: zsh, bash, fish
10
+ * - Windows: PowerShell 5.x, PowerShell 7+ (通过 PSReadLine)
11
+ * - 不支持: CMD (无持久化历史)
12
+ */
13
+ export declare function getSystemShellHistory(): ShellHistoryItem[];
14
+ /**
15
+ * 从系统历史中获取最近一条命令
16
+ * 排除 pls 命令本身
17
+ */
18
+ export declare function getLastCommandFromSystem(): ShellHistoryItem | null;
@@ -0,0 +1,151 @@
1
+ import fs from 'fs';
2
+ import { getConfig } from './config.js';
3
+ import { detectShell, getShellCapabilities } from './utils/platform.js';
4
+ /**
5
+ * 直接读取系统 shell 历史文件(类似 thefuck)
6
+ * 用于没有安装 shell hook 的情况
7
+ *
8
+ * 限制:系统历史文件不记录退出码,所以 exit 字段都是 0
9
+ *
10
+ * 支持的 Shell:
11
+ * - Unix: zsh, bash, fish
12
+ * - Windows: PowerShell 5.x, PowerShell 7+ (通过 PSReadLine)
13
+ * - 不支持: CMD (无持久化历史)
14
+ */
15
+ export function getSystemShellHistory() {
16
+ const shell = detectShell();
17
+ const capabilities = getShellCapabilities(shell);
18
+ // 检查是否支持历史读取
19
+ if (!capabilities.supportsHistory || !capabilities.historyPath) {
20
+ return [];
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
+ }
41
+ if (!fs.existsSync(historyFile)) {
42
+ return [];
43
+ }
44
+ try {
45
+ const content = fs.readFileSync(historyFile, 'utf-8');
46
+ const lines = content.trim().split('\n');
47
+ const limit = getConfig().shellHistoryLimit || 10;
48
+ // 只取最后 N 条
49
+ const recentLines = lines.slice(-limit);
50
+ return recentLines
51
+ .map(line => parser(line))
52
+ .filter((item) => item !== null);
53
+ }
54
+ catch {
55
+ return [];
56
+ }
57
+ }
58
+ /**
59
+ * 解析 zsh 历史行
60
+ * 格式: ": 1234567890:0;ls -la"
61
+ * 或者: "ls -la" (简单格式)
62
+ */
63
+ function parseZshHistoryLine(line) {
64
+ // 扩展格式: ": timestamp:duration;command"
65
+ const extendedMatch = line.match(/^:\s*(\d+):\d+;(.+)$/);
66
+ if (extendedMatch) {
67
+ const timestamp = parseInt(extendedMatch[1]);
68
+ const cmd = extendedMatch[2].trim();
69
+ return {
70
+ cmd,
71
+ exit: 0, // 系统历史文件不记录退出码
72
+ time: new Date(timestamp * 1000).toISOString(),
73
+ };
74
+ }
75
+ // 简单格式
76
+ const cmd = line.trim();
77
+ if (cmd) {
78
+ return {
79
+ cmd,
80
+ exit: 0,
81
+ time: new Date().toISOString(),
82
+ };
83
+ }
84
+ return null;
85
+ }
86
+ /**
87
+ * 解析 bash 历史行
88
+ * 格式: "ls -la"
89
+ * bash 历史文件默认不记录时间戳
90
+ */
91
+ function parseBashHistoryLine(line) {
92
+ const cmd = line.trim();
93
+ if (cmd) {
94
+ return {
95
+ cmd,
96
+ exit: 0, // 系统历史文件不记录退出码
97
+ time: new Date().toISOString(),
98
+ };
99
+ }
100
+ return null;
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
+ }
137
+ /**
138
+ * 从系统历史中获取最近一条命令
139
+ * 排除 pls 命令本身
140
+ */
141
+ export function getLastCommandFromSystem() {
142
+ const history = getSystemShellHistory();
143
+ // 从后往前找第一条非 pls 命令
144
+ for (let i = history.length - 1; i >= 0; i--) {
145
+ const item = history[i];
146
+ if (!item.cmd.startsWith('pls') && !item.cmd.startsWith('please')) {
147
+ return item;
148
+ }
149
+ }
150
+ return null;
151
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 主题系统测试
3
+ * 测试主题读取、验证、自定义主题加载等功能
4
+ */
5
+ export {};