feat: add Tab key to cycle through thinking levels

- Add onTab callback to CustomEditor
- Implement cycleThinkingLevel() in TuiRenderer
- Only works when model supports reasoning
- Cycles through: off → minimal → low → medium → high → off
- Update footer to show current thinking level with '(tab to cycle)' hint
- Update header instructions to mention tab for thinking
- Show notification when thinking level changes
This commit is contained in:
Tino Ehrich 2025-11-19 10:18:24 +01:00
parent 1f68d6eb40
commit 9e8373b86a
3 changed files with 68 additions and 15 deletions

View file

@ -1,4 +1,4 @@
import type { Agent, AgentEvent, AgentState } from "@mariozechner/pi-agent";
import type { Agent, AgentEvent, AgentState, ThinkingLevel } from "@mariozechner/pi-agent";
import type { AssistantMessage, Message } from "@mariozechner/pi-ai";
import type { SlashCommand } from "@mariozechner/pi-tui";
import {
@ -169,6 +169,9 @@ export class TuiRenderer {
chalk.dim("ctrl+k") +
chalk.gray(" to delete line") +
"\n" +
chalk.dim("tab") +
chalk.gray(" to cycle thinking") +
"\n" +
chalk.dim("/") +
chalk.gray(" for commands") +
"\n" +
@ -210,6 +213,10 @@ export class TuiRenderer {
this.handleCtrlC();
};
this.editor.onTab = () => {
return this.cycleThinkingLevel();
};
// Handle editor submission
this.editor.onSubmit = async (text: string) => {
text = text.trim();
@ -572,6 +579,32 @@ export class TuiRenderer {
}
}
private cycleThinkingLevel(): boolean {
// Only cycle if model supports thinking
if (!this.agent.state.model?.reasoning) {
return false; // Not handled, let default Tab behavior continue
}
const levels: ThinkingLevel[] = ["off", "minimal", "low", "medium", "high"];
const currentLevel = this.agent.state.thinkingLevel || "off";
const currentIndex = levels.indexOf(currentLevel);
const nextIndex = (currentIndex + 1) % levels.length;
const nextLevel = levels[nextIndex];
// Apply the new thinking level
this.agent.setThinkingLevel(nextLevel);
// Save thinking level change to session
this.sessionManager.saveThinkingLevelChange(nextLevel);
// Show brief notification
this.chatContainer.addChild(new Spacer(1));
this.chatContainer.addChild(new Text(chalk.dim(`Thinking level: ${nextLevel}`), 1, 0));
this.ui.requestRender();
return true; // Handled
}
clearEditor(): void {
this.editor.setText("");
this.ui.requestRender();