Compare commits

...
Author SHA1 Message Date
陈大猫 8a8b159ccb fix(ai): match decorative prefix candidates after each strip
Related #4354

isDefaultPosixPromptLine must try the original line and each
intermediate strip so a status glyph in front of an Oh My Zsh
➜ prompt does not drop the ➜ before matching.
2026-12-02 01:30:50 +08:00
陈大猫 7a9f072a5c fix(ai): loop-strip stacked decorative prompt prefixes
Related #4354

After a non-zero exit, p10k (and similar) may prefix a status glyph
such as ✘ before the existing theme decoration (⚡). Recognition only
stripped one 1-4 char decorative token, so the leftover ⚡ still missed
the idle-prompt matchers and MCP terminal_execute never sent the command.
2026-12-02 01:23:21 +08:00
2 changed files with 42 additions and 6 deletions

No files matched your search

+11 -6
View File
@@ -174,7 +174,7 @@ function isDefaultCmdPromptLine(line) {
}
function stripLeadingDecorativeToken(line) {
// Optional short decorative token, stripped only for recognition (#4354).
// Optional short decorative tokens, stripped only for recognition (#4354).
return line.replace(/^\s*[^\s\w\p{L}\p{N}@:#$\\\/>\[\]().]{1,4}\s+/u, "");
}
@@ -183,9 +183,11 @@ function isDefaultPosixPromptLine(line) {
// Optional virtualenv / conda / BT-panel style env name prefix: "(name) "
// before the shell prompt. Recognition only; callers still return the full
// prompt line so suffix matching sees the visible prefix (#3947).
const withoutEnvPrefix = normalized.replace(/^\([^()\n\r]+\)\s+/, "");
return [withoutEnvPrefix, stripLeadingDecorativeToken(withoutEnvPrefix)].some(
(prompt) => (
let prompt = normalized.replace(/^\([^()\n\r]+\)\s+/, "");
// Check each candidate before stripping again: a glyph such as the
// robbyrussell arrow may be part of the prompt itself (#4354).
while (true) {
if (
POSIX_PROMPT_PATTERN.test(prompt) ||
BRACKET_TIME_POSIX_PROMPT_PATTERN.test(prompt) ||
BRACKET_PATH_POSIX_PROMPT_PATTERN.test(prompt) ||
@@ -196,8 +198,11 @@ function isDefaultPosixPromptLine(line) {
POWERLEVEL10K_PROMPT_PATTERN.test(prompt) ||
POWERLINE_PROMPT_PATTERN.test(prompt) ||
OH_MY_ZSH_ROBBYRUSSELL_PROMPT_PATTERN.test(prompt)
),
);
) return true;
const stripped = stripLeadingDecorativeToken(prompt);
if (stripped === prompt) return false;
prompt = stripped;
}
}
function extractTrailingIdlePrompt(output) {
+31
View File
@@ -518,10 +518,41 @@ test("isDefaultPosixPromptLine matches short decorative prefixes and keeps the f
}
});
test("stacked decorative prefixes preserve the full extracted and tracked prompt", () => {
for (const prompt of [
...["\u2718", "\u2714", "\u2717", "\u2713"].flatMap(status => [
`${status} \u26A1 root@testhost:~# `,
`${status} \u26A1 root@testhost:~#`,
`${status} \u26A1 root@testhost \uE0B0 ~ \uE0B0 `,
`(venv) ${status} \u26A1 user@host:~# `,
`${status} \u279C netcatty`,
`${status} \u279C netcatty `,
`${status} \u279C ~ git:(main) \u2717`,
`(venv) ${status} \u279C netcatty git:(main) \u2713 `,
]),
"\u2718 \u2714 \u26A1 root@testhost:~# ",
"\u2718 \u2714 \u279C netcatty ",
]) {
assert.equal(isDefaultPosixPromptLine(prompt), true, prompt);
assert.equal(extractTrailingIdlePrompt(`welcome\r\n${prompt}`), prompt, prompt);
const session = {};
trackSessionIdlePrompt(session, `welcome\r\n${prompt}`);
assert.equal(session.lastIdlePrompt, prompt, prompt);
assert.equal(getFreshIdlePrompt(session), prompt, prompt);
}
});
test("decorative prefix recognition rejects pending input and non-decorative prefixes", () => {
for (const line of [
"\u26A1 root@testhost:~# echo hi",
" \u26A1 root@testhost \uE0B0 ~ \uE0B0 ls",
"\u2718 \u26A1 root@testhost:~# echo hi",
"\u2718 \u26A1 root@testhost \uE0B0 ~ \uE0B0 ls",
...["\u2718", "\u2714", "\u2717", "\u2713"].flatMap(status => [
`${status} \u279C netcatty ls`,
`(venv) ${status} \u279C netcatty git:(main) \u2713 ls`,
]),
"\u2718 \u2714 \u279C netcatty ls",
"OK root@testhost:~# ",
"yes root@testhost:~# ",
"git:(main) root@testhost:~# ",