Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

add fullscreen rendering mode with scrollable transcript (#316)

kt4f0112fd32a3
diff --git a/packages/ai/src/models.generated.ts b/packages/ai/src/models.generated.ts
index 1b3f1aeb95..8852e27e27 100644
--- a/packages/ai/src/models.generated.ts
+++ b/packages/ai/src/models.generated.ts
@@ -73,6 +73,24 @@ export const MODELS = {
contextWindow: 300000,
maxTokens: 8192,
} satisfies Model<"bedrock-converse-stream">,
+ "anthropic.claude-fable-5": {
+ id: "anthropic.claude-fable-5",
+ name: "Claude Fable 5",
+ api: "bedrock-converse-stream",
+ provider: "amazon-bedrock",
+ baseUrl: "https://bedrock-runtime.us-east-1.amazonaws.com",
+ reasoning: true,
+ thinkingLevelMap: {"off":null,"xhigh":"xhigh","max":"max"},
+ input: ["text", "image"],
+ cost: {
+ input: 10,
+ output: 50,
+ cacheRead: 1,
+ cacheWrite: 12.5,
+ },
+ contextWindow: 1000000,
+ maxTokens: 128000,
+ } satisfies Model<"bedrock-converse-stream">,
"anthropic.claude-haiku-4-5-20251001-v1:0": {
id: "anthropic.claude-haiku-4-5-20251001-v1:0",
name: "Claude Haiku 4.5",
@@ -213,6 +231,24 @@ export const MODELS = {
contextWindow: 1000000,
maxTokens: 64000,
} satisfies Model<"bedrock-converse-stream">,
+ "anthropic.claude-sonnet-5": {
+ id: "anthropic.claude-sonnet-5",
+ name: "Claude Sonnet 5",
+ api: "bedrock-converse-stream",
+ provider: "amazon-bedrock",
+ baseUrl: "https://bedrock-runtime.us-east-1.amazonaws.com",
+ reasoning: true,
+ thinkingLevelMap: {"xhigh":"xhigh","max":"max"},
+ input: ["text", "image"],
+ cost: {
+ input: 2,
+ output: 10,
+ cacheRead: 0.2,
+ cacheWrite: 2.5,
+ },
+ contextWindow: 1000000,
+ maxTokens: 128000,
+ } satisfies Model<"bedrock-converse-stream">,
"au.anthropic.claude-haiku-4-5-20251001-v1:0": {
id: "au.anthropic.claude-haiku-4-5-20251001-v1:0",
name: "Claude Haiku 4.5 (AU)",
@@ -301,6 +337,24 @@ export const MODELS = {
contextWindow: 1000000,
maxTokens: 128000,
} satisfies Model<"bedrock-converse-stream">,
+ "au.anthropic.claude-sonnet-5": {
+ id: "au.anthropic.claude-sonnet-5",
+ name: "Claude Sonnet 5 (AU)",
+ api: "bedrock-converse-stream",
+ provider: "amazon-bedrock",
+ baseUrl: "https://bedrock-runtime.us-east-1.amazonaws.com",
+ reasoning: true,
+ thinkingLevelMap: {"xhigh":"xhigh","max":"max"},
+ input: ["text", "image"],
+ cost: {
+ input: 2,
+ output: 10,
+ cacheRead: 0.2,
+ cacheWrite: 2.5,
+ },
+ contextWindow: 1000000,
+ maxTokens: 128000,
+ } satisfies Model<"bedrock-converse-stream">,
"deepseek.r1-v1:0": {
id: "deepseek.r1-v1:0",
name: "DeepSeek-R1",
@@ -493,6 +547,24 @@ export const MODELS = {
contextWindow: 1000000,
maxTokens: 64000,
} satisfies Model<"bedrock-converse-stream">,
+ "eu.anthropic.claude-sonnet-5": {
+ id: "eu.anthropic.claude-sonnet-5",
+ name: "Claude Sonnet 5 (EU)",
+ api: "bedrock-converse-stream",
+ provider: "amazon-bedrock",
+ baseUrl: "https://bedrock-runtime.eu-central-1.amazonaws.com",
+ reasoning: true,
+ thinkingLevelMap: {"xhigh":"xhigh","max":"max"},
+ input: ["text", "image"],
+ cost: {
+ input: 2.2,
+ output: 11,
+ cacheRead: 0.22,
+ cacheWrite: 2.75,
+ },
+ contextWindow: 1000000,
+ maxTokens: 128000,
+ } satisfies Model<"bedrock-converse-stream">,
"global.anthropic.claude-fable-5": {
id: "global.anthropic.claude-fable-5",
name: "Claude Fable 5 (Global)",
@@ -634,6 +706,24 @@ export const MODELS = {
contextWindow: 1000000,
maxTokens: 64000,
} satisfies Model<"bedrock-converse-stream">,
+ "global.anthropic.claude-sonnet-5": {
+ id: "global.anthropic.claude-sonnet-5",
+ name: "Claude Sonnet 5 (Global)",
+ api: "bedrock-converse-stream",
+ provider: "amazon-bedrock",
+ baseUrl: "https://bedrock-runtime.us-east-1.amazonaws.com",
+ reasoning: true,
+ thinkingLevelMap: {"xhigh":"xhigh","max":"max"},
+ input: ["text", "image"],
+ cost: {
+ input: 2,
+ output: 10,
+ cacheRead: 0.2,
+ cacheWrite: 2.5,
+ },
+ contextWindow: 1000000,
+ maxTokens: 128000,
+ } satisfies Model<"bedrock-converse-stream">,
"google.gemma-3-27b-it": {
id: "google.gemma-3-27b-it",
name: "Google Gemma 3 27B Instruct",
@@ -739,6 +829,24 @@ export const MODELS = {
contextWindow: 1000000,
maxTokens: 64000,
} satisfies Model<"bedrock-converse-stream">,
+ "jp.anthropic.claude-sonnet-5": {
+ id: "jp.anthropic.claude-sonnet-5",
+ name: "Claude Sonnet 5 (JP)",
+ api: "bedrock-converse-stream",
+ provider: "amazon-bedrock",
+ baseUrl: "https://bedrock-runtime.us-east-1.amazonaws.com",
+ reasoning: true,
+ thinkingLevelMap: {"xhigh":"xhigh","max":"max"},
+ input: ["text", "image"],
+ cost: {
+ input: 2,
+ output: 10,
+ cacheRead: 0.2,
+ cacheWrite: 2.5,
+ },
+ contextWindow: 1000000,
+ maxTokens: 128000,
+ } satisfies Model<"bedrock-converse-stream">,
"meta.llama3-1-70b-instruct-v1:0": {
id: "meta.llama3-1-70b-instruct-v1:0",
name: "Llama 3.1 70B Instruct",
@@ -1545,6 +1653,24 @@ export const MODELS = {
contextWindow: 1000000,
maxTokens: 64000,
} satisfies Model<"bedrock-converse-stream">,
+ "us.anthropic.claude-sonnet-5": {
+ id: "us.anthropic.claude-sonnet-5",
+ name: "Claude Sonnet 5 (US)",
+ api: "bedrock-converse-stream",
+ provider: "amazon-bedrock",
+ baseUrl: "https://bedrock-runtime.us-east-1.amazonaws.com",
+ reasoning: true,
+ thinkingLevelMap: {"xhigh":"xhigh","max":"max"},
+ input: ["text", "image"],
+ cost: {
+ input: 2,
+ output: 10,
+ cacheRead: 0.2,
+ cacheWrite: 2.5,
+ },
+ contextWindow: 1000000,
+ maxTokens: 128000,
+ } satisfies Model<"bedrock-converse-stream">,
"us.deepseek.r1-v1:0": {
id: "us.deepseek.r1-v1:0",
name: "DeepSeek-R1 (US)",
@@ -2096,6 +2222,24 @@ export const MODELS = {
contextWindow: 1000000,
maxTokens: 64000,
} satisfies Model<"anthropic-messages">,
+ "claude-sonnet-5": {
+ id: "claude-sonnet-5",
+ name: "Claude Sonnet 5",
+ api: "anthropic-messages",
+ provider: "anthropic",
+ baseUrl: "https://api.anthropic.com",
+ reasoning: true,
+ thinkingLevelMap: {"xhigh":"xhigh","max":"max"},
+ input: ["text", "image"],
+ cost: {
+ input: 2,
+ output: 10,
+ cacheRead: 0.2,
+ cacheWrite: 2.5,
+ },
+ contextWindow: 1000000,
+ maxTokens: 128000,
+ } satisfies Model<"anthropic-messages">,
},
"azure-openai-responses": {
"gpt-4": {
@@ -2838,6 +2982,23 @@ export const MODELS = {
} satisfies Model<"azure-openai-responses">,
},
"cerebras": {
+ "gemma-4-31b": {
+ id: "gemma-4-31b",
+ name: "Gemma 4 31B IT",
+ api: "openai-completions",
+ provider: "cerebras",
+ baseUrl: "https://api.cerebras.ai/v1",
+ reasoning: true,
+ input: ["text", "image"],
+ cost: {
+ input: 0.99,
+ output: 1.49,
+ cacheRead: 0,
+ cacheWrite: 0,
+ },
+ contextWindow: 131072,
+ maxTokens: 40960,
+ } satisfies Model<"openai-completions">,
"gpt-oss-120b": {
id: "gpt-oss-120b",
name: "GPT OSS 120B",
@@ -3168,6 +3329,24 @@ export const MODELS = {
contextWindow: 1000000,
maxTokens: 64000,
} satisfies Model<"anthropic-messages">,
+ "claude-sonnet-5": {
+ id: "claude-sonnet-5",
+ name: "Claude Sonnet 5",
+ api: "anthropic-messages",
+ provider: "cloudflare-ai-gateway",
+ baseUrl: "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/anthropic",
+ reasoning: true,
+ thinkingLevelMap: {"xhigh":"xhigh","max":"max"},
+ input: ["text", "image"],
+ cost: {
+ input: 2,
+ output: 10,
+ cacheRead: 0.2,
+ cacheWrite: 2.5,
+ },
+ contextWindow: 1000000,
+ maxTokens: 128000,
+ } satisfies Model<"anthropic-messages">,
"gpt-4": {
id: "gpt-4",
name: "GPT-4",
@@ -4242,6 +4421,26 @@ export const MODELS = {
contextWindow: 1000000,
maxTokens: 32000,
} satisfies Model<"anthropic-messages">,
+ "claude-sonnet-5": {
+ id: "claude-sonnet-5",
+ name: "Claude Sonnet 5",
+ api: "openai-completions",
+ provider: "github-copilot",
+ baseUrl: "https://api.individual.githubcopilot.com",
+ headers: {"User-Agent":"GitHubCopilotChat/0.35.0","Editor-Version":"vscode/1.107.0","Editor-Plugin-Version":"copilot-chat/0.35.0","Copilot-Integration-Id":"vscode-chat"},
+ compat: {"supportsStore":false,"supportsDeveloperRole":false,"supportsReasoningEffort":false},
+ reasoning: true,
+ thinkingLevelMap: {"xhigh":"xhigh","max":"max"},
+ input: ["text", "image"],
+ cost: {
+ input: 2,
+ output: 10,
+ cacheRead: 0.2,
+ cacheWrite: 2.5,
+ },
+ contextWindow: 1000000,
+ maxTokens: 128000,
+ } satisfies Model<"openai-completions">,
"gemini-2.5-pro": {
id: "gemini-2.5-pro",
name: "Gemini 2.5 Pro",
@@ -4489,6 +4688,44 @@ export const MODELS = {
contextWindow: 400000,
maxTokens: 128000,
} satisfies Model<"openai-responses">,
+ "kimi-k2.7-code": {
+ id: "kimi-k2.7-code",
+ name: "Kimi K2.7 Code",
+ api: "openai-completions",
+ provider: "github-copilot",
+ baseUrl: "https://api.individual.githubcopilot.com",
+ headers: {"User-Agent":"GitHubCopilotChat/0.35.0","Editor-Version":"vscode/1.107.0","Editor-Plugin-Version":"copilot-chat/0.35.0","Copilot-Integration-Id":"vscode-chat"},
+ compat: {"supportsStore":false,"supportsDeveloperRole":false,"supportsReasoningEffort":false},
+ reasoning: true,
+ input: ["text", "image"],
+ cost: {
+ input: 0.95,
+ output: 4,
+ cacheRead: 0.19,
+ cacheWrite: 0,
+ },
+ contextWindow: 256000,
+ maxTokens: 32000,
+ } satisfies Model<"openai-completions">,
+ "mai-code-1-flash-picker": {
+ id: "mai-code-1-flash-picker",
+ name: "MAI-Code-1-Flash",
+ api: "openai-completions",
+ provider: "github-copilot",
+ baseUrl: "https://api.individual.githubcopilot.com",
+ headers: {"User-Agent":"GitHubCopilotChat/0.35.0","Editor-Version":"vscode/1.107.0","Editor-Plugin-Version":"copilot-chat/0.35.0","Copilot-Integration-Id":"vscode-chat"},
+ compat: {"supportsStore":false,"supportsDeveloperRole":false,"supportsReasoningEffort":false},
+ reasoning: true,
+ input: ["text"],
+ cost: {
+ input: 0.75,
+ output: 4.5,
+ cacheRead: 0.075,
+ cacheWrite: 0,
+ },
+ contextWindow: 256000,
+ maxTokens: 128000,
+ } satisfies Model<"openai-completions">,
},
"google": {
"gemini-2.0-flash": {
@@ -7894,6 +8131,24 @@ export const MODELS = {
contextWindow: 200000,
maxTokens: 32000,
} satisfies Model<"openai-completions">,
+ "claude-fable-5": {
+ id: "claude-fable-5",
+ name: "Claude Fable 5",
+ api: "anthropic-messages",
+ provider: "opencode",
+ baseUrl: "https://opencode.ai/zen",
+ reasoning: true,
+ thinkingLevelMap: {"off":null,"xhigh":"xhigh","max":"max"},
+ input: ["text", "image"],
+ cost: {
+ input: 10,
+ output: 50,
+ cacheRead: 1,
+ cacheWrite: 12.5,
+ },
+ contextWindow: 1000000,
+ maxTokens: 128000,
+ } satisfies Model<"anthropic-messages">,
"claude-haiku-4-5": {
id: "claude-haiku-4-5",
name: "Claude Haiku 4.5",
@@ -8051,6 +8306,24 @@ export const MODELS = {
contextWindow: 1000000,
maxTokens: 64000,
} satisfies Model<"anthropic-messages">,
+ "claude-sonnet-5": {
+ id: "claude-sonnet-5",
+ name: "Claude Sonnet 5",
+ api: "anthropic-messages",
+ provider: "opencode",
+ baseUrl: "https://opencode.ai/zen",
+ reasoning: true,
+ thinkingLevelMap: {"xhigh":"xhigh","max":"max"},
+ input: ["text", "image"],
+ cost: {
+ input: 2,
+ output: 10,
+ cacheRead: 0.2,
+ cacheWrite: 2.5,
+ },
+ contextWindow: 1000000,
+ maxTokens: 128000,
+ } satisfies Model<"anthropic-messages">,
"deepseek-v4-flash": {
id: "deepseek-v4-flash",
name: "DeepSeek V4 Flash",
@@ -8552,6 +8825,23 @@ export const MODELS = {
contextWindow: 262144,
maxTokens: 65536,
} satisfies Model<"openai-completions">,
+ "kimi-k2.7-code": {
+ id: "kimi-k2.7-code",
+ name: "Kimi K2.7 Code",
+ api: "openai-completions",
+ provider: "opencode",
+ baseUrl: "https://opencode.ai/zen/v1",
+ reasoning: true,
+ input: ["text", "image"],
+ cost: {
+ input: 0.95,
+ output: 4,
+ cacheRead: 0.19,
+ cacheWrite: 0,
+ },
+ contextWindow: 262144,
+ maxTokens: 262144,
+ } satisfies Model<"openai-completions">,
"mimo-v2.5-free": {
id: "mimo-v2.5-free",
name: "MiMo V2.5 Free",
@@ -8571,7 +8861,7 @@ export const MODELS = {
} satisfies Model<"openai-completions">,
"minimax-m2.5": {
id: "minimax-m2.5",
- name: "MiniMax M2.5",
+ name: "MiniMax-M2.5",
api: "openai-completions",
provider: "opencode",
baseUrl: "https://opencode.ai/zen/v1",
@@ -8588,7 +8878,7 @@ export const MODELS = {
} satisfies Model<"openai-completions">,
"minimax-m2.7": {
id: "minimax-m2.7",
- name: "MiniMax M2.7",
+ name: "MiniMax-M2.7",
api: "openai-completions",
provider: "opencode",
baseUrl: "https://opencode.ai/zen/v1",
@@ -8603,6 +8893,23 @@ export const MODELS = {
contextWindow: 204800,
maxTokens: 131072,
} satisfies Model<"openai-completions">,
+ "minimax-m3": {
+ id: "minimax-m3",
+ name: "MiniMax-M3",
+ api: "openai-completions",
+ provider: "opencode",
+ baseUrl: "https://opencode.ai/zen/v1",
+ reasoning: true,
+ input: ["text", "image"],
+ cost: {
+ input: 0.3,
+ output: 1.2,
+ cacheRead: 0.06,
+ cacheWrite: 0,
+ },
+ contextWindow: 512000,
+ maxTokens: 128000,
+ } satisfies Model<"openai-completions">,
"nemotron-3-ultra-free": {
id: "nemotron-3-ultra-free",
name: "Nemotron 3 Ultra Free",
@@ -8815,7 +9122,7 @@ export const MODELS = {
} satisfies Model<"openai-completions">,
"minimax-m2.7": {
id: "minimax-m2.7",
- name: "MiniMax M2.7",
+ name: "MiniMax-M2.7",
api: "openai-completions",
provider: "opencode-go",
baseUrl: "https://opencode.ai/zen/go/v1",
@@ -8832,7 +9139,7 @@ export const MODELS = {
} satisfies Model<"openai-completions">,
"minimax-m3": {
id: "minimax-m3",
- name: "MiniMax M3 (3x usage)",
+ name: "MiniMax-M3",
api: "anthropic-messages",
provider: "opencode-go",
baseUrl: "https://opencode.ai/zen/go",
@@ -9255,6 +9562,7 @@ export const MODELS = {
provider: "openrouter",
baseUrl: "https://openrouter.ai/api/v1",
reasoning: true,
+ thinkingLevelMap: {"xhigh":"xhigh","max":"max"},
input: ["text", "image"],
cost: {
input: 2,
@@ -9478,8 +9786,8 @@ export const MODELS = {
reasoning: false,
input: ["text"],
cost: {
- input: 0.19999999999999998,
- output: 0.77,
+ input: 0.24,
+ output: 0.8999999999999999,
cacheRead: 0.135,
cacheWrite: 0,
},
@@ -9599,9 +9907,9 @@ export const MODELS = {
thinkingLevelMap: {"minimal":null,"low":null,"medium":null,"high":"high","xhigh":"max"},
input: ["text"],
cost: {
- input: 0.098,
- output: 0.196,
- cacheRead: 0.02,
+ input: 0.08900000000000001,
+ output: 0.18,
+ cacheRead: 0.018,
cacheWrite: 0,
},
contextWindow: 1048576,
@@ -10197,12 +10505,12 @@ export const MODELS = {
input: ["text"],
cost: {
input: 0.255,
- output: 1,
- cacheRead: 0.03,
+ output: 1.02,
+ cacheRead: 0,
cacheWrite: 0,
},
contextWindow: 204800,
- maxTokens: 196608,
+ maxTokens: 131072,
} satisfies Model<"openai-completions">,
"minimax/minimax-m2.1": {
id: "minimax/minimax-m2.1",
@@ -10213,13 +10521,13 @@ export const MODELS = {
reasoning: true,
input: ["text"],
cost: {
- input: 0.29,
- output: 0.95,
+ input: 0.3,
+ output: 1.2,
cacheRead: 0.03,
cacheWrite: 0,
},
contextWindow: 204800,
- maxTokens: 196608,
+ maxTokens: 131072,
} satisfies Model<"openai-completions">,
"minimax/minimax-m2.5": {
id: "minimax/minimax-m2.5",
@@ -10606,11 +10914,11 @@ export const MODELS = {
cost: {
input: 0.6,
output: 2.5,
- cacheRead: 0.6,
+ cacheRead: 0.15,
cacheWrite: 0,
},
contextWindow: 262144,
- maxTokens: 262144,
+ maxTokens: 100352,
} satisfies Model<"openai-completions">,
"moonshotai/kimi-k2.5": {
id: "moonshotai/kimi-k2.5",
@@ -10638,9 +10946,9 @@ export const MODELS = {
reasoning: true,
input: ["text", "image"],
cost: {
- input: 0.55,
- output: 3.1999999999999997,
- cacheRead: 0.11,
+ input: 0.66,
+ output: 3.41,
+ cacheRead: 0.14,
cacheWrite: 0,
},
contextWindow: 262144,
@@ -11831,6 +12139,40 @@ export const MODELS = {
contextWindow: 262144,
maxTokens: 32768,
} satisfies Model<"openai-completions">,
+ "poolside/laguna-xs-2.1": {
+ id: "poolside/laguna-xs-2.1",
+ name: "Poolside: Laguna XS 2.1",
+ api: "openai-completions",
+ provider: "openrouter",
+ baseUrl: "https://openrouter.ai/api/v1",
+ reasoning: true,
+ input: ["text"],
+ cost: {
+ input: 0.06,
+ output: 0.12,
+ cacheRead: 0.03,
+ cacheWrite: 0,
+ },
+ contextWindow: 262144,
+ maxTokens: 32768,
+ } satisfies Model<"openai-completions">,
+ "poolside/laguna-xs-2.1:free": {
+ id: "poolside/laguna-xs-2.1:free",
+ name: "Poolside: Laguna XS 2.1 (free)",
+ api: "openai-completions",
+ provider: "openrouter",
+ baseUrl: "https://openrouter.ai/api/v1",
+ reasoning: true,
+ input: ["text"],
+ cost: {
+ input: 0,
+ output: 0,
+ cacheRead: 0,
+ cacheWrite: 0,
+ },
+ contextWindow: 262144,
+ maxTokens: 32768,
+ } satisfies Model<"openai-completions">,
"poolside/laguna-xs.2": {
id: "poolside/laguna-xs.2",
name: "Poolside: Laguna XS.2",
@@ -12010,13 +12352,13 @@ export const MODELS = {
reasoning: true,
input: ["text"],
cost: {
- input: 0.09999999999999999,
- output: 0.09999999999999999,
- cacheRead: 0.09999999999999999,
+ input: 0.14950000000000002,
+ output: 1.495,
+ cacheRead: 0,
cacheWrite: 0,
},
contextWindow: 262144,
- maxTokens: 262144,
+ maxTokens: 4096,
} satisfies Model<"openai-completions">,
"qwen/qwen3-30b-a3b": {
id: "qwen/qwen3-30b-a3b",
@@ -12061,13 +12403,13 @@ export const MODELS = {
reasoning: true,
input: ["text"],
cost: {
- input: 0.08,
- output: 0.39999999999999997,
- cacheRead: 0.08,
+ input: 0.13,
+ output: 1.56,
+ cacheRead: 0,
cacheWrite: 0,
},
contextWindow: 131072,
- maxTokens: 131072,
+ maxTokens: 32768,
} satisfies Model<"openai-completions">,
"qwen/qwen3-32b": {
id: "qwen/qwen3-32b",
@@ -12095,9 +12437,9 @@ export const MODELS = {
reasoning: true,
input: ["text"],
cost: {
- input: 0.049999999999999996,
- output: 0.39999999999999997,
- cacheRead: 0.049999999999999996,
+ input: 0.117,
+ output: 0.45499999999999996,
+ cacheRead: 0,
cacheWrite: 0,
},
contextWindow: 131072,
@@ -12384,8 +12726,8 @@ export const MODELS = {
reasoning: false,
input: ["text", "image"],
cost: {
- input: 0.08,
- output: 0.5,
+ input: 0.117,
+ output: 0.45499999999999996,
cacheRead: 0,
cacheWrite: 0,
},
@@ -13081,13 +13423,13 @@ export const MODELS = {
reasoning: true,
input: ["text"],
cost: {
- input: 0.94,
+ input: 0.9299999999999999,
output: 3,
cacheRead: 0.18,
cacheWrite: 0,
},
contextWindow: 1048576,
- maxTokens: 4096,
+ maxTokens: 32768,
} satisfies Model<"openai-completions">,
"z-ai/glm-5v-turbo": {
id: "z-ai/glm-5v-turbo",
@@ -13217,9 +13559,9 @@ export const MODELS = {
reasoning: true,
input: ["text", "image"],
cost: {
- input: 0.55,
- output: 3.1999999999999997,
- cacheRead: 0.11,
+ input: 0.66,
+ output: 3.41,
+ cacheRead: 0.14,
cacheWrite: 0,
},
contextWindow: 262144,
@@ -14306,6 +14648,24 @@ export const MODELS = {
contextWindow: 200000,
maxTokens: 8192,
} satisfies Model<"anthropic-messages">,
+ "anthropic/claude-fable-5": {
+ id: "anthropic/claude-fable-5",
+ name: "Claude Fable 5",
+ api: "anthropic-messages",
+ provider: "vercel-ai-gateway",
+ baseUrl: "https://ai-gateway.vercel.sh",
+ reasoning: true,
+ thinkingLevelMap: {"off":null,"xhigh":"xhigh","max":"max"},
+ input: ["text", "image"],
+ cost: {
+ input: 10,
+ output: 50,
+ cacheRead: 1,
+ cacheWrite: 12.5,
+ },
+ contextWindow: 1000000,
+ maxTokens: 128000,
+ } satisfies Model<"anthropic-messages">,
"anthropic/claude-haiku-4.5": {
id: "anthropic/claude-haiku-4.5",
name: "Claude Haiku 4.5",
@@ -14487,6 +14847,7 @@ export const MODELS = {
provider: "vercel-ai-gateway",
baseUrl: "https://ai-gateway.vercel.sh",
reasoning: true,
+ thinkingLevelMap: {"xhigh":"xhigh","max":"max"},
input: ["text", "image"],
cost: {
input: 2,
@@ -16932,12 +17293,12 @@ export const MODELS = {
reasoning: true,
input: ["text"],
cost: {
- input: 1.5,
- output: 4.5,
- cacheRead: 0.3,
+ input: 1.4,
+ output: 4.4,
+ cacheRead: 0.26,
cacheWrite: 0,
},
- contextWindow: 1000000,
+ contextWindow: 1040000,
maxTokens: 128000,
} satisfies Model<"anthropic-messages">,
"zai/glm-5.2-fast": {
diff --git a/packages/coding-agent/src/core/settings-manager.ts b/packages/coding-agent/src/core/settings-manager.ts
index c925b486e1..f71c582561 100644
--- a/packages/coding-agent/src/core/settings-manager.ts
+++ b/packages/coding-agent/src/core/settings-manager.ts
@@ -43,6 +43,8 @@ export interface TerminalSettings {
imageWidthCells?: number; // default: 60 (preferred inline image width in terminal cells)
clearOnShrink?: boolean; // default: false (clear empty rows when content shrinks)
showTerminalProgress?: boolean; // default: false (OSC 9;4 terminal progress indicators)
+ fullscreen?: boolean; // default: false (alternate-screen rendering with scrollable transcript)
+ fullscreenMouse?: boolean; // default: true (wheel scrolling in fullscreen; disable if it breaks selection)
}
export interface ImageSettings {
@@ -1034,6 +1036,36 @@ export class SettingsManager {
this.save();
}
+ getFullscreen(): boolean {
+ // Env var overrides the setting (both directions) for one-off runs
+ if (process.env.PI_FULLSCREEN !== undefined) {
+ return process.env.PI_FULLSCREEN === "1";
+ }
+ return this.settings.terminal?.fullscreen ?? false;
+ }
+
+ setFullscreen(enabled: boolean): void {
+ if (!this.globalSettings.terminal) {
+ this.globalSettings.terminal = {};
+ }
+ this.globalSettings.terminal.fullscreen = enabled;
+ this.markModified("terminal", "fullscreen");
+ this.save();
+ }
+
+ getFullscreenMouse(): boolean {
+ return this.settings.terminal?.fullscreenMouse ?? true;
+ }
+
+ setFullscreenMouse(enabled: boolean): void {
+ if (!this.globalSettings.terminal) {
+ this.globalSettings.terminal = {};
+ }
+ this.globalSettings.terminal.fullscreenMouse = enabled;
+ this.markModified("terminal", "fullscreenMouse");
+ this.save();
+ }
+
getShowTerminalProgress(): boolean {
return this.settings.terminal?.showTerminalProgress ?? false;
}
diff --git a/packages/coding-agent/src/core/slash-commands.ts b/packages/coding-agent/src/core/slash-commands.ts
index 5138ba2eb3..1f92252da8 100644
--- a/packages/coding-agent/src/core/slash-commands.ts
+++ b/packages/coding-agent/src/core/slash-commands.ts
@@ -82,6 +82,12 @@ const CANONICAL_BUILTIN_SLASH_COMMANDS: ReadonlyArray<BuiltinSlashCommand> = [
},
{ name: "resume", description: "Resume a different session" },
{ name: "reload", description: "Reload keybindings, extensions, skills, prompts, and themes" },
+ {
+ name: "fullscreen",
+ description: "Toggle fullscreen (alternate screen) rendering with scrollable transcript",
+ argumentHint: "[on|off]",
+ takesArgument: true,
+ },
{ name: "quit", description: `Quit ${APP_NAME}` },
];
diff --git a/packages/coding-agent/src/modes/interactive/components/settings-selector.ts b/packages/coding-agent/src/modes/interactive/components/settings-selector.ts
index 206fd4134d..a06472b4f6 100644
--- a/packages/coding-agent/src/modes/interactive/components/settings-selector.ts
+++ b/packages/coding-agent/src/modes/interactive/components/settings-selector.ts
@@ -53,6 +53,7 @@ export interface SettingsConfig {
quietStartup: boolean;
clearOnShrink: boolean;
showTerminalProgress: boolean;
+ fullscreen: boolean;
warnings: WarningSettings;
}
@@ -78,6 +79,7 @@ export interface SettingsCallbacks {
onQuietStartupChange: (enabled: boolean) => void;
onClearOnShrinkChange: (enabled: boolean) => void;
onShowTerminalProgressChange: (enabled: boolean) => void;
+ onFullscreenChange: (enabled: boolean) => void;
onWarningsChange: (warnings: WarningSettings) => void;
onCancel: () => void;
}
@@ -431,6 +433,16 @@ export class SettingsSelectorComponent extends Container {
values: ["true", "false"],
});
+ // Fullscreen toggle (insert after terminal-progress)
+ const terminalProgressIndex = items.findIndex((item) => item.id === "terminal-progress");
+ items.splice(terminalProgressIndex + 1, 0, {
+ id: "fullscreen",
+ label: "Fullscreen rendering",
+ description: "Alternate-screen UI with scrollable transcript and pinned prompt",
+ currentValue: config.fullscreen ? "true" : "false",
+ values: ["true", "false"],
+ });
+
// Add borders
this.addChild(new DynamicBorder());
@@ -496,6 +508,9 @@ export class SettingsSelectorComponent extends Container {
case "terminal-progress":
callbacks.onShowTerminalProgressChange(newValue === "true");
break;
+ case "fullscreen":
+ callbacks.onFullscreenChange(newValue === "true");
+ break;
}
},
callbacks.onCancel,
diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.ts
index be6d09fea3..7c9ddd7e4b 100644
--- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts
+++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts
@@ -507,6 +507,11 @@ export class InteractiveMode {
private fdPath: string | undefined;
private mainContainer: Container;
private mainViewContainer: Container;
+ // prompt bar (editor + footer slot) — the only thing pinned to the bottom in fullscreen
+ private promptDock: Container;
+ // wraps the active footer so custom-footer swaps reflect in both layouts
+ private footerSlot: Container;
+ private fullscreenEnabled = false;
private editorContainer: Container;
private footer: FooterComponent;
private footerDataProvider: FooterDataProvider;
@@ -681,6 +686,9 @@ export class InteractiveMode {
this.version = VERSION;
this.ui = new TUI(new ProcessTerminal(), this.settingsManager.getShowHardwareCursor());
this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink());
+ this.ui.onCopy = (text) => {
+ void copyToClipboard(text).catch(() => undefined);
+ };
this.headerContainer = new Container();
this.chatContainer = new Container();
this.pendingMessagesContainer = new Container();
@@ -709,10 +717,14 @@ export class InteractiveMode {
paddingX: editorPaddingX,
autocompleteMaxVisible,
isArgumentCommand: builtinSlashCommandTakesArgument,
+ placeholder: "Type a message, / for commands",
+ placeholderColor: (text) => theme.fg("dim", text),
});
this.editor = this.defaultEditor;
this.mainContainer = new Container();
this.mainViewContainer = new Container();
+ this.promptDock = new Container();
+ this.footerSlot = new Container();
this.restoreMainAgentView();
this.editorContainer = new Container();
this.editorContainer.addChild(this.editor as Component);
@@ -969,7 +981,11 @@ export class InteractiveMode {
this.mainContainer.addChild(this.editorContainer);
this.mainContainer.addChild(this.childAgentSummary);
this.mainContainer.addChild(this.widgetContainerBelow);
- this.mainContainer.addChild(this.footer);
+ this.footerSlot.addChild(this.footer);
+ this.mainContainer.addChild(this.footerSlot);
+ this.promptDock.addChild(this.editorContainer);
+ this.promptDock.addChild(this.childAgentSummary);
+ this.promptDock.addChild(this.footerSlot);
this.ui.addChild(this.mainContainer);
this.ui.setFocus(this.editor);
@@ -978,6 +994,10 @@ export class InteractiveMode {
// Start the UI before initializing extensions so session_start handlers can use interactive dialogs
this.ui.start();
+ this.fullscreenEnabled = this.settingsManager.getFullscreen() && process.stdout.isTTY === true;
+ if (this.fullscreenEnabled) {
+ this.applyFullscreen(true);
+ }
this.isInitialized = true;
// Initialize extensions first so resources are shown before messages
@@ -2809,21 +2829,18 @@ export class InteractiveMode {
this.customFooter.dispose();
}
- // Remove current footer from the main container (the footer lives there, not on the root UI)
if (this.customFooter) {
- this.mainContainer.removeChild(this.customFooter);
+ this.footerSlot.removeChild(this.customFooter);
} else {
- this.mainContainer.removeChild(this.footer);
+ this.footerSlot.removeChild(this.footer);
}
if (factory) {
- // Create and add custom footer, passing the data provider
this.customFooter = factory(this.ui, theme, this.footerDataProvider);
- this.mainContainer.addChild(this.customFooter);
+ this.footerSlot.addChild(this.customFooter);
} else {
- // Restore built-in footer
this.customFooter = undefined;
- this.mainContainer.addChild(this.footer);
+ this.footerSlot.addChild(this.footer);
}
this.ui.requestRender();
@@ -3636,6 +3653,17 @@ export class InteractiveMode {
await this.handleReloadCommand();
return;
}
+ if (commandName === "fullscreen") {
+ this.editor.setText("");
+ const arg = commandArgs?.trim().toLowerCase();
+ if (arg && arg !== "on" && arg !== "off") {
+ this.showError("Usage: /fullscreen [on|off]");
+ return;
+ }
+ const enable = arg === "on" ? true : arg === "off" ? false : !this.fullscreenEnabled;
+ this.setFullscreenMode(enable);
+ return;
+ }
if (commandName === "debug" && !commandArgs) {
await this.handleDebugCommand();
this.editor.setText("");
@@ -5390,6 +5418,10 @@ export class InteractiveMode {
clearInterval(suspendKeepAlive);
process.removeListener("SIGINT", ignoreSigint);
this.ui.start();
+ // ui.stop() left the alt screen before suspending; re-enter it
+ if (this.fullscreenEnabled) {
+ this.applyFullscreen(true);
+ }
this.ui.requestRender(true);
});
@@ -5455,6 +5487,44 @@ export class InteractiveMode {
this.ui.requestRender();
}
+ /** Enter or leave fullscreen rendering without touching the persisted setting. */
+ private applyFullscreen(enabled: boolean): void {
+ if (enabled) {
+ if (!process.stdout.isTTY) return;
+ this.ui.enterFullscreen({
+ scroll: [
+ this.headerContainer,
+ this.mainViewContainer,
+ this.widgetContainerAbove,
+ this.recapContainer,
+ this.queuedMessagesContainer,
+ this.widgetContainerBelow,
+ ],
+ dock: this.promptDock,
+ mouse: this.settingsManager.getFullscreenMouse(),
+ });
+ } else {
+ this.ui.exitFullscreen();
+ }
+ }
+
+ private setFullscreenMode(enabled: boolean): void {
+ this.settingsManager.setFullscreen(enabled);
+ if (enabled && !process.stdout.isTTY) {
+ this.fullscreenEnabled = false;
+ this.showStatus("Fullscreen rendering requires an interactive terminal");
+ return;
+ }
+ this.fullscreenEnabled = enabled;
+ this.applyFullscreen(enabled);
+ const followKey = this.getEditorKeyDisplay("tui.viewport.follow");
+ this.showStatus(
+ enabled
+ ? `Fullscreen rendering on — wheel/pageUp scroll, ${followKey} follows output`
+ : "Fullscreen rendering off",
+ );
+ }
+
private toggleToolOutputExpansion(): void {
this.setToolsExpanded(!this.toolOutputExpanded);
}
@@ -5474,7 +5544,12 @@ export class InteractiveMode {
// Expanding/collapsing changes blocks above the viewport, which would
// otherwise force a full redraw that scrolls to the top and replays the
// whole transcript. Keep the user anchored at their current position.
- this.ui.requestRenderPreservingViewport();
+ // Fullscreen frames have no scrollback to preserve.
+ if (this.ui.isFullscreen()) {
+ this.ui.requestRender();
+ } else {
+ this.ui.requestRenderPreservingViewport();
+ }
}
private toggleThinkingBlockVisibility(): void {
@@ -5547,6 +5622,10 @@ export class InteractiveMode {
// Restart TUI
this.ui.start();
+ // ui.stop() left fullscreen so the editor got a clean terminal
+ if (this.fullscreenEnabled) {
+ this.applyFullscreen(true);
+ }
// Force full re-render since external editor uses alternate screen
this.ui.requestRender(true);
}
@@ -5840,6 +5919,7 @@ export class InteractiveMode {
quietStartup: this.settingsManager.getQuietStartup(),
clearOnShrink: this.settingsManager.getClearOnShrink(),
showTerminalProgress: this.settingsManager.getShowTerminalProgress(),
+ fullscreen: this.fullscreenEnabled,
warnings: this.settingsManager.getWarnings(),
},
{
@@ -5967,6 +6047,9 @@ export class InteractiveMode {
onShowTerminalProgressChange: (enabled) => {
this.settingsManager.setShowTerminalProgress(enabled);
},
+ onFullscreenChange: (enabled) => {
+ this.setFullscreenMode(enabled);
+ },
onWarningsChange: (warnings) => {
this.settingsManager.setWarnings(warnings);
},
@@ -7520,6 +7603,12 @@ export class InteractiveMode {
const dequeue = this.getAppKeyDisplay("app.message.dequeue");
const pasteImage = this.getAppKeyDisplay("app.clipboard.pasteImage");
+ // Fullscreen viewport keybindings
+ const viewportPageUp = this.getEditorKeyDisplay("tui.viewport.pageUp");
+ const viewportPageDown = this.getEditorKeyDisplay("tui.viewport.pageDown");
+ const viewportTop = this.getEditorKeyDisplay("tui.viewport.top");
+ const viewportFollow = this.getEditorKeyDisplay("tui.viewport.follow");
+
let hotkeys = `
**Navigation**
| Key | Action |
@@ -7562,6 +7651,14 @@ ${interrupt ? `| \`${interrupt}\` | Interrupt current operation |\n` : ""}| \`${
| \`${dequeue}\` | Restore queued messages |
| \`${pasteImage}\` | Paste image from clipboard |
| \`/\` | Slash commands |
+
+**Fullscreen mode (\`/fullscreen\`)**
+| Key | Action |
+|-----|--------|
+| \`${viewportPageUp}\` / \`${viewportPageDown}\` | Scroll transcript by page |
+| \`${viewportTop}\` | Scroll to top |
+| \`${viewportFollow}\` | Scroll to bottom and follow output |
+| mouse wheel | Scroll transcript |
`;
// Add extension-registered shortcuts
diff --git a/packages/coding-agent/test/edit-tool-no-full-redraw.test.ts b/packages/coding-agent/test/edit-tool-no-full-redraw.test.ts
index 21d4e7d588..7bd485d70e 100644
--- a/packages/coding-agent/test/edit-tool-no-full-redraw.test.ts
+++ b/packages/coding-agent/test/edit-tool-no-full-redraw.test.ts
@@ -28,6 +28,17 @@ class FakeTerminal implements Terminal {
clearScreen(): void {}
setTitle(_title: string): void {}
setProgress(_active: boolean): void {}
+ altScreenActive = false;
+ enterAltScreen(): void {
+ this.altScreenActive = true;
+ }
+ leaveAltScreen(): void {
+ this.altScreenActive = false;
+ }
+ mouseTrackingActive = false;
+ setMouseTracking(enabled: boolean): void {
+ this.mouseTrackingActive = enabled;
+ }
get fullClearCount(): number {
return this.writes.filter((write) => write.includes("\x1b[2J\x1b[H\x1b[3J")).length;
diff --git a/packages/coding-agent/test/fullscreen-mode.test.ts b/packages/coding-agent/test/fullscreen-mode.test.ts
new file mode 100644
index 0000000000..0f17a1c94b
--- /dev/null
+++ b/packages/coding-agent/test/fullscreen-mode.test.ts
@@ -0,0 +1,80 @@
+import { existsSync, mkdirSync, readFileSync, rmSync } from "fs";
+import { join } from "path";
+import { afterEach, beforeEach, describe, expect, it } from "vitest";
+import { SettingsManager } from "../src/core/settings-manager.js";
+import { BUILTIN_SLASH_COMMANDS } from "../src/core/slash-commands.js";
+
+describe("fullscreen mode settings", () => {
+ const testDir = join(process.cwd(), "test-fullscreen-tmp");
+ const agentDir = join(testDir, "agent");
+ const projectDir = join(testDir, "project");
+ let savedEnv: string | undefined;
+
+ beforeEach(() => {
+ if (existsSync(testDir)) {
+ rmSync(testDir, { recursive: true });
+ }
+ mkdirSync(agentDir, { recursive: true });
+ mkdirSync(join(projectDir, ".prime", "agent"), { recursive: true });
+ savedEnv = process.env.PI_FULLSCREEN;
+ delete process.env.PI_FULLSCREEN;
+ });
+
+ afterEach(() => {
+ if (existsSync(testDir)) {
+ rmSync(testDir, { recursive: true });
+ }
+ if (savedEnv === undefined) {
+ delete process.env.PI_FULLSCREEN;
+ } else {
+ process.env.PI_FULLSCREEN = savedEnv;
+ }
+ });
+
+ it("defaults to off with mouse enabled", () => {
+ const manager = SettingsManager.create(projectDir, agentDir);
+ expect(manager.getFullscreen()).toBe(false);
+ expect(manager.getFullscreenMouse()).toBe(true);
+ });
+
+ it("persists the fullscreen toggle", async () => {
+ const manager = SettingsManager.create(projectDir, agentDir);
+ manager.setFullscreen(true);
+ await manager.flush();
+
+ const settings = JSON.parse(readFileSync(join(agentDir, "settings.json"), "utf-8"));
+ expect(settings.terminal.fullscreen).toBe(true);
+
+ const reloaded = SettingsManager.create(projectDir, agentDir);
+ expect(reloaded.getFullscreen()).toBe(true);
+ });
+
+ it("PI_FULLSCREEN env var overrides the setting in both directions", () => {
+ const manager = SettingsManager.create(projectDir, agentDir);
+
+ process.env.PI_FULLSCREEN = "1";
+ expect(manager.getFullscreen()).toBe(true);
+
+ manager.setFullscreen(true);
+ process.env.PI_FULLSCREEN = "0";
+ expect(manager.getFullscreen()).toBe(false);
+ });
+
+ it("persists the fullscreen mouse toggle", async () => {
+ const manager = SettingsManager.create(projectDir, agentDir);
+ manager.setFullscreenMouse(false);
+ await manager.flush();
+
+ const reloaded = SettingsManager.create(projectDir, agentDir);
+ expect(reloaded.getFullscreenMouse()).toBe(false);
+ });
+});
+
+describe("fullscreen slash command", () => {
+ it("is registered with an on|off argument hint", () => {
+ const command = BUILTIN_SLASH_COMMANDS.find((c) => c.name === "fullscreen");
+ expect(command).toBeDefined();
+ expect(command?.argumentHint).toBe("[on|off]");
+ expect(command?.takesArgument).toBe(true);
+ });
+});
diff --git a/packages/coding-agent/test/interactive-mode-status.test.ts b/packages/coding-agent/test/interactive-mode-status.test.ts
index d80c48eb78..f4cbf2c98d 100644
--- a/packages/coding-agent/test/interactive-mode-status.test.ts
+++ b/packages/coding-agent/test/interactive-mode-status.test.ts
@@ -1485,7 +1485,11 @@ describe("InteractiveMode.setToolsExpanded", () => {
builtInHeader: header,
chatContainer: { children: [chatChild] },
childAgentDetail,
- ui: { requestRender: vi.fn(), requestRenderPreservingViewport: vi.fn() },
+ ui: {
+ requestRender: vi.fn(),
+ requestRenderPreservingViewport: vi.fn(),
+ isFullscreen: vi.fn().mockReturnValue(false),
+ },
};
(InteractiveMode as any).prototype.setToolsExpanded.call(fakeThis, true);
diff --git a/packages/tui/src/fullscreen.ts b/packages/tui/src/fullscreen.ts
new file mode 100644
index 0000000000..0f20c0ef5b
--- /dev/null
+++ b/packages/tui/src/fullscreen.ts
@@ -0,0 +1,238 @@
+/**
+ * Fullscreen (alternate-screen) viewport: a scrollable window over the
+ * transcript with a dock (editor/footer) pinned to the bottom rows. Frames
+ * are a fixed grid painted with absolute addressing and diffed row-by-row;
+ * scroll position is application state, not terminal scrollback.
+ */
+
+import { isImageLine } from "./terminal-image.js";
+import { sliceByColumn, stripAnsi, visibleWidth } from "./utils.js";
+
+const MIN_TRANSCRIPT_ROWS = 3;
+
+// Kitty images span multiple physical rows and cannot be clipped to a window.
+const IMAGE_PLACEHOLDER = "\x1b[2m[image — view in inline mode]\x1b[0m";
+
+export interface ScrollInfo {
+ following: boolean;
+ linesBelow: number;
+ linesAbove: number;
+}
+
+// Transcript-anchored selection endpoint (line index + visible column), so
+// streaming appends and scrolling never shift what is selected.
+interface SelectionPoint {
+ line: number;
+ col: number;
+}
+
+export class FullscreenViewport {
+ private scrollTop = 0;
+ private following = true;
+ private prevFrame: string[] = [];
+ private prevWidth = 0;
+ private prevHeight = 0;
+ private lastMaxScroll = 0;
+ private lastWindowHeight = 0;
+ private lastTranscript: string[] = [];
+ private selectionAnchor: SelectionPoint | null = null;
+ private selectionHead: SelectionPoint | null = null;
+
+ /**
+ * Compose a frame of exactly `height` lines: scrolled transcript window on
+ * top, dock pinned to the bottom. Following pins the window to the
+ * transcript end; otherwise it stays frozen while content appends.
+ */
+ composeFrame(transcript: string[], dock: string[], height: number): string[] {
+ let dockLines = dock;
+ const maxDock = Math.max(0, height - MIN_TRANSCRIPT_ROWS);
+ if (dockLines.length > maxDock) {
+ // bottom of the dock (editor + footer) wins over widgets above it
+ dockLines = dockLines.slice(dockLines.length - maxDock);
+ }
+ const windowHeight = height - dockLines.length;
+ const maxScroll = Math.max(0, transcript.length - windowHeight);
+
+ if (this.following) {
+ this.scrollTop = maxScroll;
+ } else {
+ this.scrollTop = Math.max(0, Math.min(this.scrollTop, maxScroll));
+ }
+ this.lastMaxScroll = maxScroll;
+ this.lastWindowHeight = windowHeight;
+ this.lastTranscript = transcript;
+
+ const window = transcript.slice(this.scrollTop, this.scrollTop + windowHeight);
+ for (let i = 0; i < window.length; i++) {
+ if (isImageLine(window[i])) window[i] = IMAGE_PLACEHOLDER;
+ }
+ this.highlightSelection(window);
+ while (window.length < windowHeight) {
+ window.push("");
+ }
+ return [...window, ...dockLines];
+ }
+
+ private orderedSelection(): { start: SelectionPoint; end: SelectionPoint } | null {
+ const a = this.selectionAnchor;
+ const b = this.selectionHead;
+ if (!a || !b || (a.line === b.line && a.col === b.col)) return null;
+ const flipped = a.line > b.line || (a.line === b.line && a.col > b.col);
+ return flipped ? { start: b, end: a } : { start: a, end: b };
+ }
+
+ // Per-line selected column span, or null when the line is outside the selection.
+ private selectionSpan(
+ lineIndex: number,
+ sel: { start: SelectionPoint; end: SelectionPoint },
+ ): { from: number; to: number } | null {
+ if (lineIndex < sel.start.line || lineIndex > sel.end.line) return null;
+ return {
+ from: lineIndex === sel.start.line ? sel.start.col : 0,
+ to: lineIndex === sel.end.line ? sel.end.col : Number.MAX_SAFE_INTEGER,
+ };
+ }
+
+ private highlightSelection(window: string[]): void {
+ const sel = this.orderedSelection();
+ if (!sel) return;
+ for (let i = 0; i < window.length; i++) {
+ const span = this.selectionSpan(this.scrollTop + i, sel);
+ if (!span) continue;
+ const width = visibleWidth(window[i]);
+ const from = Math.min(span.from, width);
+ const to = Math.min(span.to, width);
+ if (to <= from) continue;
+ const before = sliceByColumn(window[i], 0, from);
+ // selected span is rendered plain-inverse: SGR codes inside it could
+ // cancel the inverse attribute mid-span
+ const selected = stripAnsi(sliceByColumn(window[i], from, to - from));
+ const after = sliceByColumn(window[i], to, Math.max(0, width - to));
+ window[i] = `${before}\x1b[0m\x1b[7m${selected}\x1b[27m${after}`;
+ }
+ }
+
+ /** Begin a selection at a screen position; false when outside the transcript window. */
+ beginSelection(screenRow: number, screenCol: number): boolean {
+ if (screenRow < 0 || screenRow >= this.lastWindowHeight) {
+ this.clearSelection();
+ return false;
+ }
+ const point = { line: this.scrollTop + screenRow, col: Math.max(0, screenCol) };
+ this.selectionAnchor = point;
+ this.selectionHead = { ...point };
+ return true;
+ }
+
+ extendSelection(screenRow: number, screenCol: number): void {
+ if (!this.selectionAnchor) return;
+ const row = Math.max(0, Math.min(screenRow, this.lastWindowHeight - 1));
+ this.selectionHead = { line: this.scrollTop + row, col: Math.max(0, screenCol) };
+ }
+
+ /** Finish the selection and return its plain text (null when empty). */
+ endSelection(): string | null {
+ const sel = this.orderedSelection();
+ this.clearSelection();
+ if (!sel) return null;
+ const lines: string[] = [];
+ for (let lineIndex = sel.start.line; lineIndex <= sel.end.line; lineIndex++) {
+ const line = this.lastTranscript[lineIndex] ?? "";
+ const span = this.selectionSpan(lineIndex, sel);
+ if (!span) continue;
+ const width = visibleWidth(line);
+ const from = Math.min(span.from, width);
+ const to = Math.min(span.to, width);
+ lines.push(stripAnsi(sliceByColumn(line, from, Math.max(0, to - from))).trimEnd());
+ }
+ const text = lines.join("\n");
+ return text.trim().length > 0 ? text : null;
+ }
+
+ clearSelection(): void {
+ this.selectionAnchor = null;
+ this.selectionHead = null;
+ }
+
+ hasSelection(): boolean {
+ return this.orderedSelection() !== null;
+ }
+
+ /** Row-diff a composed frame against the previous one with absolute addressing. */
+ paint(
+ write: (data: string) => void,
+ frame: string[],
+ width: number,
+ height: number,
+ cursorPos: { row: number; col: number } | null,
+ ): void {
+ // over-tall frames (overlay overflow) show their bottom `height` lines
+ if (frame.length > height) {
+ frame = frame.slice(frame.length - height);
+ }
+
+ let buffer = "\x1b[?2026h";
+ if (width !== this.prevWidth || height !== this.prevHeight || this.prevFrame.length === 0) {
+ buffer += "\x1b[2J\x1b[H";
+ this.prevFrame = [];
+ }
+ for (let row = 0; row < height; row++) {
+ const line = frame[row] ?? "";
+ if (this.prevFrame[row] === line) continue;
+ buffer += `\x1b[${row + 1};1H\x1b[2K`;
+ // an overwide line would wrap and shear the grid; clamp instead of crash
+ buffer += visibleWidth(line) > width ? sliceByColumn(line, 0, width, true) : line;
+ }
+ if (cursorPos) {
+ buffer += `\x1b[${Math.min(cursorPos.row, height - 1) + 1};${cursorPos.col + 1}H`;
+ }
+ buffer += "\x1b[?2026l";
+ write(buffer);
+
+ this.prevFrame = frame;
+ this.prevWidth = width;
+ this.prevHeight = height;
+ }
+
+ /** Force the next paint to clear and repaint the whole screen. */
+ reset(): void {
+ this.prevFrame = [];
+ }
+
+ /** Scrolling up pauses following; reaching the bottom resumes it. */
+ scrollBy(delta: number): void {
+ const base = this.following ? this.lastMaxScroll : this.scrollTop;
+ this.scrollTop = Math.max(0, Math.min(base + delta, this.lastMaxScroll));
+ this.following = this.scrollTop >= this.lastMaxScroll;
+ }
+
+ scrollToTop(): void {
+ this.scrollTop = 0;
+ this.following = this.lastMaxScroll === 0;
+ }
+
+ scrollToBottom(): void {
+ this.scrollTop = this.lastMaxScroll;
+ this.following = true;
+ }
+
+ pageSize(): number {
+ return Math.max(1, this.lastWindowHeight - 1);
+ }
+
+ windowHeight(): number {
+ return this.lastWindowHeight;
+ }
+
+ isFollowing(): boolean {
+ return this.following;
+ }
+
+ scrollInfo(): ScrollInfo {
+ return {
+ following: this.following,
+ linesBelow: Math.max(0, this.lastMaxScroll - this.scrollTop),
+ linesAbove: this.scrollTop,
+ };
+ }
+}
diff --git a/packages/tui/src/index.ts b/packages/tui/src/index.ts
index f498791436..c1f3ea7c83 100644
--- a/packages/tui/src/index.ts
+++ b/packages/tui/src/index.ts
@@ -29,6 +29,8 @@ export { Text } from "./components/text.js";
export { TruncatedText } from "./components/truncated-text.js";
// Editor component interface (for custom editors)
export type { EditorComponent } from "./editor-component.js";
+// Fullscreen (alternate-screen) viewport
+export { FullscreenViewport, type ScrollInfo } from "./fullscreen.js";
// Fuzzy matching
export { type FuzzyMatch, fuzzyFilter, fuzzyFilterScored, fuzzyMatch, type ScoredItem } from "./fuzzy.js";
// Keybindings
@@ -59,6 +61,16 @@ export {
} from "./keys.js";
// LaTeX math to Unicode conversion
export { latexToUnicode } from "./latex.js";
+// SGR mouse event parsing
+export {
+ isMouseSequence,
+ isWheelDown,
+ isWheelUp,
+ MOUSE_WHEEL_DOWN,
+ MOUSE_WHEEL_UP,
+ type MouseEvent,
+ parseSgrMouseEvent,
+} from "./mouse.js";
// Render caching
export { VersionedRenderCache } from "./render-cache.js";
// Input buffering for batch splitting
diff --git a/packages/tui/src/keybindings.ts b/packages/tui/src/keybindings.ts
index 356554cff8..f74dd47c68 100644
--- a/packages/tui/src/keybindings.ts
+++ b/packages/tui/src/keybindings.ts
@@ -32,6 +32,11 @@ export interface Keybindings {
"tui.input.submit": true;
"tui.input.tab": true;
"tui.input.copy": true;
+ // Fullscreen transcript viewport
+ "tui.viewport.pageUp": true;
+ "tui.viewport.pageDown": true;
+ "tui.viewport.top": true;
+ "tui.viewport.follow": true;
// Generic selection actions
"tui.select.up": true;
"tui.select.down": true;
@@ -119,6 +124,22 @@ export const TUI_KEYBINDINGS = {
"tui.input.submit": { defaultKeys: "enter", description: "Submit input" },
"tui.input.tab": { defaultKeys: "tab", description: "Tab / autocomplete" },
"tui.input.copy": { defaultKeys: "ctrl+c", description: "Copy selection" },
+ "tui.viewport.pageUp": {
+ defaultKeys: "pageUp",
+ description: "Scroll transcript up a page (fullscreen)",
+ },
+ "tui.viewport.pageDown": {
+ defaultKeys: "pageDown",
+ description: "Scroll transcript down a page (fullscreen)",
+ },
+ "tui.viewport.top": {
+ defaultKeys: "shift+alt+up",
+ description: "Scroll transcript to top (fullscreen)",
+ },
+ "tui.viewport.follow": {
+ defaultKeys: "alt+down",
+ description: "Scroll to bottom and follow output (fullscreen)",
+ },
"tui.select.up": { defaultKeys: "up", description: "Move selection up" },
"tui.select.down": { defaultKeys: "down", description: "Move selection down" },
"tui.select.pageUp": { defaultKeys: "pageUp", description: "Selection page up" },
diff --git a/packages/tui/src/mouse.ts b/packages/tui/src/mouse.ts
new file mode 100644
index 0000000000..fdcad4684f
--- /dev/null
+++ b/packages/tui/src/mouse.ts
@@ -0,0 +1,56 @@
+/** SGR mouse event parsing (CSI < button ; x ; y M/m). */
+
+export interface MouseEvent {
+ /** Base button code with modifier/motion bits stripped (wheel: 64 up, 65 down). */
+ button: number;
+ /** 1-based column. */
+ x: number;
+ /** 1-based row. */
+ y: number;
+ /** True for press/wheel/drag ("M"), false for release ("m"). */
+ press: boolean;
+ /** True for drag/motion reports (bit 32). */
+ motion: boolean;
+ shift: boolean;
+ alt: boolean;
+ ctrl: boolean;
+}
+
+export const MOUSE_WHEEL_UP = 64;
+export const MOUSE_WHEEL_DOWN = 65;
+export const MOUSE_BUTTON_LEFT = 0;
+
+const SGR_MOUSE_PATTERN = /^\x1b\[<(\d+);(\d+);(\d+)([Mm])$/;
+const MODIFIER_SHIFT = 4;
+const MODIFIER_ALT = 8;
+const MODIFIER_CTRL = 16;
+const MOTION_BIT = 32;
+
+/** True for any mouse report (SGR or legacy), parseable or not. */
+export function isMouseSequence(sequence: string): boolean {
+ return sequence.startsWith("\x1b[<") || sequence.startsWith("\x1b[M");
+}
+
+export function parseSgrMouseEvent(sequence: string): MouseEvent | null {
+ const match = sequence.match(SGR_MOUSE_PATTERN);
+ if (!match) return null;
+ const raw = Number(match[1]);
+ return {
+ button: raw & ~(MODIFIER_SHIFT | MODIFIER_ALT | MODIFIER_CTRL | MOTION_BIT),
+ x: Number(match[2]),
+ y: Number(match[3]),
+ press: match[4] === "M",
+ motion: (raw & MOTION_BIT) !== 0,
+ shift: (raw & MODIFIER_SHIFT) !== 0,
+ alt: (raw & MODIFIER_ALT) !== 0,
+ ctrl: (raw & MODIFIER_CTRL) !== 0,
+ };
+}
+
+export function isWheelUp(event: MouseEvent): boolean {
+ return event.press && event.button === MOUSE_WHEEL_UP;
+}
+
+export function isWheelDown(event: MouseEvent): boolean {
+ return event.press && event.button === MOUSE_WHEEL_DOWN;
+}
diff --git a/packages/tui/src/terminal.ts b/packages/tui/src/terminal.ts
index a70bc1180d..e6f16b436d 100644
--- a/packages/tui/src/terminal.ts
+++ b/packages/tui/src/terminal.ts
@@ -57,6 +57,18 @@ export interface Terminal {
clearFromCursor(): void; // Clear from cursor to end of screen
clearScreen(): void; // Clear entire screen and move cursor to (0,0)
+ // Alternate screen buffer. The primary screen (and its scrollback) is left
+ // untouched while the alt screen is active, so a full-screen view can be
+ // shown and dismissed without disturbing the transcript history.
+ enterAltScreen(): void;
+ leaveAltScreen(): void;
+ get altScreenActive(): boolean;
+
+ // SGR mouse tracking (?1000 + ?1006); motion tracking is deliberately never
+ // enabled so native drag-selection keeps working.
+ setMouseTracking(enabled: boolean): void;
+ get mouseTrackingActive(): boolean;
+
// Title operations
setTitle(title: string): void; // Set terminal window title
@@ -73,6 +85,8 @@ export class ProcessTerminal implements Terminal {
private resizeHandler?: () => void;
private _kittyProtocolActive = false;
private _modifyOtherKeysActive = false;
+ private _altScreenActive = false;
+ private _mouseTrackingActive = false;
private stdinBuffer?: StdinBuffer;
private stdinDataHandler?: (data: string) => void;
private progressInterval?: ReturnType<typeof setInterval>;
@@ -334,6 +348,16 @@ export class ProcessTerminal implements Terminal {
process.stdout.write(TERMINAL_PROGRESS_CLEAR_SEQUENCE);
}
+ // never strand the user on the alt screen or with mouse tracking on
+ if (this._mouseTrackingActive) {
+ process.stdout.write("\x1b[?1006l\x1b[?1002l");
+ this._mouseTrackingActive = false;
+ }
+ if (this._altScreenActive) {
+ process.stdout.write("\x1b[?1049l");
+ this._altScreenActive = false;
+ }
+
// Disable bracketed paste mode
process.stdout.write("\x1b[?2004l");
@@ -426,6 +450,34 @@ export class ProcessTerminal implements Terminal {
process.stdout.write("\x1b[2J\x1b[H"); // Clear screen and move to home (1,1)
}
+ enterAltScreen(): void {
+ if (this._altScreenActive) return;
+ this._altScreenActive = true;
+ this.write("\x1b[?1049h");
+ }
+
+ leaveAltScreen(): void {
+ if (!this._altScreenActive) return;
+ this._altScreenActive = false;
+ this.write("\x1b[?1049l");
+ }
+
+ get altScreenActive(): boolean {
+ return this._altScreenActive;
+ }
+
+ setMouseTracking(enabled: boolean): void {
+ if (enabled === this._mouseTrackingActive) return;
+ this._mouseTrackingActive = enabled;
+ // ?1002 (button-event tracking) reports drag motion for in-app selection
+ // but not hover, keeping passive mouse movement unreported.
+ this.write(enabled ? "\x1b[?1002h\x1b[?1006h" : "\x1b[?1006l\x1b[?1002l");
+ }
+
+ get mouseTrackingActive(): boolean {
+ return this._mouseTrackingActive;
+ }
+
setTitle(title: string): void {
// OSC 0;title BEL - set terminal window title
process.stdout.write(`\x1b]0;${title}\x07`);
diff --git a/packages/tui/src/tui.ts b/packages/tui/src/tui.ts
index 1b48537e51..d57efac2fd 100644
--- a/packages/tui/src/tui.ts
+++ b/packages/tui/src/tui.ts
@@ -6,7 +6,10 @@ import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import { performance } from "node:perf_hooks";
+import { FullscreenViewport, type ScrollInfo } from "./fullscreen.js";
+import { getKeybindings } from "./keybindings.js";
import { isKeyRelease, matchesKey } from "./keys.js";
+import { isMouseSequence, isWheelDown, isWheelUp, MOUSE_BUTTON_LEFT, parseSgrMouseEvent } from "./mouse.js";
import type { Terminal } from "./terminal.js";
import { deleteKittyImage, getCapabilities, isImageLine, setCellDimensions } from "./terminal-image.js";
import { extractSegments, normalizeTerminalOutput, sliceByColumn, sliceWithWidth, visibleWidth } from "./utils.js";
@@ -249,6 +252,8 @@ export class TUI extends Container {
/** Global callback for debug key (Shift+Ctrl+D). Called before input is forwarded to focused component. */
public onDebug?: () => void;
+ /** Copies fullscreen mouse selections; when unset, OSC 52 is written directly. */
+ public onCopy?: (text: string) => void;
private renderRequested = false;
private renderTimer: NodeJS.Timeout | undefined;
private lastRenderAt = 0;
@@ -263,6 +268,26 @@ export class TUI extends Container {
private preserveViewportOnNextRender = false; // One-shot: repaint visible viewport in place instead of replaying scrollback
private stopped = false;
+ // While set, doRender paints fixed frames via the viewport; the inline
+ // differ's bookkeeping stays frozen in `inlineState` until exit.
+ private fullscreen: {
+ viewport: FullscreenViewport;
+ scroll: Component[];
+ dock: Component;
+ mouse: boolean;
+ inlineState: {
+ previousLines: string[];
+ previousKittyImageIds: Set<number>;
+ previousWidth: number;
+ previousHeight: number;
+ cursorRow: number;
+ hardwareCursorRow: number;
+ maxLinesRendered: number;
+ previousViewportTop: number;
+ };
+ } | null = null;
+ private static readonly WHEEL_SCROLL_LINES = 3;
+
// Overlay stack for modal components rendered on top of base content
private focusOrderCounter = 0;
private overlayStack: {
@@ -474,6 +499,8 @@ export class TUI extends Container {
}
stop(): void {
+ // before the exit bookkeeping below, which assumes the primary screen
+ this.exitFullscreen();
this.stopped = true;
if (this.renderTimer) {
clearTimeout(this.renderTimer);
@@ -497,6 +524,7 @@ export class TUI extends Container {
requestRender(force = false): void {
if (force) {
+ this.fullscreen?.viewport.reset();
this.previousLines = [];
this.previousWidth = -1; // -1 triggers widthChanged, forcing a full clear
this.previousHeight = -1; // -1 triggers heightChanged, forcing a full clear
@@ -538,6 +566,100 @@ export class TUI extends Container {
this.requestRender();
}
+ /**
+ * Render a scrollable transcript window on the alternate screen with `dock`
+ * pinned to the bottom rows; the primary screen stays untouched until exit.
+ * Wheel tracking is enabled blind — probing is not viable (tmux never
+ * answers DECRQM) and unsupporting terminals ignore the mode-sets.
+ */
+ enterFullscreen(options: { scroll: Component[]; dock: Component; mouse?: boolean }): void {
+ if (this.fullscreen) return;
+ this.fullscreen = {
+ viewport: new FullscreenViewport(),
+ scroll: options.scroll,
+ dock: options.dock,
+ mouse: options.mouse !== false,
+ inlineState: {
+ previousLines: this.previousLines,
+ previousKittyImageIds: this.previousKittyImageIds,
+ previousWidth: this.previousWidth,
+ previousHeight: this.previousHeight,
+ cursorRow: this.cursorRow,
+ hardwareCursorRow: this.hardwareCursorRow,
+ maxLinesRendered: this.maxLinesRendered,
+ previousViewportTop: this.previousViewportTop,
+ },
+ };
+ this.terminal.enterAltScreen();
+ this.terminal.hideCursor();
+ if (options.mouse !== false) {
+ this.terminal.setMouseTracking(true);
+ }
+ this.requestRender();
+ }
+
+ /**
+ * Leave fullscreen. The inline differ resumes against the entry snapshot,
+ * so content produced while fullscreen flows into native scrollback.
+ */
+ exitFullscreen(): void {
+ if (!this.fullscreen) return;
+ const { inlineState } = this.fullscreen;
+ this.fullscreen = null;
+ this.terminal.setMouseTracking(false);
+ this.terminal.leaveAltScreen();
+ this.previousLines = inlineState.previousLines;
+ this.previousKittyImageIds = inlineState.previousKittyImageIds;
+ this.previousWidth = inlineState.previousWidth;
+ this.previousHeight = inlineState.previousHeight;
+ this.cursorRow = inlineState.cursorRow;
+ this.hardwareCursorRow = inlineState.hardwareCursorRow;
+ this.maxLinesRendered = inlineState.maxLinesRendered;
+ this.previousViewportTop = inlineState.previousViewportTop;
+ // synchronous so the flush also happens on shutdown, where a scheduled render never fires
+ if (!this.stopped) {
+ this.doRender();
+ }
+ }
+
+ isFullscreen(): boolean {
+ return this.fullscreen !== null;
+ }
+
+ /** Scroll the fullscreen transcript window (negative = up). */
+ scrollBy(lines: number): void {
+ if (!this.fullscreen) return;
+ this.fullscreen.viewport.scrollBy(lines);
+ this.requestRender();
+ }
+
+ scrollToTop(): void {
+ if (!this.fullscreen) return;
+ this.fullscreen.viewport.scrollToTop();
+ this.requestRender();
+ }
+
+ scrollToBottom(): void {
+ if (!this.fullscreen) return;
+ this.fullscreen.viewport.scrollToBottom();
+ this.requestRender();
+ }
+
+ /** Scroll state of the fullscreen window, or null when not fullscreen. */
+ getScrollInfo(): ScrollInfo | null {
+ return this.fullscreen?.viewport.scrollInfo() ?? null;
+ }
+
+ private copySelection(text: string): void {
+ if (this.onCopy) {
+ this.onCopy(text);
+ return;
+ }
+ // fallback: OSC 52 works locally, over SSH, and through tmux (set-clipboard)
+ const base64 = Buffer.from(text, "utf8").toString("base64");
+ this.terminal.write(`\x1b]52;c;${base64}\x07`);
+ }
+
private scheduleRender(): void {
if (this.stopped || this.renderTimer || !this.renderRequested) {
return;
@@ -587,6 +709,10 @@ export class TUI extends Container {
return;
}
+ if (this.fullscreen && this.handleFullscreenInput(data)) {
+ return;
+ }
+
// If focused component is an overlay, verify it's still visible
// (visibility can change due to terminal resize or visible() callback)
const focusedOverlay = this.overlayStack.find((o) => o.component === this.focusedComponent);
@@ -613,6 +739,63 @@ export class TUI extends Container {
}
}
+ // Mouse reports are always consumed (nothing downstream understands them);
+ // viewport keys are skipped while an overlay has focus so selectors keep
+ // their own pageUp/pageDown.
+ private handleFullscreenInput(data: string): boolean {
+ const fullscreen = this.fullscreen;
+ if (!fullscreen) return false;
+
+ const overlayFocused = this.overlayStack.some((o) => o.component === this.focusedComponent);
+
+ if (isMouseSequence(data)) {
+ // consumed even when disabled — mouse reports are garbage downstream
+ const event = fullscreen.mouse ? parseSgrMouseEvent(data) : null;
+ if (event && !overlayFocused) {
+ const viewport = fullscreen.viewport;
+ if (isWheelUp(event)) {
+ this.scrollBy(-TUI.WHEEL_SCROLL_LINES);
+ } else if (isWheelDown(event)) {
+ this.scrollBy(TUI.WHEEL_SCROLL_LINES);
+ } else if (event.button === MOUSE_BUTTON_LEFT && event.press && !event.motion) {
+ viewport.beginSelection(event.y - 1, event.x - 1);
+ this.requestRender();
+ } else if (event.button === MOUSE_BUTTON_LEFT && event.press && event.motion) {
+ viewport.extendSelection(event.y - 1, event.x - 1);
+ this.requestRender();
+ } else if (!event.press && viewport.hasSelection()) {
+ const text = viewport.endSelection();
+ if (text) this.copySelection(text);
+ this.requestRender();
+ } else if (!event.press) {
+ viewport.clearSelection();
+ }
+ }
+ return true;
+ }
+
+ if (overlayFocused) return false;
+
+ const keybindings = getKeybindings();
+ if (keybindings.matches(data, "tui.viewport.pageUp")) {
+ this.scrollBy(-fullscreen.viewport.pageSize());
+ return true;
+ }
+ if (keybindings.matches(data, "tui.viewport.pageDown")) {
+ this.scrollBy(fullscreen.viewport.pageSize());
+ return true;
+ }
+ if (keybindings.matches(data, "tui.viewport.top")) {
+ this.scrollToTop();
+ return true;
+ }
+ if (keybindings.matches(data, "tui.viewport.follow")) {
+ this.scrollToBottom();
+ return true;
+ }
+ return false;
+ }
+
private consumeCellSizeResponse(data: string): boolean {
// Response format: ESC [ 6 ; height ; width t
const match = data.match(/^\x1b\[6;(\d+);(\d+)t$/);
@@ -969,8 +1152,54 @@ export class TUI extends Container {
return null;
}
+ private renderFullscreen(): void {
+ const fullscreen = this.fullscreen;
+ if (!fullscreen) return;
+ const width = this.terminal.columns;
+ const height = this.terminal.rows;
+
+ const transcript: string[] = [];
+ for (const component of fullscreen.scroll) {
+ for (const line of component.render(width)) {
+ transcript.push(line);
+ }
+ }
+ const dock = fullscreen.dock.render(width);
+
+ let frame = fullscreen.viewport.composeFrame(transcript, dock, height);
+ const scrollInfo = fullscreen.viewport.scrollInfo();
+ if (!scrollInfo.following) {
+ // Follow hint composited over the bottom of the transcript window,
+ // just above the dock. Overlays still paint on top of it.
+ const followKey = getKeybindings().getKeys("tui.viewport.follow")[0] ?? "alt+down";
+ const label = ` ${followKey} to follow `;
+ const labelWidth = visibleWidth(label);
+ const row = fullscreen.viewport.windowHeight() - 1;
+ if (row >= 0 && row < frame.length && labelWidth <= width) {
+ const col = Math.floor((width - labelWidth) / 2);
+ frame[row] = this.compositeLineAt(frame[row], `\x1b[7m${label}\x1b[27m`, col, labelWidth, width);
+ }
+ }
+ if (this.overlayStack.length > 0) {
+ frame = this.compositeOverlays(frame, width, height);
+ }
+ const cursorPos = this.extractCursorPosition(frame, height);
+ this.applyLineResets(frame);
+ fullscreen.viewport.paint((data) => this.terminal.write(data), frame, width, height, cursorPos);
+ if (cursorPos && this.showHardwareCursor) {
+ this.terminal.showCursor();
+ } else {
+ this.terminal.hideCursor();
+ }
+ }
+
private doRender(): void {
if (this.stopped) return;
+ if (this.fullscreen) {
+ this.preserveViewportOnNextRender = false;
+ this.renderFullscreen();
+ return;
+ }
// One-shot: consume here so it never leaks into a later render.
const preserveViewport = this.preserveViewportOnNextRender;
this.preserveViewportOnNextRender = false;
diff --git a/packages/tui/src/utils.ts b/packages/tui/src/utils.ts
index b5c196e18e..b049a0d808 100644
--- a/packages/tui/src/utils.ts
+++ b/packages/tui/src/utils.ts
@@ -765,6 +765,11 @@ function wrapSingleLine(line: string, width: number): string[] {
const PUNCTUATION_REGEX = /[(){}[\]<>.,;:'"!?+\-=*/\\|&%^$#@~`]/;
+/** Remove all escape sequences (CSI, OSC, DCS/APC, two-char) leaving plain text. */
+export function stripAnsi(str: string): string {
+ return str.replace(/\x1b(?:\[[0-9;:?<=>]*[\x40-\x7e]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[P_^X][^\x1b]*\x1b\\|.)/g, "");
+}
+
/**
* Check if a character is whitespace.
*/
diff --git a/packages/tui/test/fullscreen.test.ts b/packages/tui/test/fullscreen.test.ts
new file mode 100644
index 0000000000..1403c43e81
--- /dev/null
+++ b/packages/tui/test/fullscreen.test.ts
@@ -0,0 +1,363 @@
+import assert from "node:assert";
+import { describe, it } from "node:test";
+import { type Component, TUI } from "../src/tui.js";
+import { VirtualTerminal } from "./virtual-terminal.js";
+
+class TestComponent implements Component {
+ lines: string[] = [];
+ render(_width: number): string[] {
+ return this.lines;
+ }
+ invalidate(): void {}
+}
+
+class LoggingVirtualTerminal extends VirtualTerminal {
+ private writes: string[] = [];
+
+ override write(data: string): void {
+ this.writes.push(data);
+ super.write(data);
+ }
+
+ getWrites(): string {
+ return this.writes.join("");
+ }
+
+ clearWrites(): void {
+ this.writes = [];
+ }
+}
+
+const WHEEL_UP = "\x1b[<64;5;5M";
+const WHEEL_DOWN = "\x1b[<65;5;5M";
+const PAGE_UP = "\x1b[5~";
+const VIEWPORT_TOP = "\x1b[1;4A"; // shift+alt+up
+const FOLLOW = "\x1b[1;3B"; // alt+down
+
+interface Setup {
+ terminal: LoggingVirtualTerminal;
+ tui: TUI;
+ chat: TestComponent;
+ dock: TestComponent;
+}
+
+function setup(transcriptLines: string[], cols = 40, rows = 10): Setup {
+ const terminal = new LoggingVirtualTerminal(cols, rows);
+ const tui = new TUI(terminal);
+ const chat = new TestComponent();
+ chat.lines = transcriptLines;
+ const dock = new TestComponent();
+ dock.lines = ["> prompt", "footer"];
+ // Children drive inline rendering (before enter / after exit); the same
+ // components are passed explicitly as fullscreen scroll/dock roots.
+ tui.addChild(chat);
+ tui.addChild(dock);
+ tui.start();
+ return { terminal, tui, chat, dock };
+}
+
+function lines(count: number, prefix = "Line"): string[] {
+ return Array.from({ length: count }, (_, i) => `${prefix} ${i}`);
+}
+
+describe("TUI fullscreen mode", () => {
+ it("enters the alt screen and lays out transcript window above the dock", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(20));
+ await terminal.waitForRender();
+
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ assert.strictEqual(tui.isFullscreen(), true);
+ assert.strictEqual(terminal.getActiveBufferType(), "alternate");
+ assert.strictEqual(terminal.mouseTrackingActive, true, "probe succeeds → wheel tracking enabled");
+
+ // rows=10, dock=2 → window shows the last 8 of 20 transcript lines
+ const viewport = terminal.getViewport();
+ assert.strictEqual(viewport[0], "Line 12");
+ assert.strictEqual(viewport[7], "Line 19");
+ assert.strictEqual(viewport[8], "> prompt");
+ assert.strictEqual(viewport[9], "footer");
+
+ tui.stop();
+ });
+
+ it("keeps the window pinned to the bottom while following", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(20));
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ chat.lines = lines(25);
+ tui.requestRender();
+ await terminal.waitForRender();
+
+ const viewport = terminal.getViewport();
+ assert.strictEqual(viewport[7], "Line 24", "window follows appended content");
+ assert.strictEqual(viewport[8], "> prompt", "dock stays pinned");
+
+ tui.stop();
+ });
+
+ it("wheel up unfollows and freezes the window while content appends", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(20));
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ terminal.sendInput(WHEEL_UP);
+ await terminal.waitForRender();
+
+ let viewport = terminal.getViewport();
+ assert.strictEqual(viewport[0], "Line 9", "wheel scrolls up 3 lines");
+ assert.strictEqual(tui.getScrollInfo()?.following, false);
+
+ chat.lines = lines(40);
+ tui.requestRender();
+ await terminal.waitForRender();
+
+ viewport = terminal.getViewport();
+ assert.strictEqual(viewport[0], "Line 9", "appended content does not move the window");
+ assert.strictEqual(viewport[8], "> prompt", "dock still visible");
+ assert.strictEqual(tui.getScrollInfo()?.linesBelow, 23);
+ assert.ok(viewport[7]?.includes("to follow"), "follow hint composited above the dock");
+
+ tui.stop();
+ });
+
+ it("hides the follow hint while following", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(20));
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ assert.ok(!terminal.getViewport().join("\n").includes("to follow"));
+
+ terminal.sendInput(WHEEL_UP);
+ await terminal.waitForRender();
+ assert.ok(terminal.getViewport().join("\n").includes("to follow"));
+
+ terminal.sendInput(FOLLOW);
+ await terminal.waitForRender();
+ assert.ok(!terminal.getViewport().join("\n").includes("to follow"));
+
+ tui.stop();
+ });
+
+ it("scrolling back to the bottom resumes following", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(20));
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ terminal.sendInput(WHEEL_UP);
+ await terminal.waitForRender();
+ assert.strictEqual(tui.getScrollInfo()?.following, false);
+
+ terminal.sendInput(WHEEL_DOWN);
+ await terminal.waitForRender();
+ assert.strictEqual(tui.getScrollInfo()?.following, true);
+
+ chat.lines = lines(22);
+ tui.requestRender();
+ await terminal.waitForRender();
+ assert.strictEqual(terminal.getViewport()[7], "Line 21");
+
+ tui.stop();
+ });
+
+ it("page and home/end keys scroll the window while the editor keeps focus", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(30));
+ const editor = new TestComponent();
+ tui.setFocus(editor);
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ terminal.sendInput(PAGE_UP);
+ await terminal.waitForRender();
+ // window height 8 → page size 7; top was 22, now 15
+ assert.strictEqual(terminal.getViewport()[0], "Line 15");
+
+ terminal.sendInput(VIEWPORT_TOP);
+ await terminal.waitForRender();
+ assert.strictEqual(terminal.getViewport()[0], "Line 0");
+ assert.strictEqual(tui.getScrollInfo()?.following, false);
+
+ terminal.sendInput(FOLLOW);
+ await terminal.waitForRender();
+ assert.strictEqual(terminal.getViewport()[7], "Line 29");
+ assert.strictEqual(tui.getScrollInfo()?.following, true);
+
+ tui.stop();
+ });
+
+ it("row-diffs frames: only changed rows are repainted", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(20));
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+ terminal.clearWrites();
+
+ chat.lines = [...lines(19), "Line 19 changed"];
+ tui.requestRender();
+ await terminal.waitForRender();
+
+ const writes = terminal.getWrites();
+ assert.ok(!writes.includes("\x1b[2J"), "no full clear for a single-line change");
+ assert.ok(writes.includes("\x1b[8;1H"), "repaints the changed row (window row 8)");
+ const repaintedRows = writes.match(/\x1b\[\d+;1H\x1b\[2K/g) ?? [];
+ assert.strictEqual(repaintedRows.length, 1, "exactly one row repainted");
+ assert.strictEqual(terminal.getViewport()[7], "Line 19 changed");
+
+ tui.stop();
+ });
+
+ it("resize repaints the whole frame and clamps the scroll position", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(30));
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ terminal.sendInput(VIEWPORT_TOP);
+ await terminal.waitForRender();
+ terminal.clearWrites();
+
+ terminal.resize(40, 20);
+ await terminal.waitForRender();
+
+ assert.ok(terminal.getWrites().includes("\x1b[2J"), "resize forces a full frame repaint");
+ const viewport = terminal.getViewport();
+ assert.strictEqual(viewport[0], "Line 0", "scroll position clamped, still at top");
+ assert.strictEqual(viewport[18], "> prompt", "dock re-anchored to the new bottom");
+
+ tui.stop();
+ });
+
+ it("composites overlays onto the fullscreen frame", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(20));
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ const overlay = new TestComponent();
+ overlay.lines = ["OVERLAY CONTENT"];
+ const handle = tui.showOverlay(overlay, { anchor: "center", width: 20 });
+ await terminal.waitForRender();
+
+ assert.ok(
+ terminal.getViewport().some((line) => line.includes("OVERLAY CONTENT")),
+ "overlay visible on the fullscreen frame",
+ );
+
+ handle.hide();
+ await terminal.waitForRender();
+ assert.ok(!terminal.getViewport().some((line) => line.includes("OVERLAY CONTENT")));
+
+ tui.stop();
+ });
+
+ it("exit restores the primary screen and flushes fullscreen-era content into scrollback", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(5));
+ await terminal.waitForRender();
+
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+ assert.strictEqual(terminal.getActiveBufferType(), "alternate");
+
+ chat.lines = lines(30);
+ tui.requestRender();
+ await terminal.waitForRender();
+
+ tui.exitFullscreen();
+ await terminal.waitForRender();
+
+ assert.strictEqual(tui.isFullscreen(), false);
+ assert.strictEqual(terminal.getActiveBufferType(), "normal");
+ assert.strictEqual(terminal.mouseTrackingActive, false);
+ const scrollBuffer = terminal.getScrollBuffer().join("\n");
+ assert.ok(scrollBuffer.includes("Line 29"), "content appended while fullscreen reached the primary buffer");
+ assert.ok(scrollBuffer.includes("Line 0"), "pre-fullscreen content still present");
+
+ tui.stop();
+ });
+
+ it("stop() leaves the alt screen and disables mouse tracking", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(20));
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ tui.stop();
+ await terminal.flush();
+
+ assert.strictEqual(terminal.getActiveBufferType(), "normal");
+ assert.strictEqual(terminal.mouseTrackingActive, false);
+ });
+
+ it("drag-selecting copies the selected text on release", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(20));
+ const copies: string[] = [];
+ tui.onCopy = (text) => copies.push(text);
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ // window shows lines 12-19; press on row 1 col 1, drag to row 2 col 6
+ terminal.sendInput("\x1b[<0;1;1M");
+ terminal.sendInput("\x1b[<32;6;2M");
+ await terminal.waitForRender();
+ assert.ok(terminal.getWrites().includes("\x1b[7m"), "selection highlighted while dragging");
+
+ terminal.sendInput("\x1b[<0;6;2m");
+ await terminal.waitForRender();
+ assert.deepStrictEqual(copies, ["Line 12\nLine"]);
+
+ tui.stop();
+ });
+
+ it("writes OSC 52 when no copy handler is set", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(20));
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+ terminal.clearWrites();
+
+ terminal.sendInput("\x1b[<0;1;1M");
+ terminal.sendInput("\x1b[<32;8;1M");
+ terminal.sendInput("\x1b[<0;8;1m");
+ await terminal.waitForRender();
+
+ const expected = Buffer.from("Line 12", "utf8").toString("base64");
+ assert.ok(terminal.getWrites().includes(`\x1b]52;c;${expected}\x07`));
+
+ tui.stop();
+ });
+
+ it("a plain click copies nothing and clears any selection", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(20));
+ const copies: string[] = [];
+ tui.onCopy = (text) => copies.push(text);
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ terminal.sendInput("\x1b[<0;5;3M");
+ terminal.sendInput("\x1b[<0;5;3m");
+ await terminal.waitForRender();
+
+ assert.deepStrictEqual(copies, []);
+
+ tui.stop();
+ });
+
+ it("mouse reports are consumed and never reach the focused component", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(20));
+ const received: string[] = [];
+ const editor: Component = {
+ render: () => [],
+ invalidate: () => {},
+ handleInput: (data: string) => received.push(data),
+ };
+ tui.setFocus(editor);
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ terminal.sendInput(WHEEL_UP);
+ terminal.sendInput("\x1b[<0;3;3M"); // left click
+ terminal.sendInput("a");
+ await terminal.waitForRender();
+
+ assert.deepStrictEqual(received, ["a"], "only keyboard input reaches the editor");
+
+ tui.stop();
+ });
+});
diff --git a/packages/tui/test/mouse.test.ts b/packages/tui/test/mouse.test.ts
new file mode 100644
index 0000000000..73dfa5950f
--- /dev/null
+++ b/packages/tui/test/mouse.test.ts
@@ -0,0 +1,93 @@
+import assert from "node:assert";
+import { describe, it } from "node:test";
+import { isMouseSequence, isWheelDown, isWheelUp, parseSgrMouseEvent } from "../src/mouse.js";
+import { StdinBuffer } from "../src/stdin-buffer.js";
+
+describe("parseSgrMouseEvent", () => {
+ it("parses wheel up and wheel down", () => {
+ const up = parseSgrMouseEvent("\x1b[<64;10;5M");
+ assert.deepStrictEqual(up, {
+ button: 64,
+ x: 10,
+ y: 5,
+ press: true,
+ motion: false,
+ shift: false,
+ alt: false,
+ ctrl: false,
+ });
+ assert.strictEqual(isWheelUp(up!), true);
+ assert.strictEqual(isWheelDown(up!), false);
+
+ const down = parseSgrMouseEvent("\x1b[<65;1;1M");
+ assert.strictEqual(isWheelDown(down!), true);
+ assert.strictEqual(isWheelUp(down!), false);
+ });
+
+ it("strips modifier bits into flags", () => {
+ // 64 + shift(4) + ctrl(16) = 84
+ const event = parseSgrMouseEvent("\x1b[<84;3;7M");
+ assert.strictEqual(event!.button, 64);
+ assert.strictEqual(event!.shift, true);
+ assert.strictEqual(event!.ctrl, true);
+ assert.strictEqual(event!.alt, false);
+ assert.strictEqual(isWheelUp(event!), true);
+ });
+
+ it("distinguishes press from release", () => {
+ assert.strictEqual(parseSgrMouseEvent("\x1b[<0;5;5M")?.press, true);
+ assert.strictEqual(parseSgrMouseEvent("\x1b[<0;5;5m")?.press, false);
+ });
+
+ it("flags drag motion and strips the motion bit from the button", () => {
+ const drag = parseSgrMouseEvent("\x1b[<32;5;5M");
+ assert.strictEqual(drag?.motion, true);
+ assert.strictEqual(drag?.button, 0);
+ assert.strictEqual(parseSgrMouseEvent("\x1b[<0;5;5M")?.motion, false);
+ });
+
+ it("returns null for non-mouse input", () => {
+ assert.strictEqual(parseSgrMouseEvent("\x1b[A"), null);
+ assert.strictEqual(parseSgrMouseEvent("a"), null);
+ assert.strictEqual(parseSgrMouseEvent("\x1b[<64;10M"), null);
+ });
+});
+
+describe("isMouseSequence", () => {
+ it("matches SGR and legacy mouse reports", () => {
+ assert.strictEqual(isMouseSequence("\x1b[<64;10;5M"), true);
+ assert.strictEqual(isMouseSequence("\x1b[M "), true);
+ assert.strictEqual(isMouseSequence("\x1b[A"), false);
+ });
+});
+
+describe("SGR mouse through StdinBuffer", () => {
+ it("assembles a sequence that arrives split across chunks", () => {
+ const buffer = new StdinBuffer({ timeout: 10 });
+ const received: string[] = [];
+ buffer.on("data", (seq) => received.push(seq));
+
+ buffer.process("\x1b");
+ buffer.process("[<64");
+ buffer.process(";20;5M");
+
+ assert.deepStrictEqual(received, ["\x1b[<64;20;5M"]);
+ const event = parseSgrMouseEvent(received[0]!);
+ assert.strictEqual(event!.button, 64);
+ assert.strictEqual(event!.x, 20);
+ assert.strictEqual(event!.y, 5);
+ buffer.destroy();
+ });
+
+ it("assembles a DECRPM mouse-probe response", () => {
+ const buffer = new StdinBuffer({ timeout: 10 });
+ const received: string[] = [];
+ buffer.on("data", (seq) => received.push(seq));
+
+ buffer.process("\x1b[?1006;");
+ buffer.process("2$y");
+
+ assert.deepStrictEqual(received, ["\x1b[?1006;2$y"]);
+ buffer.destroy();
+ });
+});
diff --git a/packages/tui/test/virtual-terminal.ts b/packages/tui/test/virtual-terminal.ts
index c7ca45102d..400f6fe9c3 100644
--- a/packages/tui/test/virtual-terminal.ts
+++ b/packages/tui/test/virtual-terminal.ts
@@ -14,6 +14,8 @@ export class VirtualTerminal implements Terminal {
private resizeHandler?: () => void;
private _columns: number;
private _rows: number;
+ private _altScreenActive = false;
+ private _mouseTrackingActive = false;
constructor(columns = 80, rows = 24) {
this._columns = columns;
@@ -95,6 +97,28 @@ export class VirtualTerminal implements Terminal {
this.xterm.write("\x1b[2J\x1b[H"); // Clear screen and move to home (1,1)
}
+ enterAltScreen(): void {
+ this._altScreenActive = true;
+ this.write("\x1b[?1049h");
+ }
+
+ leaveAltScreen(): void {
+ this._altScreenActive = false;
+ this.write("\x1b[?1049l");
+ }
+
+ get altScreenActive(): boolean {
+ return this._altScreenActive;
+ }
+
+ setMouseTracking(enabled: boolean): void {
+ this._mouseTrackingActive = enabled;
+ }
+
+ get mouseTrackingActive(): boolean {
+ return this._mouseTrackingActive;
+ }
+
setTitle(title: string): void {
// OSC 0;title BEL - set terminal window title
this.xterm.write(`\x1b]0;${title}\x07`);
@@ -209,6 +233,11 @@ export class VirtualTerminal implements Terminal {
};
}
+ /** Which xterm buffer is active: "normal" or "alternate". */
+ getActiveBufferType(): "normal" | "alternate" {
+ return this.xterm.buffer.active.type;
+ }
+
/** Wait for TUI's throttled render pipeline to settle. */
async waitForRender(): Promise<void> {
await new Promise<void>((resolve) => process.nextTick(resolve));