mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-26 02:31:40 +00:00
fix(mcp): recognize Powerline U+E0B0-U+E0B7 idle prompt endings (#4359)
This commit is contained in:
2 files changed
+48
No files matched your search
@@ -147,6 +147,9 @@ const MACOS_ROOT_PROMPT_PATTERN = /^[A-Za-z0-9_][A-Za-z0-9_.-]*:(?:~|\/|[^\s:#$>
|
||||
const POWERLEVEL10K_PROMPT_PATTERN =
|
||||
/^(?:[^\s@]+@[^\s:]+\s+)?[^\s❯][^❯\r\n]*\s+❯$/;
|
||||
|
||||
const POWERLINE_PROMPT_PATTERN =
|
||||
/^\s*(?:[\uE0B0-\uE0B7]\s*)?(?:[^\s@\uE0B0-\uE0B7]+@[^\s:\uE0B0-\uE0B7]+|[~/])[^\r\n]*[\uE0B0-\uE0B7]$/;
|
||||
|
||||
// Oh My Zsh default theme (robbyrussell): leading ➜ (U+279C) then cwd (%c),
|
||||
// optionally ` git:(branch)` and a dirty/clean marker. Idle forms look like
|
||||
// `➜ ~`, `➜ netcatty`, `➜ ~ git:(main)`, `➜ ~ git:(main) ✗`.
|
||||
@@ -180,6 +183,7 @@ function isDefaultPosixPromptLine(line) {
|
||||
MACOS_ROOT_PROMPT_PATTERN.test(withoutEnvPrefix) ||
|
||||
ZSH_PROMPT_PATTERN.test(withoutEnvPrefix) ||
|
||||
POWERLEVEL10K_PROMPT_PATTERN.test(withoutEnvPrefix) ||
|
||||
POWERLINE_PROMPT_PATTERN.test(withoutEnvPrefix) ||
|
||||
OH_MY_ZSH_ROBBYRUSSELL_PROMPT_PATTERN.test(withoutEnvPrefix)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -410,6 +410,50 @@ test("extractTrailingIdlePrompt recognizes Powerlevel10k ❯ and preserves trail
|
||||
assert.equal(extractTrailingIdlePrompt("welcome\r\n~ ❯\r\n"), "");
|
||||
});
|
||||
|
||||
test("isDefaultPosixPromptLine matches Powerline separator idle prompts", () => {
|
||||
for (const prompt of [
|
||||
" ubuntu@VM-0-10-ubuntu \uE0B0 /opt/xxxx \uE0B0 ",
|
||||
"\uE0B2 ubuntu@VM-0-10-ubuntu \uE0B0 /opt/xxxx \uE0B0 ",
|
||||
"ubuntu@VM-0-10-ubuntu\uE0B0 /opt/xxxx\uE0B0",
|
||||
"user@host\uE0B0 ",
|
||||
"~\uE0B0 ",
|
||||
"~/src \uE0B0 ",
|
||||
"/opt/xxxx\uE0B0 ",
|
||||
...Array.from({ length: 8 }, (_, i) => `~/src ${String.fromCharCode(0xE0B0 + i)} `),
|
||||
]) {
|
||||
assert.equal(isDefaultPosixPromptLine(prompt), true, prompt);
|
||||
assert.equal(extractTrailingIdlePrompt(`welcome\r\n${prompt}`), prompt, prompt);
|
||||
}
|
||||
});
|
||||
|
||||
test("Powerline recognition rejects pending input, bare separators, and other PUA endings", () => {
|
||||
for (const line of [
|
||||
" ubuntu@VM-0-10-ubuntu \uE0B0 /opt/xxxx \uE0B0 ls",
|
||||
"\uE0B2 ubuntu@VM-0-10-ubuntu \uE0B0 /opt/xxxx \uE0B0 echo hi",
|
||||
"ubuntu@VM-0-10-ubuntu\uE0B0 /opt/xxxx\uE0B0ls",
|
||||
"~/src \uE0B0 echo hi",
|
||||
"proj \uE0B0 ",
|
||||
"copied output \uE0B0 ",
|
||||
" ubuntu@VM-0-10-ubuntu /opt/xxxx ",
|
||||
...Array.from({ length: 8 }, (_, i) => String.fromCharCode(0xE0B0 + i))
|
||||
.flatMap(separator => [separator, `${separator} `]),
|
||||
...[0xE000, 0xE0AF, 0xE0B8, 0xF000, 0xF8FF]
|
||||
.map(code => `~/src ${String.fromCharCode(code)} `),
|
||||
]) {
|
||||
assert.equal(isDefaultPosixPromptLine(line), false, line);
|
||||
assert.equal(extractTrailingIdlePrompt(`welcome\r\n${line}`), "", line);
|
||||
}
|
||||
});
|
||||
|
||||
test("Powerline recognition preserves existing idle prompt recognition", () => {
|
||||
for (const prompt of ["~ ❯", "user@host ~ ❯", "user@host:~$"]) {
|
||||
assert.equal(isDefaultPosixPromptLine(prompt), true, prompt);
|
||||
assert.equal(extractTrailingIdlePrompt(prompt), prompt, prompt);
|
||||
}
|
||||
const twoLinePrompt = "[demo@example-host ~]\n$";
|
||||
assert.equal(extractTrailingIdlePrompt(twoLinePrompt), twoLinePrompt);
|
||||
});
|
||||
|
||||
test("trackSessionIdlePrompt and getFreshIdlePrompt accept a Powerlevel10k ❯ prompt", () => {
|
||||
const session = {};
|
||||
trackSessionIdlePrompt(session, "Last login...\r\n~ ❯ ");
|
||||
|
||||
Reference in new issue
Block a user