Merge pull request #13420 from Kilo-Org/fix/cli-startup-review

fix(cli): address startup review feedback
This commit is contained in:
Marius
2026-08-25 16:40:45 +02:00
committed by GitHub
4 changed files with 39 additions and 8 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@kilocode/cli": patch
---
Fix CLI help disposal and shell completion after startup optimization.
@@ -19,6 +19,14 @@ export function hasLazyCommandSelection() {
return selected
}
export function resetLazyCommandSelection() {
selected = false
}
export function markLazyCommandSelection() {
selected = true
}
export function lazy<T = {}, U = {}>(input: {
command: string | readonly string[]
aliases?: string | readonly string[]
@@ -29,9 +37,11 @@ export function lazy<T = {}, U = {}>(input: {
const load = () => (state.task ??= input.load())
if (completion) {
tasks.push(
load().then((command) => {
state.command = command
}),
load()
.then((command) => {
state.command = command
})
.catch(() => undefined),
)
}
return {
@@ -39,7 +49,7 @@ export function lazy<T = {}, U = {}>(input: {
aliases: input.aliases,
describe: input.describe,
builder: ((args: Argv<T>) => {
selected = true
markLazyCommandSelection()
if (state.command) return build(state.command, args)
return load().then((command) => build(command, args))
}) as never,
@@ -1,13 +1,15 @@
import { cmd } from "../cli/cmd/cmd"
import { generateHelp } from "./help"
import type { Argv } from "yargs"
import { markLazyCommandSelection } from "@/kilocode/cli/lazy-commands"
export function createHelpCommand(root?: () => Argv) {
return cmd({
command: "help [command]",
describe: "show full CLI reference",
builder: (yargs) =>
yargs
builder: (yargs) => {
markLazyCommandSelection()
return yargs
.positional("command", {
describe: "command to show help for",
type: "string",
@@ -22,7 +24,8 @@ export function createHelpCommand(root?: () => Argv) {
type: "string",
choices: ["md", "text"] as const,
default: "md" as const,
}),
})
},
async handler(args) {
if (!args.command && !args.all) {
if (root) {
@@ -1,7 +1,13 @@
import { describe, expect, test } from "bun:test"
import { afterEach, beforeEach, describe, expect, test } from "bun:test"
import { KiloCli } from "../../../src/kilocode/cli/setup"
import { createHelpCommand } from "../../../src/kilocode/help-command"
import { resetLazyCommandSelection } from "../../../src/kilocode/cli/lazy-commands"
import yargs from "yargs"
describe("CLI bootstrap runtime selection", () => {
beforeEach(resetLazyCommandSelection)
afterEach(resetLazyCommandSelection)
test("uses the narrow runtime for worker-backed TUI launches", () => {
expect(KiloCli.workerTui({ _: [] })).toBe(true)
expect(KiloCli.workerTui({ _: ["./project"] })).toBe(true)
@@ -11,4 +17,11 @@ describe("CLI bootstrap runtime selection", () => {
expect(KiloCli.workerTui({ _: [], mini: true })).toBe(false)
expect(KiloCli.workerTui({ _: [], worktree: "feature" })).toBe(false)
})
test("keeps full bootstrap when the eager help command is selected", () => {
const command = createHelpCommand()
if (typeof command.builder !== "function") throw new Error("help builder is not a function")
command.builder(yargs([]))
expect(KiloCli.workerTui({ _: [] })).toBe(false)
})
})