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
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ export class AgentManagerProvider implements vscode.Disposable {
this.terminalManager.showTerminal(msg.sessionId, this.state)
return null
}
if (type === "agentManager.showLocalTerminal") {
this.terminalManager.showLocalTerminal()
return null
}
if (type === "agentManager.showExistingLocalTerminal") {
this.terminalManager.showExistingLocal()
return null
}
if (type === "agentManager.requestRepoInfo") {
void this.sendRepoInfo()
return null
Expand Down
26 changes: 26 additions & 0 deletions packages/kilo-vscode/src/agent-manager/SessionTerminalManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,32 @@ export class SessionTerminalManager {
this.showOrCreate(sessionId, cwd, name)
}

/**
* Show (or create) a terminal for the local workspace (no session required).
* Used when the user triggers a terminal in local mode without an active session.
*/
private static readonly LOCAL_KEY = "__local__"

showLocalTerminal(): void {
if (this.showExisting(SessionTerminalManager.LOCAL_KEY, false)) return

const cwd = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath
if (!cwd) {
this.log("showLocalTerminal: no workspace folder open")
vscode.window.showWarningMessage("Open a folder to use the local terminal")
return
}

this.showOrCreate(SessionTerminalManager.LOCAL_KEY, cwd, "Agent: local")
}

/**
* Show the existing local terminal if one was previously created (used on context switch).
*/
showExistingLocal(): boolean {
return this.showExisting(SessionTerminalManager.LOCAL_KEY)
}

/**
* Show the terminal for a session if it already exists (used when switching sessions).
* Returns true if the terminal was shown, false if no terminal exists for the session.
Expand Down
2 changes: 2 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 @@ -158,6 +158,8 @@ describe("Agent Manager Provider — onMessage routing", () => {
"agentManager.closeSession",
"agentManager.configureSetupScript",
"agentManager.showTerminal",
"agentManager.showLocalTerminal",
"agentManager.showExistingLocalTerminal",
"agentManager.requestRepoInfo",
"agentManager.requestState",
"agentManager.setTabOrder",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,11 @@ const AgentManagerContent: Component = () => {
} else if (fallback && isPending(fallback.id)) {
setActivePendingId(fallback.id)
session.clearCurrentSession()
vscode.postMessage({ type: "agentManager.showExistingLocalTerminal" })
} else {
setActivePendingId(undefined)
session.clearCurrentSession()
vscode.postMessage({ type: "agentManager.showExistingLocalTerminal" })
}
}

Expand Down Expand Up @@ -612,6 +614,7 @@ const AgentManagerContent: Component = () => {
else if (msg.action === "showTerminal") {
const id = session.currentSessionID()
if (id) vscode.postMessage({ type: "agentManager.showTerminal", sessionId: id })
else if (selection() === LOCAL) vscode.postMessage({ type: "agentManager.showLocalTerminal" })
} else if (msg.action === "toggleDiff") {
setDiffOpen((prev) => !prev)
} else if (msg.action === "newTab") handleNewTabForCurrentSelection()
Expand Down Expand Up @@ -1713,6 +1716,7 @@ const AgentManagerContent: Component = () => {
onClick={() => {
const id = session.currentSessionID()
if (id) vscode.postMessage({ type: "agentManager.showTerminal", sessionId: id })
else if (selection() === LOCAL) vscode.postMessage({ type: "agentManager.showLocalTerminal" })
}}
/>
</TooltipKeybind>
Expand Down
12 changes: 12 additions & 0 deletions packages/kilo-vscode/webview-ui/src/types/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,16 @@ export interface ShowTerminalRequest {
sessionId: string
}

// Show terminal for the local workspace (when no session is active)
export interface ShowLocalTerminalRequest {
type: "agentManager.showLocalTerminal"
}

// Show existing local terminal when switching to local context (no-op if none exists)
export interface ShowExistingLocalTerminalRequest {
type: "agentManager.showExistingLocalTerminal"
}

/**
* Maximum number of parallel worktree versions for multi-version mode.
* Keep in sync with MAX_MULTI_VERSIONS in src/agent-manager/constants.ts.
Expand Down Expand Up @@ -1264,6 +1274,8 @@ export type WebviewMessage =
| RequestStateMessage
| ConfigureSetupScriptRequest
| ShowTerminalRequest
| ShowLocalTerminalRequest
| ShowExistingLocalTerminalRequest
| CreateMultiVersionRequest
| SetTabOrderRequest
| SetSessionsCollapsedRequest
Expand Down
Loading