778 lines
40 KiB
JavaScript
778 lines
40 KiB
JavaScript
import test from 'node:test';
|
||
import assert from 'node:assert';
|
||
import { detectTerminalActivity, detectInteractiveMenu } from '../src/utils/activity-detector.js';
|
||
|
||
test('ActivityDetector — Classificação Determinística de Terminais (IA vs Shell Puro)', async (t) => {
|
||
await t.test('1. Terminais Vazios ou Nulos', () => {
|
||
const r1 = detectTerminalActivity('');
|
||
assert.strictEqual(r1.hasAiActivity, false);
|
||
assert.strictEqual(r1.shellType, 'empty');
|
||
|
||
const r2 = detectTerminalActivity(null);
|
||
assert.strictEqual(r2.hasAiActivity, false);
|
||
assert.strictEqual(r2.shellType, 'empty');
|
||
|
||
const r3 = detectTerminalActivity(' \n\n ');
|
||
assert.strictEqual(r3.hasAiActivity, false);
|
||
assert.strictEqual(r3.shellType, 'empty');
|
||
});
|
||
|
||
await t.test('2. Shell Puro: PowerShell', () => {
|
||
const psInitial = `Windows PowerShell\nCopyright (C) Microsoft Corporation. All rights reserved.\n\nPS C:\\Users\\winic> `;
|
||
const r1 = detectTerminalActivity(psInitial);
|
||
assert.strictEqual(r1.hasAiActivity, false, 'PowerShell inicial deve ser identificado como shell puro');
|
||
assert.strictEqual(r1.shellType, 'powershell');
|
||
|
||
const psAfterCommand = `PS D:\\Desenvolvimento> git status\nOn branch master\nnothing to commit\nPS D:\\Desenvolvimento> `;
|
||
const r2 = detectTerminalActivity(psAfterCommand);
|
||
assert.strictEqual(r2.hasAiActivity, false, 'PowerShell após comando deve ser shell puro');
|
||
assert.strictEqual(r2.shellType, 'powershell');
|
||
});
|
||
|
||
await t.test('3. Shell Puro: DOS / CMD', () => {
|
||
const dosInitial = `Microsoft Windows [Version 10.0.26100.2605]\n(c) Microsoft Corporation. Todos os direitos reservados.\n\nC:\\Users\\winic> `;
|
||
const r1 = detectTerminalActivity(dosInitial);
|
||
assert.strictEqual(r1.hasAiActivity, false, 'DOS/CMD inicial deve ser identificado como shell puro');
|
||
assert.strictEqual(r1.shellType, 'cmd');
|
||
|
||
const dosAfterDir = `C:\\Users\\winic> dir\n Volume in drive C has no label.\nC:\\Users\\winic> `;
|
||
const r2 = detectTerminalActivity(dosAfterDir);
|
||
assert.strictEqual(r2.hasAiActivity, false);
|
||
assert.strictEqual(r2.shellType, 'cmd');
|
||
});
|
||
|
||
await t.test('4. Shell Puro: Bash / WSL / Git Bash', () => {
|
||
const bashInitial = `winic@ubuntu-server:~$ `;
|
||
const r1 = detectTerminalActivity(bashInitial);
|
||
assert.strictEqual(r1.hasAiActivity, false, 'Bash inicial deve ser identificado como shell puro');
|
||
assert.strictEqual(r1.shellType, 'bash');
|
||
|
||
const gitBash = `winic@NTB-4VCYNG4 MINGW64 /d/Desenvolvimento\n$ `;
|
||
const r2 = detectTerminalActivity(gitBash);
|
||
assert.strictEqual(r2.hasAiActivity, false);
|
||
assert.strictEqual(r2.shellType, 'bash');
|
||
});
|
||
|
||
await t.test('5. Agente de IA Ativo: Antigravity CLI (agy)', () => {
|
||
const agyOutput = `
|
||
PS E:\\SREOracleServer> agy
|
||
|
||
▄▀▀▄ Antigravity CLI 1.5.4
|
||
▀▀▀▀▀▀ winicius2006@gmail.com (Google AI Pro)
|
||
▀▀▀▀▀▀▀▀ Gemini 3.8 Flash (Medium)
|
||
▄▀▀ ▀▀▄ E:/SREOracleServer
|
||
▄▀▀ ▀▀▄
|
||
|
||
────────────────────────────────────────────────────────────
|
||
> inicialize o projeto
|
||
○ Thought for 22s
|
||
● Ran (git remote -v)
|
||
● Explored 1 file (AGENTS.md)
|
||
────────────────────────────────────────────────────────────
|
||
>
|
||
────────────────────────────────────────────────────────────
|
||
? for shortcuts Gemini 3.8 Flash · medium
|
||
`;
|
||
const r = detectTerminalActivity(agyOutput);
|
||
assert.strictEqual(r.hasAiActivity, true, 'Antigravity CLI ativo deve ser hasAiActivity = true');
|
||
assert.strictEqual(r.aiType, 'agy');
|
||
});
|
||
|
||
await t.test('6. Agente de IA Ativo: Claude Code', () => {
|
||
const claudeOutput = `
|
||
● Ran 3 commands, checked 1 task
|
||
✻ Worked for 45s
|
||
────────────────────────────────────────────────────────────
|
||
❯ esc to cancel · ctrl+o to expand · shift+tab to cycle
|
||
`;
|
||
const r = detectTerminalActivity(claudeOutput);
|
||
assert.strictEqual(r.hasAiActivity, true, 'Claude Code ativo deve ser hasAiActivity = true');
|
||
assert.strictEqual(r.aiType, 'claude');
|
||
});
|
||
|
||
await t.test('7. Agente de IA Ativo: Kiro CLI e Gemini CLI', () => {
|
||
const kiroOutput = `Kiro CLI v0.4.2\nConnected to workspace\nkiro> `;
|
||
const r1 = detectTerminalActivity(kiroOutput);
|
||
assert.strictEqual(r1.hasAiActivity, true);
|
||
assert.strictEqual(r1.aiType, 'kiro');
|
||
|
||
const geminiOutput = `Gemini CLI v1.2.0\ngemini-cli> `;
|
||
const r2 = detectTerminalActivity(geminiOutput);
|
||
assert.strictEqual(r2.hasAiActivity, true);
|
||
assert.strictEqual(r2.aiType, 'gemini');
|
||
});
|
||
|
||
await t.test('8. Agente de IA que foi encerrado voltando ao Shell puro', () => {
|
||
const exitedAgy = `
|
||
Antigravity CLI 1.5.4
|
||
> /exit
|
||
Saindo do Antigravity CLI...
|
||
PS C:\\Users\\winic>
|
||
`;
|
||
const r = detectTerminalActivity(exitedAgy);
|
||
assert.strictEqual(r.hasAiActivity, false, 'Se o agente encerrou e o prompt final é PS, deve ser shell puro');
|
||
assert.strictEqual(r.shellType, 'powershell');
|
||
});
|
||
|
||
await t.test('9. Spinners Braille em Execução (Agente Pensando)', () => {
|
||
const thinkingOutput = `> Analisando estrutura do banco...\n⠇ Buscando migrations`;
|
||
const r = detectTerminalActivity(thinkingOutput);
|
||
assert.strictEqual(r.hasAiActivity, true);
|
||
assert.strictEqual(r.isThinking, true);
|
||
});
|
||
|
||
await t.test('10. Claude Code pausado por limite de uso (Usage limit reached)', () => {
|
||
const rateLimitedClaudeOutput = `
|
||
> continue
|
||
|
||
• Usage limit reached again • continuing automatically at 1:50pm • esc to cancel
|
||
↳ You've hit your 5-hour limit • resets 1:50pm (America/Sao_Paulo)
|
||
|
||
* Crunched for 0s • done 12:22 PM
|
||
|
||
⚠ Usage limit reached • limit resets 1:50pm
|
||
Continuing automatically at 1:50pm • Esc to cancel
|
||
`;
|
||
const r = detectTerminalActivity(rateLimitedClaudeOutput);
|
||
assert.strictEqual(r.hasAiActivity, true, 'Deve identificar sessão do Claude Code');
|
||
assert.strictEqual(r.aiType, 'claude');
|
||
assert.strictEqual(r.isThinking, false, 'Agente pausado por cota NÃO deve ser marcado como thinking/trabalhando');
|
||
assert.strictEqual(r.isPaused, true, 'Deve marcar isPaused = true');
|
||
assert.strictEqual(r.pauseReason, 'usage_limit');
|
||
assert.strictEqual(r.pauseResetTime, '1:50pm', 'Deve extrair o horário de reset da cota');
|
||
});
|
||
|
||
await t.test('11. Agente com resposta contendo palavras reservadas (.thinking) e prompt ocioso final', () => {
|
||
// Caso real relatado pelo usuário: o agente gerou texto mencionando .thinking, mas o terminal está pronto no prompt
|
||
const agyTerminalWithThinkingMention = `
|
||
────────────────────────────────────────────────────────────
|
||
Para alterar o status usamos a classe .thinking e a cor #f59e0b.
|
||
Também verificamos running command e compiling no buffer.
|
||
────────────────────────────────────────────────────────────
|
||
│ >
|
||
? for shortcuts Gemini 3.8 Flash · medium
|
||
`;
|
||
const r1 = detectTerminalActivity(agyTerminalWithThinkingMention);
|
||
assert.strictEqual(r1.hasAiActivity, true, 'Deve identificar Antigravity CLI');
|
||
assert.strictEqual(r1.aiType, 'agy');
|
||
assert.strictEqual(r1.isThinking, false, 'Precedência de prompt ocioso: não deve ficar preso em thinking');
|
||
assert.strictEqual(r1.details, 'Antigravity CLI pronto');
|
||
|
||
const claudeTerminalWithThinkingMention = `
|
||
Here is the implementation:
|
||
const isThinking = true;
|
||
We use thinking mode for complex reasoning.
|
||
────────────────────────────────────────────────────────────
|
||
Claude>
|
||
`;
|
||
const r2 = detectTerminalActivity(claudeTerminalWithThinkingMention);
|
||
assert.strictEqual(r2.hasAiActivity, true, 'Deve identificar Claude Code');
|
||
assert.strictEqual(r2.aiType, 'claude');
|
||
assert.strictEqual(r2.isThinking, false, 'Prompt ocioso do Claude Code deve marcar isThinking = false');
|
||
assert.strictEqual(r2.details, 'Claude Code pronto');
|
||
});
|
||
|
||
await t.test('12. Menu Interativo do Antigravity CLI (Switch Model) com cursor >', () => {
|
||
const agyMenu = `
|
||
Switch Model
|
||
|
||
Search: █
|
||
|
||
Gemini 4 Argon
|
||
Gemini 4 Hydrogen
|
||
> Orchestrator (Argon) (current)
|
||
Gemini 3.8 Flash
|
||
Claude Opus 5.5
|
||
Claude Sonnet 5.5
|
||
GPT-OSS 120B (Medium)
|
||
Gemini 4 Carbon
|
||
|
||
Keyboard: ↑/↓ Navigate enter Select esc Go Back
|
||
`;
|
||
const menu = detectInteractiveMenu(agyMenu);
|
||
assert.strictEqual(menu.hasInteractiveMenu, true);
|
||
assert.strictEqual(menu.axis, 'vertical');
|
||
assert.strictEqual(menu.menuTitle, 'Switch Model');
|
||
assert.strictEqual(menu.selectedIndex, 2);
|
||
assert.strictEqual(menu.options.length, 8);
|
||
assert.strictEqual(menu.options[0].label, 'Gemini 4 Argon');
|
||
assert.strictEqual(menu.options[2].label, 'Orchestrator (Argon) (current)');
|
||
assert.strictEqual(menu.options[2].selected, true);
|
||
assert.ok(menu.rawHint.includes('Keyboard: ↑/↓ Navigate'));
|
||
|
||
const r = detectTerminalActivity(agyMenu);
|
||
assert.strictEqual(r.hasInteractiveMenu, true);
|
||
assert.strictEqual(r.isThinking, false, 'Menu interativo aberto nunca deve marcar isThinking=true');
|
||
assert.strictEqual(r.details, 'Aguardando seleção em menu interativo');
|
||
assert.strictEqual(r.interactiveMenu.selectedIndex, 2);
|
||
});
|
||
|
||
await t.test('13. Menu de Aprovação no Kiro/Kilo CLI com cursor ❯ e rodapé esc to close', () => {
|
||
const kiroMenu = `
|
||
Verificar se o Kilo já está instalado requires approval
|
||
shell → Get-Command kilo,kilocode -ErrorAction SilentlyContinue | Select-Object Name,Source; node --version
|
||
|
||
❯ Allow once
|
||
Deny once
|
||
Create allow rule to approve future similar actions
|
||
Create deny rule to block future similar actions
|
||
|
||
esc to close · ↑↓ to navigate · ↵ to select · Tab to edit
|
||
`;
|
||
const r = detectTerminalActivity(kiroMenu);
|
||
assert.strictEqual(r.hasInteractiveMenu, true);
|
||
assert.strictEqual(r.isThinking, false);
|
||
assert.strictEqual(r.details, 'Aguardando seleção em menu interativo');
|
||
assert.strictEqual(r.interactiveMenu.selectedIndex, 0);
|
||
assert.strictEqual(r.interactiveMenu.options.length, 4);
|
||
assert.strictEqual(r.interactiveMenu.options[0].label, 'Allow once');
|
||
assert.strictEqual(r.interactiveMenu.options[0].selected, true);
|
||
assert.strictEqual(r.interactiveMenu.options[3].label, 'Create deny rule to block future similar actions');
|
||
assert.ok(r.interactiveMenu.rawHint.includes('esc to close'));
|
||
});
|
||
|
||
await t.test('14. Menu do Claude Code (Do you want to proceed?) tem precedência sobre spinner/running command', () => {
|
||
const claudeMenu = `
|
||
⠋ Running command...
|
||
Do you want to proceed?
|
||
❯ 1. Yes
|
||
2. Yes, and don't ask again for this command
|
||
3. No, and tell Claude what to do differently (esc)
|
||
|
||
Enter to confirm · Esc to cancel
|
||
`;
|
||
const r = detectTerminalActivity(claudeMenu);
|
||
assert.strictEqual(r.hasAiActivity, true);
|
||
assert.strictEqual(r.aiType, 'claude');
|
||
assert.strictEqual(r.hasInteractiveMenu, true);
|
||
assert.strictEqual(r.isThinking, false, 'Precedência de menu sobre spinner acima');
|
||
assert.strictEqual(r.details, 'Aguardando seleção em menu interativo');
|
||
assert.strictEqual(r.interactiveMenu.menuTitle, 'Do you want to proceed?');
|
||
assert.strictEqual(r.interactiveMenu.selectedIndex, 0);
|
||
assert.strictEqual(r.interactiveMenu.options.length, 3);
|
||
assert.strictEqual(r.interactiveMenu.options[0].numberPrefix, '1');
|
||
assert.strictEqual(r.interactiveMenu.options[1].numberPrefix, '2');
|
||
assert.strictEqual(r.interactiveMenu.options[2].numberPrefix, '3');
|
||
});
|
||
|
||
await t.test('15. Menus com ANSI colors e não falso-positivo em histórico > /model', () => {
|
||
const ansiMenu = `\x1B[1mSwitch Model\x1B[0m\n\n Gemini 4 Argon\n\x1B[36m>\x1B[0m \x1B[1mGemini 3.8 Flash\x1B[0m\n\n\x1B[2mKeyboard: ↑/↓ Navigate enter Select esc Go Back\x1B[0m`;
|
||
const menu = detectInteractiveMenu(ansiMenu);
|
||
assert.strictEqual(menu.hasInteractiveMenu, true);
|
||
assert.strictEqual(menu.selectedIndex, 1);
|
||
assert.strictEqual(menu.options[1].label, 'Gemini 3.8 Flash');
|
||
|
||
const historyNotMenu = `
|
||
> /model
|
||
L Model set to Gemini 3.8 Flash
|
||
>
|
||
? for shortcuts
|
||
`;
|
||
const noMenu = detectInteractiveMenu(historyNotMenu);
|
||
assert.strictEqual(noMenu.hasInteractiveMenu, false);
|
||
assert.strictEqual(noMenu.selectedIndex, -1);
|
||
assert.deepStrictEqual(noMenu.options, []);
|
||
|
||
const emptyNull = detectInteractiveMenu(null);
|
||
assert.strictEqual(emptyNull.hasInteractiveMenu, false);
|
||
const emptyStr = detectInteractiveMenu('');
|
||
assert.strictEqual(emptyStr.hasInteractiveMenu, false);
|
||
|
||
const approvalThenSlashModel = `Tool requires approval\n> /model\nL Model set to Gemini`;
|
||
assert.strictEqual(detectInteractiveMenu(approvalThenSlashModel).hasInteractiveMenu, false);
|
||
});
|
||
|
||
await t.test('16. Menu Horizontal do Kilo CLI (Permission required) sem ANSI e com destaque ANSI', () => {
|
||
const kiloHorizPlain = `
|
||
△ Permission required
|
||
# Verifica conectividade com a internet via ping.
|
||
$ ping -n 4 google.com
|
||
|
||
Allow once Allow always Reject ctrl+f fullscreen ⇆ select enter confirm
|
||
`;
|
||
const menuPlain = detectInteractiveMenu(kiloHorizPlain);
|
||
assert.strictEqual(menuPlain.hasInteractiveMenu, true);
|
||
assert.strictEqual(menuPlain.axis, 'horizontal');
|
||
assert.ok(menuPlain.menuTitle.includes('Permission required'));
|
||
assert.strictEqual(menuPlain.selectedIndex, 0, 'Sem destaque ANSI deve fazer fallback para índice 0');
|
||
assert.strictEqual(menuPlain.options.length, 3);
|
||
assert.deepStrictEqual(
|
||
menuPlain.options.map(o => o.label),
|
||
['Allow once', 'Allow always', 'Reject']
|
||
);
|
||
assert.strictEqual(menuPlain.options[0].selected, true);
|
||
assert.strictEqual(menuPlain.options[1].selected, false);
|
||
assert.ok(menuPlain.rawHint.includes('⇆ select'));
|
||
|
||
const actPlain = detectTerminalActivity(kiloHorizPlain);
|
||
assert.strictEqual(actPlain.hasInteractiveMenu, true);
|
||
assert.strictEqual(actPlain.isThinking, false);
|
||
assert.strictEqual(actPlain.aiType, 'kiro');
|
||
assert.strictEqual(actPlain.details, 'Aguardando seleção em menu interativo');
|
||
|
||
// Com escape ANSI de fundo reverso (\x1B[7m) destacando a 2ª opção ("Allow always")
|
||
const kiloHorizReverse = `△ Permission required\n$ ping -n 4 google.com\n\nAllow once \x1B[7mAllow always\x1B[0m Reject ctrl+f fullscreen ⇆ select enter confirm`;
|
||
const menuRev = detectInteractiveMenu(kiloHorizReverse);
|
||
assert.strictEqual(menuRev.hasInteractiveMenu, true);
|
||
assert.strictEqual(menuRev.axis, 'horizontal');
|
||
assert.strictEqual(menuRev.selectedIndex, 1);
|
||
assert.strictEqual(menuRev.options[1].selected, true);
|
||
assert.strictEqual(menuRev.options[1].label, 'Allow always');
|
||
|
||
// Com escape ANSI de cor de fundo 256/RGB (\x1B[48;...) destacando a 3ª opção ("Reject")
|
||
const kiloHorizBg = `△ Permission required\n$ ping -n 4 google.com\n\nAllow once Allow always \x1B[48;5;214;30mReject\x1B[0m ctrl+f fullscreen ⇆ select enter confirm`;
|
||
const menuBg = detectInteractiveMenu(kiloHorizBg);
|
||
assert.strictEqual(menuBg.hasInteractiveMenu, true);
|
||
assert.strictEqual(menuBg.axis, 'horizontal');
|
||
assert.strictEqual(menuBg.selectedIndex, 2);
|
||
assert.strictEqual(menuBg.options[2].selected, true);
|
||
assert.strictEqual(menuBg.options[2].label, 'Reject');
|
||
});
|
||
|
||
await t.test('17. Evita falso positivo com bullet ● em execução pós-aprovação e acerta 2 opções ANSI distintas', () => {
|
||
const runningAfterApproval = `
|
||
△ Permission required
|
||
$ git status
|
||
|
||
● Ran (git status)
|
||
● Explored src/utils
|
||
⠋ Working...
|
||
`;
|
||
const activeActivity = detectTerminalActivity(runningAfterApproval);
|
||
assert.strictEqual(activeActivity.hasInteractiveMenu, false, 'Saída normal com ● Ran e spinner não é menu interativo');
|
||
assert.strictEqual(activeActivity.isThinking, true, 'Spinner ativo sem rodapé TUI deve manter isThinking = true');
|
||
assert.strictEqual(activeActivity.interactiveMenu, null);
|
||
|
||
// Bullet genérico ● após menção a aprovação sem rodapé TUI também não pode ativar menu
|
||
const bulletWithoutFooter = `△ Permission required\n● Verificando dependências no workspace\n Item auxiliar`;
|
||
assert.strictEqual(detectInteractiveMenu(bulletWithoutFooter).hasInteractiveMenu, false, 'Bullet ● sem rodapé TUI não deve ser interpretado como cursor de menu');
|
||
|
||
// Menu horizontal de 2 opções onde ambas possuem fundo ANSI distinto (escuro 236 vs destaque âmbar 214)
|
||
const twoOptionBg = `△ Permission required\n$ git push\n\n\x1B[48;5;236mAllow once\x1B[0m \x1B[48;5;214mReject\x1B[0m ctrl+f fullscreen ⇆ select enter confirm`;
|
||
const twoOptMenu = detectInteractiveMenu(twoOptionBg);
|
||
assert.strictEqual(twoOptMenu.hasInteractiveMenu, true);
|
||
assert.strictEqual(twoOptMenu.axis, 'horizontal');
|
||
assert.strictEqual(twoOptMenu.selectedIndex, 1, 'Deve identificar opção com fundo de destaque em vez de escolher o primeiro fundo distinto');
|
||
assert.strictEqual(twoOptMenu.options[1].label, 'Reject');
|
||
assert.strictEqual(twoOptMenu.options[1].selected, true);
|
||
});
|
||
|
||
await t.test('18. Regressão Kilo CLI com borda de caixa (┃) e Always allow não desloca índices nem títulos', () => {
|
||
const kiloBoxedPermission = [
|
||
' ┃ △ Permission required',
|
||
' ┃ # List files in the current directory to identify build artifacts or project files.',
|
||
' ┃',
|
||
' ┃ $ Get-ChildItem -LiteralPath "."',
|
||
' ┃',
|
||
' ┃ Allow once Allow always Reject ctrl+f fullscreen ⇆ select enter confirm ',
|
||
' ┃'
|
||
].join('\n');
|
||
|
||
const menuBox = detectInteractiveMenu(kiloBoxedPermission);
|
||
assert.strictEqual(menuBox.hasInteractiveMenu, true);
|
||
assert.strictEqual(menuBox.axis, 'horizontal');
|
||
assert.strictEqual(menuBox.selectedIndex, 0);
|
||
assert.ok(menuBox.menuTitle.includes('Permission required'));
|
||
assert.strictEqual(menuBox.menuTitle.includes('┃'), false);
|
||
assert.deepStrictEqual(
|
||
menuBox.options.map(o => o.label),
|
||
['Allow once', 'Allow always', 'Reject'],
|
||
'Borda de caixa ┃ não pode entrar como opção 0 do menu'
|
||
);
|
||
|
||
// Verifica preservação exata dos offsets ANSI com barra amarela + botões coloridos
|
||
const kiloBoxedAnsi =
|
||
' \x1B[33m┃\x1B[0m \x1B[33m△\x1B[0m Permission required\n' +
|
||
' \x1B[33m┃\x1B[0m $ Get-ChildItem -LiteralPath "."\n' +
|
||
' \x1B[33m┃\x1B[0m \x1B[48;5;236mAllow once\x1B[0m \x1B[48;5;214;30mAllow always\x1B[0m \x1B[48;5;236mReject\x1B[0m ctrl+f fullscreen ⇆ select enter confirm \n' +
|
||
' └─────────────────────────────────────────────────────────────────────────────┘';
|
||
const menuAnsiBox = detectInteractiveMenu(kiloBoxedAnsi);
|
||
assert.strictEqual(menuAnsiBox.hasInteractiveMenu, true);
|
||
assert.deepStrictEqual(menuAnsiBox.options.map(o => o.label), ['Allow once', 'Allow always', 'Reject']);
|
||
assert.strictEqual(menuAnsiBox.selectedIndex, 1, 'Offset ANSI com prefixo ┃ deve localizar destaque na opção Allow always');
|
||
assert.strictEqual(menuAnsiBox.options[1].selected, true);
|
||
|
||
// Caso Always allow com lista de ferramentas "- Get-ChildItem *" antes de Confirm / Cancel
|
||
const kiloAlwaysAllow = [
|
||
' ┃ △ Always allow',
|
||
' ┃ - Get-ChildItem *',
|
||
' ┃ Confirm Cancel ⇆ select enter confirm ',
|
||
' ┃'
|
||
].join('\n');
|
||
const menuAlways = detectInteractiveMenu(kiloAlwaysAllow);
|
||
assert.strictEqual(menuAlways.hasInteractiveMenu, true);
|
||
assert.strictEqual(menuAlways.axis, 'horizontal');
|
||
assert.deepStrictEqual(menuAlways.options.map(o => o.label), ['Confirm', 'Cancel']);
|
||
assert.strictEqual(menuAlways.selectedIndex, 0);
|
||
assert.ok(menuAlways.menuTitle.includes('Always allow'), `Título esperado contendo "Always allow", recebido "${menuAlways.menuTitle}"`);
|
||
assert.strictEqual(menuAlways.menuTitle.includes('Get-ChildItem'), false);
|
||
|
||
// Fallback de título sem RE_APPROVAL_HEADER deve pular item de lista "- Get-ChildItem *" (inclusive com linha vazia ┃ separadora)
|
||
const kiloFallbackTitle = [
|
||
' ┃ Escopo permanente',
|
||
' ┃ - Get-ChildItem *',
|
||
' ┃ Confirm Cancel',
|
||
' ┃',
|
||
' ┃ ⇆ select enter confirm',
|
||
' ┃'
|
||
].join('\n');
|
||
const menuTwoLineBox = detectInteractiveMenu(kiloFallbackTitle);
|
||
assert.strictEqual(menuTwoLineBox.hasInteractiveMenu, true);
|
||
assert.deepStrictEqual(menuTwoLineBox.options.map(o => o.label), ['Confirm', 'Cancel']);
|
||
assert.strictEqual(menuTwoLineBox.menuTitle, 'Escopo permanente');
|
||
|
||
// Pipe/borda intermediária entre opções deve ser filtrada; linha anterior com múltiplos espaços não deve sobrescrever barra inline
|
||
const kiloMidPipeAndPrevTwoSpaces = [
|
||
' ┃ △ Permission required',
|
||
' ┃ $ echo hello world',
|
||
' ┃ Confirm │ Cancel ⇆ select enter confirm'
|
||
].join('\n');
|
||
const menuMidPipe = detectInteractiveMenu(kiloMidPipeAndPrevTwoSpaces);
|
||
assert.strictEqual(menuMidPipe.hasInteractiveMenu, true);
|
||
assert.deepStrictEqual(menuMidPipe.options.map(o => o.label), ['Confirm', 'Cancel']);
|
||
|
||
// Linha anterior apenas com espaços simples antes de rodapé horizontal sem opções inline não deve virar menu horizontal
|
||
const singleSpaceProseBeforeFooter = ' Texto normal sem separador duplo\n ⇆ select enter confirm';
|
||
assert.strictEqual(detectInteractiveMenu(singleSpaceProseBeforeFooter).axis === 'horizontal', false);
|
||
|
||
// Rodapé horizontal isolado na linha 0 sem opções não deve gerar menu horizontal nem opções fantasma
|
||
const footerOnlyLineZero = detectInteractiveMenu('ctrl+f fullscreen ⇆ select enter confirm');
|
||
assert.strictEqual(footerOnlyLineZero.axis === 'horizontal', false);
|
||
assert.strictEqual(footerOnlyLineZero.options.length, 0);
|
||
});
|
||
|
||
await t.test('19. Kiro CLI moderno (trabalhando com Pac-Man/Thinking.../Kiro is working, ocioso com Credits e prompt ›/ask) e subagente AGY', () => {
|
||
const kiroWorkingTrace = [
|
||
'The file will have its original line endings in your working directory',
|
||
'ᗥ Thinking... (esc to cancel)',
|
||
'› Kiro is working · 1m 47s · Type to steer · Ctrl+S to queue'
|
||
].join('\n');
|
||
const actWorking = detectTerminalActivity(kiroWorkingTrace);
|
||
assert.strictEqual(actWorking.hasAiActivity, true);
|
||
assert.strictEqual(actWorking.aiType, 'kiro');
|
||
assert.strictEqual(actWorking.isThinking, true);
|
||
|
||
const kiroPacManSpinnerOnly = [
|
||
'Kiro CLI session',
|
||
'ᗧ Analisando arquivos do projeto'
|
||
].join('\n');
|
||
const actPacMan = detectTerminalActivity(kiroPacManSpinnerOnly);
|
||
assert.strictEqual(actPacMan.hasAiActivity, true);
|
||
assert.strictEqual(actPacMan.aiType, 'kiro');
|
||
assert.strictEqual(actPacMan.isThinking, true);
|
||
|
||
const kiroIdleUnicode = [
|
||
'Running command npm test',
|
||
'The file will have its original line endings in your working directory',
|
||
'▸ Credits: turn 4.76 • session 101.34 | Time: 33s',
|
||
'Default · claude-sonnet-5.5 · medium · ◑ 36%',
|
||
'› ask a question or describe a task ↵'
|
||
].join('\n');
|
||
const actIdleUnicode = detectTerminalActivity(kiroIdleUnicode);
|
||
assert.strictEqual(actIdleUnicode.hasAiActivity, true);
|
||
assert.strictEqual(actIdleUnicode.aiType, 'kiro');
|
||
assert.strictEqual(actIdleUnicode.isThinking, false);
|
||
assert.strictEqual(actIdleUnicode.details, 'Kiro CLI pronto');
|
||
|
||
const kiroIdleAscii = [
|
||
'Tasks restantes: nenhuma.',
|
||
'▸ Credits: turn 2.41 • session 115.28 | Time: 37s',
|
||
'Default · claude-sonnet-5.5 · medium · ◒ 39%',
|
||
'> Ask a question or describe a task ↵'
|
||
].join('\n');
|
||
const actIdleAscii = detectTerminalActivity(kiroIdleAscii);
|
||
assert.strictEqual(actIdleAscii.hasAiActivity, true);
|
||
assert.strictEqual(actIdleAscii.aiType, 'kiro');
|
||
assert.strictEqual(actIdleAscii.isThinking, false);
|
||
|
||
const agySubagentTrace = [
|
||
'>',
|
||
'● Agent(self: Builder hotfix) · 3m1s',
|
||
'? for shortcuts auto · Orchestrator (Argon) · 1 subagent(s)'
|
||
].join('\n');
|
||
const actAgySubagent = detectTerminalActivity(agySubagentTrace);
|
||
assert.strictEqual(actAgySubagent.hasAiActivity, true);
|
||
assert.strictEqual(actAgySubagent.aiType, 'agy');
|
||
assert.strictEqual(actAgySubagent.isThinking, true);
|
||
|
||
const agySubagentNoFooterCount = [
|
||
'>',
|
||
'● Agent(self: Reviewer) · 1m0s',
|
||
'? for shortcuts auto · Orchestrator (Argon)'
|
||
].join('\n');
|
||
assert.strictEqual(detectTerminalActivity(agySubagentNoFooterCount).isThinking, true);
|
||
|
||
const agySubagentFooterOnly = [
|
||
'● Running background step',
|
||
'>',
|
||
'? for shortcuts auto · 1 subagent(s)'
|
||
].join('\n');
|
||
assert.strictEqual(detectTerminalActivity(agySubagentFooterOnly).isThinking, true);
|
||
|
||
const agyIdleClean = [
|
||
'Tarefa concluída com sucesso.',
|
||
'>',
|
||
'? for shortcuts auto · Orchestrator (Argon)'
|
||
].join('\n');
|
||
const actAgyIdle = detectTerminalActivity(agyIdleClean);
|
||
assert.strictEqual(actAgyIdle.hasAiActivity, true);
|
||
assert.strictEqual(actAgyIdle.aiType, 'agy');
|
||
assert.strictEqual(actAgyIdle.isThinking, false);
|
||
});
|
||
|
||
await t.test('20. Menus de Seleção de Modelos TUI (Switch Model no Antigravity e Select model/variant no Kilo CLI)', () => {
|
||
// 20.1 Antigravity CLI: Switch Model com cursor > e rodapé com atalhos
|
||
const agySwitchModel = [
|
||
'Switch Model',
|
||
'',
|
||
' Search: ',
|
||
' ────────────────────',
|
||
'',
|
||
' Gemini 4 Argon',
|
||
' Gemini 4 Hydrogen',
|
||
' Orchestrator (Argon)',
|
||
'> Gemini 3.8 Flash (current)',
|
||
' Claude Opus 5.5',
|
||
' Claude Sonnet 5.5',
|
||
' GPT-OSS 120B (Medium)',
|
||
' Gemini 4 Carbon ',
|
||
'',
|
||
' Effort ◂ ●━━━━━━━━━━━━━━◉──────────────○ ▸',
|
||
' low medium high ',
|
||
' Balanced speed and reasoning quality for most tasks',
|
||
'',
|
||
'Keyboard: ↑/↓ Navigate ←/→ Effort enter Select esc Go Back',
|
||
'',
|
||
' auto · Gemini 3.8 Flash · medium'
|
||
].join('\n');
|
||
const agyMenu = detectInteractiveMenu(agySwitchModel);
|
||
assert.strictEqual(agyMenu.hasInteractiveMenu, true);
|
||
assert.strictEqual(agyMenu.axis, 'vertical');
|
||
assert.strictEqual(agyMenu.menuTitle, 'Switch Model');
|
||
assert.strictEqual(agyMenu.selectedIndex, 3);
|
||
assert.strictEqual(agyMenu.options.length, 8);
|
||
assert.strictEqual(agyMenu.options[0].label, 'Gemini 4 Argon');
|
||
assert.strictEqual(agyMenu.options[3].label, 'Gemini 3.8 Flash (current)');
|
||
assert.strictEqual(agyMenu.options[3].selected, true);
|
||
|
||
// 20.2 Kilo/Kiro CLI: Select model com cabeçalho, categorias, bullet ● e atalhos ctrl+a / ctrl+f
|
||
const kiloSelectModel = [
|
||
' Select model esc ',
|
||
'',
|
||
' Search ',
|
||
'',
|
||
' Recent ',
|
||
' ● Gemini 3.1 Flash Lite (LiteLLM) OmniRoute (chaves Gemini via LiteLLM) ',
|
||
' NVIDIA: Nemotron 3 Ultra (free) Kilo Gateway May train ',
|
||
'',
|
||
' Recommended ',
|
||
' Auto Efficient ',
|
||
' Auto Free May train ',
|
||
' NVIDIA: Nemotron 3.5 Super VL (free) May train ',
|
||
' Glyph Cluster May train ',
|
||
' Anthropic: Claude Opus 5.5 ',
|
||
'',
|
||
' Connect provider ctrl+a Favorite ctrl+f ',
|
||
'',
|
||
' ● Tip Define custom formatter commands with file extensions in config ',
|
||
'',
|
||
' D:\\Desenvolvimento\\maestri-remote:master 7.8.27 '
|
||
].join('\n');
|
||
const kiloMenu = detectInteractiveMenu(kiloSelectModel);
|
||
assert.strictEqual(kiloMenu.hasInteractiveMenu, true);
|
||
assert.strictEqual(kiloMenu.axis, 'vertical');
|
||
assert.strictEqual(kiloMenu.menuTitle, 'Select model');
|
||
assert.strictEqual(kiloMenu.selectedIndex, 0);
|
||
assert.strictEqual(kiloMenu.options.length, 7);
|
||
assert.strictEqual(kiloMenu.options[0].label, 'Gemini 3.1 Flash Lite (LiteLLM) OmniRoute (chaves Gemini via LiteLLM)');
|
||
assert.strictEqual(kiloMenu.options[0].selected, true);
|
||
assert.strictEqual(kiloMenu.options[1].label, 'NVIDIA: Nemotron 3 Ultra (free) Kilo Gateway');
|
||
assert.strictEqual(kiloMenu.options[1].selected, false);
|
||
assert.strictEqual(kiloMenu.options[6].label, 'Anthropic: Claude Opus 5.5');
|
||
assert.strictEqual(kiloMenu.rawHint, 'Connect provider ctrl+a Favorite ctrl+f');
|
||
|
||
// 20.3 Detecção determinística de atividade de terminal em menus de modelo deve forçar isThinking = false
|
||
const actAgyMenu = detectTerminalActivity(agySwitchModel);
|
||
assert.strictEqual(actAgyMenu.hasAiActivity, true);
|
||
assert.strictEqual(actAgyMenu.isThinking, false);
|
||
assert.strictEqual(actAgyMenu.hasInteractiveMenu, true);
|
||
assert.strictEqual(actAgyMenu.details, 'Aguardando seleção em menu interativo');
|
||
|
||
const actKiloMenu = detectTerminalActivity(kiloSelectModel);
|
||
assert.strictEqual(actKiloMenu.hasAiActivity, true);
|
||
assert.strictEqual(actKiloMenu.isThinking, false);
|
||
assert.strictEqual(actKiloMenu.hasInteractiveMenu, true);
|
||
});
|
||
|
||
await t.test('21. Menus de Esforço de Raciocínio TUI (Set Effort no Antigravity CLI com régua horizontal)', () => {
|
||
// 21.1 Set Effort com medium selecionado
|
||
const agyEffortMedium = [
|
||
'Set Effort',
|
||
'',
|
||
' ◂ ●━━━━━━━━━━━━━━◉──────────────○ ▸',
|
||
' low medium high ',
|
||
' Balanced speed and reasoning quality for most tasks (current)',
|
||
'',
|
||
'Keyboard: ←/→ Effort enter Select esc Go Back',
|
||
'',
|
||
' auto · Gemini 3.8 Flash · medium'
|
||
].join('\n');
|
||
const menuMedium = detectInteractiveMenu(agyEffortMedium);
|
||
assert.strictEqual(menuMedium.hasInteractiveMenu, true);
|
||
assert.strictEqual(menuMedium.axis, 'horizontal');
|
||
assert.strictEqual(menuMedium.menuTitle, 'Set Effort');
|
||
assert.strictEqual(menuMedium.selectedIndex, 1);
|
||
assert.strictEqual(menuMedium.options.length, 3);
|
||
assert.strictEqual(menuMedium.options[0].label, 'low');
|
||
assert.strictEqual(menuMedium.options[1].label, 'medium');
|
||
assert.strictEqual(menuMedium.options[1].selected, true);
|
||
assert.strictEqual(menuMedium.options[2].label, 'high');
|
||
assert.strictEqual(menuMedium.options[2].selected, false);
|
||
|
||
// 21.2 Set Effort com high selecionado
|
||
const agyEffortHigh = [
|
||
'Set Effort',
|
||
'',
|
||
' ◂ ●━━━━━━━━━━━━━━●━━━━━━━━━━━━━━◉ ▸',
|
||
' low medium high ',
|
||
' Deeper reasoning for complex problems — slower but stronger (current)',
|
||
'',
|
||
'Keyboard: ←/→ Effort enter Select esc Go Back'
|
||
].join('\n');
|
||
const menuHigh = detectInteractiveMenu(agyEffortHigh);
|
||
assert.strictEqual(menuHigh.hasInteractiveMenu, true);
|
||
assert.strictEqual(menuHigh.axis, 'horizontal');
|
||
assert.strictEqual(menuHigh.selectedIndex, 2);
|
||
assert.strictEqual(menuHigh.options[2].selected, true);
|
||
|
||
// 21.3 Set Effort com low selecionado
|
||
const agyEffortLow = [
|
||
'Set Effort',
|
||
'',
|
||
' ◂ ◉━━━━━━━━━━━━━━○──────────────○ ▸',
|
||
' low medium high ',
|
||
' Quick and concise responses for simple queries (current)',
|
||
'',
|
||
'Keyboard: ←/→ Effort enter Select esc Go Back'
|
||
].join('\n');
|
||
const menuLow = detectInteractiveMenu(agyEffortLow);
|
||
assert.strictEqual(menuLow.hasInteractiveMenu, true);
|
||
assert.strictEqual(menuLow.axis, 'horizontal');
|
||
assert.strictEqual(menuLow.selectedIndex, 0);
|
||
assert.strictEqual(menuLow.options[0].selected, true);
|
||
|
||
// 21.4 detectTerminalActivity com Set Effort força isThinking = false e ativa hasInteractiveMenu
|
||
const actEffort = detectTerminalActivity(agyEffortMedium);
|
||
assert.strictEqual(actEffort.hasAiActivity, true);
|
||
assert.strictEqual(actEffort.isThinking, false);
|
||
assert.strictEqual(actEffort.hasInteractiveMenu, true);
|
||
});
|
||
|
||
await t.test('22. Painel de Controles do Kiro CLI (Model Controls / tab to switch panels) e guarda contra opções vazias', () => {
|
||
// 22.1 Tela real capturada do Kiro CLI com controles de modelo
|
||
const kiroControlsScreen = [
|
||
'sonnet-3.5 tab to switch panels',
|
||
' thinking n/a Not available for this model.',
|
||
' effort medium Sets deliberation level. Higher levels help with complex tasks, but i...',
|
||
' fallback claude-sonnet-5 Answers for this model when it refuses or is unavailable.',
|
||
'esc to go back · ↑↓ to navigate · ↵ to select · ↑ at top for controls · tab to switch panels'
|
||
].join('\n');
|
||
|
||
const kiroMenu = detectInteractiveMenu(kiroControlsScreen);
|
||
assert.strictEqual(kiroMenu.hasInteractiveMenu, true);
|
||
assert.strictEqual(kiroMenu.axis, 'vertical');
|
||
assert.strictEqual(kiroMenu.menuTitle, 'sonnet-3.5');
|
||
assert.strictEqual(kiroMenu.selectedIndex, 1); // default effort
|
||
assert.strictEqual(kiroMenu.options.length, 3);
|
||
assert.strictEqual(kiroMenu.options[0].label, 'thinking: n/a');
|
||
assert.strictEqual(kiroMenu.options[1].label, 'effort: medium');
|
||
assert.strictEqual(kiroMenu.options[1].selected, true);
|
||
assert.strictEqual(kiroMenu.options[2].label, 'fallback: claude-sonnet-5');
|
||
|
||
// 22.2 Classificação de aiType deve ser determinística como 'kiro'
|
||
const kiroAct = detectTerminalActivity(kiroControlsScreen);
|
||
assert.strictEqual(kiroAct.hasAiActivity, true);
|
||
assert.strictEqual(kiroAct.aiType, 'kiro');
|
||
assert.strictEqual(kiroAct.isThinking, false);
|
||
assert.strictEqual(kiroAct.hasInteractiveMenu, true);
|
||
|
||
// 22.3 Terminal com rodapé mas sem opções NÃO pode retornar hasInteractiveMenu: true com options: []
|
||
const emptyFooterScreen = [
|
||
'Some random message here',
|
||
'esc to go back · ↑↓ to navigate · ↵ to select'
|
||
].join('\n');
|
||
const emptyMenu = detectInteractiveMenu(emptyFooterScreen);
|
||
assert.strictEqual(emptyMenu.hasInteractiveMenu, false);
|
||
assert.deepStrictEqual(emptyMenu.options, []);
|
||
});
|
||
|
||
await t.test('23. Kiro CLI moderno com tela mista de Select model e Settings for model (prioriza lista de modelos)', () => {
|
||
// 23.1 Tela completa do Kiro CLI com busca de modelo, lista de modelos e painel de controles no rodapé
|
||
const kiroFullModelScreen = [
|
||
' Select model: type to search esc',
|
||
'',
|
||
' Recent',
|
||
'● claude-3-5-sonnet-20241022 Anthropic Claude 3.5 Sonnet',
|
||
' gemini-2.0-flash-exp Google Gemini 2.0 Flash',
|
||
' gpt-4o OpenAI GPT-4o',
|
||
'──────────────────────────────────────────────────────────────────────────────────────',
|
||
'Settings for model: claude-3-5-sonnet-20241022 tab to switch panels',
|
||
' thinking: n/a',
|
||
' effort: medium',
|
||
' fallback: none',
|
||
'esc to go back · ↑↓ to navigate · ↵ to select · tab to switch panels'
|
||
].join('\n');
|
||
|
||
const menu = detectInteractiveMenu(kiroFullModelScreen);
|
||
assert.strictEqual(menu.hasInteractiveMenu, true);
|
||
assert.strictEqual(menu.axis, 'vertical');
|
||
assert.strictEqual(menu.menuTitle, 'Select model');
|
||
assert.strictEqual(menu.selectedIndex, 0);
|
||
assert.strictEqual(menu.options.length, 3);
|
||
assert.strictEqual(menu.options[0].label, 'claude-3-5-sonnet-20241022 Anthropic Claude 3.5 Sonnet');
|
||
assert.strictEqual(menu.options[0].selected, true);
|
||
assert.strictEqual(menu.options[1].label, 'gemini-2.0-flash-exp Google Gemini 2.0 Flash');
|
||
assert.strictEqual(menu.options[2].label, 'gpt-4o OpenAI GPT-4o');
|
||
|
||
// 23.2 Classificação de atividade não confunde com pensando
|
||
const act = detectTerminalActivity(kiroFullModelScreen);
|
||
assert.strictEqual(act.hasAiActivity, true);
|
||
assert.strictEqual(act.aiType, 'kiro');
|
||
assert.strictEqual(act.isThinking, false);
|
||
assert.strictEqual(act.hasInteractiveMenu, true);
|
||
});
|
||
|
||
await t.test('24. Kiro CLI /effort com tela mista de Select model e foco ativo em Settings for model (prioriza controles)', () => {
|
||
const kiroEffortScreen = [
|
||
' Select model: type to search esc',
|
||
'',
|
||
' Recent',
|
||
'● claude-sonnet-4 Anthropic Claude Sonnet 4',
|
||
' gemini-2.5-pro Google Gemini 2.5 Pro',
|
||
'──────────────────────────────────────────────────────────────────────────────────────',
|
||
'Settings for model: claude-sonnet-4 tab to switch panels',
|
||
' thinking n/a Not available for this model.',
|
||
'❯ effort medium Sets deliberation level.',
|
||
' fallback none Answers for this model when it refuses or is unavailable.',
|
||
'esc to go back · ↑↓ to navigate · ←→ to toggle · ↵ back to models · tab to switch panels'
|
||
].join('\n');
|
||
|
||
const menu = detectInteractiveMenu(kiroEffortScreen);
|
||
assert.strictEqual(menu.hasInteractiveMenu, true);
|
||
assert.strictEqual(menu.axis, 'vertical');
|
||
assert.strictEqual(menu.menuTitle, 'Settings for model: claude-sonnet-4');
|
||
assert.strictEqual(menu.selectedIndex, 1);
|
||
assert.strictEqual(menu.options.length, 3);
|
||
assert.strictEqual(menu.options[0].label, 'thinking: n/a');
|
||
assert.strictEqual(menu.options[1].label, 'effort: medium');
|
||
assert.strictEqual(menu.options[1].selected, true);
|
||
assert.strictEqual(menu.options[2].label, 'fallback: none');
|
||
|
||
const act = detectTerminalActivity(kiroEffortScreen);
|
||
assert.strictEqual(act.hasAiActivity, true);
|
||
assert.strictEqual(act.aiType, 'kiro');
|
||
assert.strictEqual(act.isThinking, false);
|
||
assert.strictEqual(act.hasInteractiveMenu, true);
|
||
});
|
||
});
|