Repository navigation
feat(agent-manager): attach focused terminal context #13230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "kilo-code": patch | ||
| --- | ||
|
|
||
| Capture `@terminal` from the focused Agent Manager terminal, including embedded Run and Setup terminals, instead of using an unrelated active VS Code terminal. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { describe, expect, it } from "bun:test" | ||
| import { | ||
| readTerminalOutput, | ||
| registerTerminalOutput, | ||
| unregisterTerminalOutput, | ||
| } from "../../webview-ui/agent-manager/terminal/output" | ||
|
|
||
| describe("Agent Manager terminal output", () => { | ||
| it("reads and unregisters a terminal buffer", () => { | ||
| registerTerminalOutput("term-1", () => "embedded output") | ||
| expect(readTerminalOutput("term-1")).toBe("embedded output") | ||
| unregisterTerminalOutput("term-1") | ||
| expect(readTerminalOutput("term-1")).toBeUndefined() | ||
| }) | ||
|
|
||
| it("truncates large terminal buffers", () => { | ||
| registerTerminalOutput("term-2", () => Array.from({ length: 501 }, (_, index) => `line-${index}`).join("\n")) | ||
| const output = readTerminalOutput("term-2") | ||
| expect(output).toContain("[...1 lines omitted...]") | ||
| expect(output).toContain("line-0") | ||
| expect(output).toContain("line-500") | ||
| unregisterTerminalOutput("term-2") | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -142,6 +142,7 @@ import { | |||||
| resolveRunScriptRequest, | ||||||
| resolveVscodeTerminalRequest, | ||||||
| } from "./terminal" | ||||||
| import { readTerminalOutput } from "./terminal/output" | ||||||
| import { focusCurrentTab, renderTab, renderTerminalLayer, renderNewTabButton } from "./tab-rendering" | ||||||
| import { useTabScroll } from "./tab-scroll" | ||||||
| import { DiffPanel } from "./DiffPanel" | ||||||
|
|
@@ -372,6 +373,21 @@ const AgentManagerContent: Component = () => { | |||||
| const sel = selection() | ||||||
| return sel === null ? null : nsKey(sel) | ||||||
| }) | ||||||
| const resolveEmbeddedTerminal = async (context?: string) => { | ||||||
| const key = nsKey(context ?? LOCAL) | ||||||
| const side = terms.sidesForContext(key) | ||||||
| const tabs = terms.forSelection(key) | ||||||
| const focused = terms.focusedId() | ||||||
| const focusedTerm = side.find((term) => term.id === focused) ?? tabs.find((term) => term.id === focused) | ||||||
| const sideTerm = side.find((term) => term.id === terms.sideActiveFor(key)) | ||||||
| const tab = tabs.find((term) => term.id === terms.activeId()) | ||||||
| const id = focusedTerm?.id ?? sideTerm?.id | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [SUGGESTION]: Hidden side terminals outrank the visible tab terminal When nothing is focused,
Suggested change
Reply with |
||||||
| const target = id ?? tab?.id | ||||||
| if (!target) return undefined | ||||||
| const term = side.find((item) => item.id === target) ?? tabs.find((item) => item.id === target) | ||||||
| if (!term) return undefined | ||||||
| return readTerminalOutput(term.id) | ||||||
| } | ||||||
| const requestChatFocus = createChatFocus({ | ||||||
| term: () => terms.activeId(), | ||||||
| history, | ||||||
|
|
@@ -2572,10 +2588,12 @@ const AgentManagerContent: Component = () => { | |||||
| readonly={readOnly()} | ||||||
| continueInWorktree={selection() === LOCAL} | ||||||
| promptBoxId={`agent-manager:${selection() ?? "unassigned"}`} | ||||||
| terminalContext={() => selection() ?? undefined} | ||||||
| deferFocusToQuestion={hasQuestionOption} | ||||||
| pendingSessionID={selection() === LOCAL ? activePendingId() : undefined} | ||||||
| focusOnDraftChange={focusOnDraftChange} | ||||||
| onFocusChange={rememberPromptFocus} | ||||||
| resolveEmbeddedTerminal={resolveEmbeddedTerminal} | ||||||
| /> | ||||||
| <Show when={readOnly()}> | ||||||
| <div class="am-readonly-banner"> | ||||||
|
|
@@ -2765,7 +2783,6 @@ const AgentManagerContent: Component = () => { | |||||
| </div> | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
| export const AgentManagerApp: Component = () => { | ||||||
| return ( | ||||||
| <ProviderShell.Root> | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { truncateTerminalOutput } from "../../../src/services/terminal/truncate" | ||
|
|
||
| type Reader = () => string | ||
|
|
||
| const readers = new Map<string, Reader>() | ||
|
|
||
| export function registerTerminalOutput(id: string, read: Reader): void { | ||
| readers.set(id, read) | ||
| } | ||
|
|
||
| export function unregisterTerminalOutput(id: string): void { | ||
| readers.delete(id) | ||
| } | ||
|
|
||
| export function readTerminalOutput(id: string): string | undefined { | ||
| const content = readers.get(id)?.() | ||
| if (content === undefined) return undefined | ||
| return truncateTerminalOutput(content).content | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[WARNING]: Session-keyed reveal runs first and steals prompt focus
showExisting(sessionId, false)returns as soon as this session has any live mapped VS Code terminal, soagentManagerContextis never consulted. A focused worktree, local, or Run terminal is ignored andgetTerminalContentscopies the session terminal instead.preserveFocus=falsealso callsTerminal.show(false), which moves keyboard focus into the terminal panel. The previous default (true) still selected the terminal forselectAll/copySelectionwithout leaving the Agent Manager prompt, and nothing restores focus after capture.Consider revealing with
preserveFocus=true, and only after the focused or context-keyed terminal, so@terminalmatches what the user is looking at.Reply with
@kilocode-bot fix itto have Kilo Code address this issue.