-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(agent-manager): run project scripts in the selected terminal #12680
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
Merged
marius-kilocode
merged 6 commits into
main
from
move-run-capability-to-agent-manager-terminal
Jul 30, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
49223b3
feat(agent-manager): run project scripts in the embedded side terminal
marius-kilocode 22d1a50
feat(agent-manager): add run terminal destination setting
marius-kilocode 4016919
fix(agent-manager): route run through terminal dropdown
marius-kilocode 3a829f5
chore: remove implementation plan
marius-kilocode a6f6655
fix(agent-manager): address run terminal review findings
marius-kilocode a282a14
fix(agent-manager): keep provider below size cap
marius-kilocode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "kilo-code": minor | ||
| --- | ||
|
|
||
| Run Agent Manager project scripts in the terminal selected by the existing toolbar dropdown. Agent Manager panel uses the named side terminal, while VS Code terminal retains the integrated task flow. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| import { spawn } from "child_process" | ||
| import { setTimeout as sleep } from "node:timers/promises" | ||
| import type { Proc } from "../../pty/pty" | ||
| import { Log } from "../../util/log" | ||
|
|
||
| const log = Log.create({ service: "pty.termination" }) | ||
| const GRACE_MS = 200 | ||
| const SPAWN_TIMEOUT_MS = 5_000 | ||
|
|
||
| export type Process = Pick<Proc, "pid" | "onExit" | "kill"> | ||
|
|
||
| export type Runtime = { | ||
| readonly platform: NodeJS.Platform | ||
| readonly taskkill: ( | ||
| file: string, | ||
| args: string[], | ||
| opts: { stdio: "ignore"; windowsHide: true; timeout: number }, | ||
| ) => Promise<boolean> | ||
| readonly tree: () => Promise<Array<{ pid: number; parent: number }>> | ||
| readonly alive: (pid: number) => boolean | ||
| readonly signal: (pid: number, signal: "SIGTERM" | "SIGKILL") => void | ||
| readonly sleep: (ms: number) => Promise<void> | ||
| } | ||
|
|
||
| const runtime: Runtime = { | ||
| platform: process.platform, | ||
| taskkill, | ||
| tree, | ||
| alive: (pid) => { | ||
| try { | ||
| process.kill(pid, 0) | ||
| return true | ||
| } catch { | ||
| return false | ||
| } | ||
| }, | ||
| signal: (pid, signal) => process.kill(pid, signal), | ||
| sleep, | ||
| } | ||
|
|
||
| function direct(proc: Process, signal?: "SIGTERM" | "SIGKILL") { | ||
| try { | ||
| proc.kill(signal) | ||
| } catch (err) { | ||
| log.warn("failed to kill PTY directly", { err, pid: proc.pid, signal }) | ||
| } | ||
| } | ||
|
|
||
| function descendants(root: number, rows: Array<{ pid: number; parent: number }>) { | ||
| const children = new Map<number, number[]>() | ||
| for (const row of rows) { | ||
| const list = children.get(row.parent) ?? [] | ||
| list.push(row.pid) | ||
| children.set(row.parent, list) | ||
| } | ||
| const seen = new Set<number>() | ||
| const collect = (pid: number): number[] => { | ||
| const result: number[] = [] | ||
| for (const child of children.get(pid) ?? []) { | ||
| if (seen.has(child)) continue | ||
| seen.add(child) | ||
| result.push(...collect(child), child) | ||
| } | ||
| return result | ||
| } | ||
| return collect(root) | ||
| } | ||
|
|
||
| async function family(root: number, input: Runtime) { | ||
| const rows = await input.tree().catch((err) => { | ||
| log.debug("failed to inspect PTY process tree", { err, pid: root }) | ||
| return [] | ||
| }) | ||
| return [...descendants(root, rows), root] | ||
| } | ||
|
|
||
| function signal(proc: Process, pids: number[], value: "SIGTERM" | "SIGKILL", input: Runtime) { | ||
| for (const pid of pids) { | ||
| let sent = false | ||
| for (const target of [-pid, pid]) { | ||
| try { | ||
| input.signal(target, value) | ||
| sent = true | ||
| } catch (err) { | ||
| log.debug("failed to signal PTY process", { err, pid: target, signal: value }) | ||
| } | ||
| } | ||
| if (pid === proc.pid && !sent) direct(proc, value) | ||
| } | ||
| } | ||
|
|
||
| async function tree(file: string = "ps", args: string[] = ["-axo", "pid=,ppid="]) { | ||
| return await new Promise<Array<{ pid: number; parent: number }>>((resolve) => { | ||
| try { | ||
| const child = spawn(file, args, { | ||
| stdio: ["ignore", "pipe", "ignore"], | ||
| windowsHide: true, | ||
| timeout: SPAWN_TIMEOUT_MS, | ||
| killSignal: "SIGKILL", | ||
| }) | ||
| const chunks: Buffer[] = [] | ||
| child.stdout?.on("data", (chunk: Buffer) => chunks.push(chunk)) | ||
| child.once("error", () => resolve([])) | ||
| child.once("close", (code) => { | ||
| if (code !== 0) return resolve([]) | ||
| const rows = Buffer.concat(chunks) | ||
| .toString("utf8") | ||
| .trim() | ||
| .split("\n") | ||
| .filter(Boolean) | ||
| .map((line) => line.trim().split(/\s+/).map(Number)) | ||
| .filter(([pid, parent]) => Number.isSafeInteger(pid) && Number.isSafeInteger(parent)) | ||
| .map(([pid, parent]) => ({ pid: pid!, parent: parent! })) | ||
| resolve(rows) | ||
| }) | ||
| } catch { | ||
| resolve([]) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| async function taskkill( | ||
| file: string, | ||
| args: string[], | ||
| opts: { stdio: "ignore"; windowsHide: true; timeout: number }, | ||
| ) { | ||
| return await new Promise<boolean>((resolve) => { | ||
| try { | ||
| const child = spawn(file, args, opts) | ||
| child.once("exit", (code) => resolve(code === 0)) | ||
| child.once("error", (err) => { | ||
| log.warn("taskkill failed", { err }) | ||
| resolve(false) | ||
| }) | ||
| } catch (err) { | ||
| log.warn("failed to start taskkill", { err }) | ||
| resolve(false) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| export async function terminate(proc: Process, input: Runtime = runtime): Promise<void> { | ||
| const state = { exited: false } | ||
| const listener = proc.onExit(() => { | ||
| state.exited = true | ||
| }) | ||
| try { | ||
| if (!proc.pid) { | ||
| direct(proc) | ||
| if (!state.exited) await input.sleep(GRACE_MS) | ||
| return | ||
| } | ||
|
|
||
| if (input.platform === "win32") { | ||
| const killed = await input.taskkill("taskkill", ["/pid", String(proc.pid), "/f", "/t"], { | ||
| stdio: "ignore", | ||
| windowsHide: true, | ||
| timeout: SPAWN_TIMEOUT_MS, | ||
| }) | ||
| if (!killed && !state.exited) direct(proc) | ||
| if (!state.exited) await input.sleep(GRACE_MS) | ||
| return | ||
| } | ||
|
|
||
| const initial = await family(proc.pid, input) | ||
| signal(proc, initial, "SIGTERM", input) | ||
| await input.sleep(GRACE_MS) | ||
| const remaining = new Set(initial.filter(input.alive)) | ||
| if (input.alive(proc.pid)) for (const pid of await family(proc.pid, input)) remaining.add(pid) | ||
| if (remaining.size > 0) { | ||
| signal(proc, [...remaining], "SIGKILL", input) | ||
| await input.sleep(GRACE_MS) | ||
| } | ||
| } finally { | ||
| listener.dispose() | ||
| } | ||
| } | ||
|
|
||
| export * as KiloPtyTermination from "./termination" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.