Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/terminal-integrated-font.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-vscode": patch
---

Agent Manager terminals now use `terminal.integrated.fontFamily` and `terminal.integrated.fontSize` (including Nerd Font glyphs) instead of the editor font.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { parseToolRequest, startFromTool, type ToolRequest } from "./tool-start"
import { stopSessionProcesses } from "../kilo-provider/background-process"

import { startSession } from "./mcp-warmup"
import { readTerminalFont, watchTerminalFont } from "./terminal-font"
import { buildKeybindingMap } from "./format-keybinding"
import { resolveVersionModels, buildInitialMessages, type CreatedVersion } from "./multi-version"
import { Semaphore } from "./semaphore"
Expand Down Expand Up @@ -73,6 +74,7 @@ export class AgentManagerProvider implements Disposable {
private cachedWorktreeStats: { type: "agentManager.worktreeStats"; stats: WorktreeStats[] } | undefined
private cachedLocalStats: { type: "agentManager.localStats"; stats: LocalStats } | undefined
private unsubTool: (() => void) | undefined
private unsubFont: (() => void) | undefined
private closing: Promise<void> | undefined
private onVisibilityChange: ((visible: boolean) => void) | undefined

Expand All @@ -96,6 +98,10 @@ export class AgentManagerProvider implements Disposable {
getWorktreePath: (id) => this.getStateManager()?.getWorktree(id)?.path,
log: (...args) => this.log("[XTerm]", ...args),
post: (msg) => this.postToWebview(msg),
getTerminalFont: () => readTerminalFont(),
})
this.unsubFont = watchTerminalFont((font) => {
this.postToWebview({ type: "agentManager.terminal.fontChanged", font })
})
this.run = new RunController({
root: () => this.getRoot(),
Expand Down Expand Up @@ -1791,6 +1797,7 @@ export class AgentManagerProvider implements Disposable {
await this.stateReady?.catch((err) => this.log("dispose: stateReady rejected:", err))
await this.state?.flush().catch((err) => this.log("dispose: state flush failed:", err))
this.unsubTool?.()
this.unsubFont?.()
this.connectionService.unregisterFocused("agent-manager")
this.connectionService.registerOpen("agent-manager", [])
this.diffs.stop()
Expand Down
57 changes: 57 additions & 0 deletions packages/kilo-vscode/src/agent-manager/terminal-font.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Helpers to read and watch the user's integrated-terminal font settings.
*
* VS Code's integrated terminal falls back to the editor font family when
* its own family is unset. Font size has a separate platform default. We
* replicate those settings for Agent Manager xterm instances.
*/

import * as vscode from "vscode"

export interface TerminalFont {
fontFamily: string
fontSize: number
}

const FALLBACK = "Menlo, Monaco, 'Courier New', monospace"
const SIZE = process.platform === "darwin" ? 12 : 14

export function resolveTerminalFont(
family: string | undefined,
size: number | undefined,
editor: string | undefined,
): TerminalFont {
return {
fontFamily: family?.trim() || editor?.trim() || FALLBACK,
fontSize: size ?? SIZE,
}
}

/** Resolve the user's integrated-terminal font, mirroring VS Code's own
* family fallback while preserving the terminal's independent size. */
export function readTerminalFont(): TerminalFont {
const term = vscode.workspace.getConfiguration("terminal.integrated")
const editor = vscode.workspace.getConfiguration("editor")
return resolveTerminalFont(
term.get<string>("fontFamily"),
term.get<number>("fontSize"),
editor.get<string>("fontFamily"),
)
}

/** True when a config change affects the effective terminal family or size. */
export function affectsTerminalFont(e: vscode.ConfigurationChangeEvent): boolean {
return (
e.affectsConfiguration("terminal.integrated.fontFamily") ||
e.affectsConfiguration("terminal.integrated.fontSize") ||
e.affectsConfiguration("editor.fontFamily")
)
}

/** Subscribe to terminal-font config changes. Returns a cleanup function. */
export function watchTerminalFont(callback: (font: TerminalFont) => void): () => void {
const sub = vscode.workspace.onDidChangeConfiguration((e) => {
if (affectsTerminalFont(e)) callback(readTerminalFont())
})
return () => sub.dispose()
}
5 changes: 4 additions & 1 deletion packages/kilo-vscode/src/agent-manager/terminal-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import type { KiloClient } from "@kilocode/sdk/v2/client"
import type { AgentManagerInMessage, AgentManagerOutMessage } from "./types"
import type { AgentManagerInMessage, AgentManagerOutMessage, TerminalFont } from "./types"
import { TerminalManager } from "./terminal-manager"

interface ServerConfig {
Expand All @@ -36,6 +36,8 @@ export interface TerminalRoutingDeps {
log(...args: unknown[]): void
/** Send a message back to the webview. */
post(message: AgentManagerOutMessage): void
/** Return the current terminal font settings. */
getTerminalFont(): TerminalFont
}

/** True iff the message belongs to the terminal-tab subsystem. */
Expand Down Expand Up @@ -106,6 +108,7 @@ export class TerminalRouter {
terminalId: created.terminalId,
title: created.title,
wsUrl: created.wsUrl,
font: this.deps.getTerminalFont(),
})
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
Expand Down
10 changes: 10 additions & 0 deletions packages/kilo-vscode/src/agent-manager/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import type { ApplyConflict } from "./GitOps"
import type { BranchListItem, WorktreeSetupErrorCode } from "./git-import"
import type { ExternalWorktreeItem } from "./WorktreeManager"
import type { RunStatus } from "./run/manager"
import type { TerminalFont } from "./terminal-font"

export type { TerminalFont }

// ---------------------------------------------------------------------------
// Shared payload types
Expand Down Expand Up @@ -147,6 +150,7 @@ interface TerminalCreatedMessage {
terminalId: string
title: string
wsUrl: string
font: TerminalFont
}

interface TerminalClosedMessage {
Expand All @@ -160,6 +164,11 @@ interface TerminalErrorMessage {
message: string
}

interface TerminalFontChangedMessage {
type: "agentManager.terminal.fontChanged"
font: TerminalFont
}

interface ErrorOutMessage {
type: "error"
message: string
Expand Down Expand Up @@ -314,6 +323,7 @@ export type AgentManagerOutMessage =
| TerminalCreatedMessage
| TerminalClosedMessage
| TerminalErrorMessage
| TerminalFontChangedMessage

// ---------------------------------------------------------------------------
// Webview → Extension messages (onMessage)
Expand Down
4 changes: 4 additions & 0 deletions packages/kilo-vscode/tests/unit/agent-manager-arch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,10 @@ const VSCODE_ALLOWED: Record<string, { note: string }> = {
"run/task.ts": {
note: "vscode adapter for Agent Manager run scripts",
},
// Reads terminal.integrated.* and editor.font* config for xterm font settings
"terminal-font.ts": {
note: "vscode config reader for integrated terminal font settings",
},
}

/**
Expand Down
101 changes: 101 additions & 0 deletions packages/kilo-vscode/tests/unit/agent-manager-terminal-font.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { describe, expect, it } from "bun:test"
import type { KiloClient } from "@kilocode/sdk/v2/client"
import { createRoot } from "solid-js"
import { affectsTerminalFont, resolveTerminalFont } from "../../src/agent-manager/terminal-font"
import { TerminalRouter } from "../../src/agent-manager/terminal-routing"
import type { AgentManagerOutMessage, TerminalFont } from "../../src/agent-manager/types"
import { createTerminalMessageHandler, createTerminalState } from "../../webview-ui/agent-manager/terminal/state"
import { LOCAL } from "../../webview-ui/agent-manager/navigate"
import type { ExtensionMessage } from "../../webview-ui/src/types/messages/extension-messages"

const font: TerminalFont = {
fontFamily: "MesloLGS NF",
fontSize: 18,
}

describe("Agent Manager terminal font", () => {
it("resolves terminal settings without inheriting the editor size", () => {
expect(resolveTerminalFont(undefined, undefined, undefined)).toEqual({
fontFamily: "Menlo, Monaco, 'Courier New', monospace",
fontSize: process.platform === "darwin" ? 12 : 14,
})
expect(resolveTerminalFont("MesloLGS NF", 16, "Menlo")).toEqual({
fontFamily: "MesloLGS NF",
fontSize: 16,
})
expect(resolveTerminalFont(undefined, 16, "Menlo")).toEqual({
fontFamily: "Menlo",
fontSize: 16,
})
})

it("watches only settings that affect the terminal family or size", () => {
const event = (key: string) =>
({
affectsConfiguration: (target: string) => target === key,
}) as Parameters<typeof affectsTerminalFont>[0]

expect(affectsTerminalFont(event("terminal.integrated.fontFamily"))).toBe(true)
expect(affectsTerminalFont(event("terminal.integrated.fontSize"))).toBe(true)
expect(affectsTerminalFont(event("editor.fontFamily"))).toBe(true)
expect(affectsTerminalFont(event("editor.fontSize"))).toBe(false)
expect(affectsTerminalFont(event("terminal.integrated.letterSpacing"))).toBe(false)
})

it("includes the current font when creating a terminal", async () => {
const client = {
pty: {
create: async () => ({ data: { id: "pty-1", title: "Terminal 1" } }),
remove: async () => ({ data: true }),
update: async () => ({ data: true }),
},
} as unknown as KiloClient
const message = new Promise<AgentManagerOutMessage>((resolve) => {
const router = new TerminalRouter({
getClient: () => client,
getServerConfig: () => ({ baseUrl: "http://127.0.0.1:4096", password: "secret" }),
getRoot: () => "/workspace",
getWorktreePath: () => undefined,
log: () => undefined,
post: resolve,
getTerminalFont: () => font,
})

expect(router.handle({ type: "agentManager.terminal.create", worktreeId: null })).toBe(true)
})

const created = await message
expect(created.type).toBe("agentManager.terminal.created")
if (created.type !== "agentManager.terminal.created") return
expect(created.font).toEqual(font)
expect(created.worktreeId).toBeNull()
expect(created.wsUrl).toContain("/pty/pty-1/connect")
})

it("keeps the created font in terminal state", () => {
createRoot((dispose) => {
const state = createTerminalState(() => LOCAL)
const activated: string[] = []
const handler = createTerminalMessageHandler({
state,
activate: (id) => activated.push(id),
saveTabMemory: () => undefined,
setSelection: () => undefined,
showError: () => undefined,
})
const message = {
type: "agentManager.terminal.created",
worktreeId: null,
terminalId: "terminal-1",
title: "Terminal 1",
wsUrl: "ws://127.0.0.1/pty/pty-1/connect",
font,
} satisfies ExtensionMessage

expect(handler(message)).toBe(true)
expect(state.forSelection(LOCAL)[0]?.font).toEqual(font)
expect(activated).toEqual(["terminal-1"])
dispose()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ const AgentManagerContent: Component = () => {
onCreated: (contextKey, terminalId) => appendToTabOrder(contextKey, terminalId),
})
const unsubTerminals = vscode.onMessage((msg) => {
terminalDispatch(msg as unknown as { type: string } & Record<string, unknown>)
terminalDispatch(msg)
})

const unsub = vscode.onMessage((msg) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ import "@xterm/xterm/css/xterm.css"
import { useVSCode } from "../../src/context/vscode"
import { useLanguage } from "../../src/context/language"
import { formatReviewCommentsMarkdown } from "../../src/utils/review-comment-markdown"
import type { TerminalFont } from "./state"

interface Props {
terminalId: string
wsUrl: string
/** Terminal font settings forwarded from the extension host. Used on
* initial mount; live changes arrive via `agentManager.terminal.fontChanged`. */
font: TerminalFont
/** Whether this terminal is currently the focused tab.
*
* The xterm subtree always stays in the paint tree (see the layer /
Expand Down Expand Up @@ -126,8 +130,8 @@ export const TerminalTab: Component<Props> = (props) => {
const term = new Terminal({
convertEol: true,
cursorBlink: true,
fontFamily: cssVar("--vscode-editor-font-family", "Menlo, Monaco, 'Courier New', monospace"),
fontSize: Number.parseFloat(cssVar("--font-size-base", "13px")),
fontFamily: props.font.fontFamily,
fontSize: props.font.fontSize,
scrollback: 5000,
theme: readTheme(),
allowProposedApi: true,
Expand Down Expand Up @@ -268,6 +272,7 @@ export const TerminalTab: Component<Props> = (props) => {
if (!isRenderable()) return
try {
fit.fit()
syncSize()
} catch (err) {
// Layout not settled yet; ResizeObserver retries on next change.
log("repaint fit() threw", err)
Expand All @@ -288,12 +293,19 @@ export const TerminalTab: Component<Props> = (props) => {
return
}

if (message.type === "agentManager.terminal.fontChanged") {
term.options.fontFamily = message.font.fontFamily
term.options.fontSize = message.font.fontSize
scheduleRepaint()
return
}

// fontSizeChanged/ready control the Kilo chat UI font — do not apply
// them to the terminal, which has its own independent font settings.
// Keep the repaint for any downstream layout side-effects.
const size =
message.type === "fontSizeChanged" ? message.fontSize : message.type === "ready" ? message.fontSize : undefined
if (size === undefined) return
term.options.fontSize = size
fit.fit()
syncSize()
scheduleRepaint()
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function renderTerminalLayer(props: { state: TerminalStateControls }): JS
const visible = () => slotVisible(term.id, term.contextKey)
return (
<div class={`am-terminal-slot ${visible() ? "am-terminal-slot-visible" : ""}`}>
<TerminalTab terminalId={term.id} wsUrl={term.wsUrl} active={visible()} />
<TerminalTab terminalId={term.id} wsUrl={term.wsUrl} active={visible()} font={term.font} />
</div>
)
}}
Expand Down
Loading
Loading