mcp-ssh-pty 1.2.1 → 1.2.2
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/dist/shell-manager.js +18 -3
- package/package.json +1 -1
package/dist/shell-manager.js
CHANGED
|
@@ -251,8 +251,14 @@ export class ShellManager {
|
|
|
251
251
|
const newLines = this.outputLines.slice(startLineCount);
|
|
252
252
|
const currentOutput = newLines.join("\n") +
|
|
253
253
|
(this.outputBuffer ? "\n" + this.outputBuffer : "");
|
|
254
|
-
|
|
254
|
+
// 获取最后一行用于提示符检测
|
|
255
|
+
// 处理 \r(回车):取最后一个 \r 后面的内容,因为那才是当前可见的行
|
|
256
|
+
let lastLine = this.outputBuffer ||
|
|
255
257
|
(newLines.length > 0 ? newLines[newLines.length - 1] : "");
|
|
258
|
+
const lastCR = lastLine.lastIndexOf("\r");
|
|
259
|
+
if (lastCR !== -1) {
|
|
260
|
+
lastLine = lastLine.slice(lastCR + 1);
|
|
261
|
+
}
|
|
256
262
|
const hasPrompt = this.detectPrompt(lastLine);
|
|
257
263
|
// 检测输出是否稳定(连续 3 次检查没有新输出)
|
|
258
264
|
if (this.lastOutputTime <= lastCheckTime) {
|
|
@@ -299,8 +305,13 @@ export class ShellManager {
|
|
|
299
305
|
* 私有方法:检测提示符
|
|
300
306
|
*/
|
|
301
307
|
detectPrompt(line) {
|
|
302
|
-
// 移除 ANSI
|
|
303
|
-
const cleanLine = line
|
|
308
|
+
// 移除 ANSI 转义序列(更完整的正则)
|
|
309
|
+
const cleanLine = line
|
|
310
|
+
.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, "") // 标准 ANSI 序列
|
|
311
|
+
.replace(/\x1b\][^\x07]*\x07/g, "") // OSC 序列 (如 \e]2;...\a)
|
|
312
|
+
.replace(/\x1b\][^\x1b]*\x1b\\/g, "") // OSC 序列 (如 \e]7;...\e\)
|
|
313
|
+
.replace(/[\x00-\x1f]/g, "") // 其他控制字符
|
|
314
|
+
.trim();
|
|
304
315
|
if (!cleanLine)
|
|
305
316
|
return false;
|
|
306
317
|
// 常见提示符模式
|
|
@@ -313,6 +324,10 @@ export class ShellManager {
|
|
|
313
324
|
/\)\s*[$#>]\s*$/, // )$ 或 )# 结尾(一些自定义 PS1)
|
|
314
325
|
/~\s*[$#>]\s*$/, // ~$ 结尾
|
|
315
326
|
/@.*:\s*[$#>]\s*$/, // user@host: $ 格式
|
|
327
|
+
/^➜\s+/, // oh-my-zsh robbyrussell 主题 (➜ 开头)
|
|
328
|
+
/❯\s*$/, // pure/starship 主题
|
|
329
|
+
/λ\s*$/, // lambda 主题
|
|
330
|
+
/^\s*%\s*$/, // zsh 默认提示符
|
|
316
331
|
];
|
|
317
332
|
return patterns.some((p) => p.test(cleanLine));
|
|
318
333
|
}
|