Skip to content

Comments

feat(cli): add optional cwd argument to serve#601

Open
Olusammytee wants to merge 2 commits intoKilo-Org:devfrom
Olusammytee:feat/128-serve-cwd
Open

feat(cli): add optional cwd argument to serve#601
Olusammytee wants to merge 2 commits intoKilo-Org:devfrom
Olusammytee:feat/128-serve-cwd

Conversation

@Olusammytee
Copy link
Contributor

Summary

  • add an optional positional project path to kilo serve
  • resolve relative paths from current shell working directory
  • change into the target directory before booting the server, with clear error handling when the path is invalid

Fixes #128

Copilot AI review requested due to automatic review settings February 22, 2026 18:31
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

}),
describe: "starts a headless kilo server", // kilocode_change
handler: async (args) => {
const baseCwd = process.env.PWD ?? process.cwd()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[WARNING]: Missing kilocode_change markers on Kilo-specific code in shared file

This file is shared with upstream opencode. Per AGENTS.md, Kilo-specific changes in shared code should be marked with kilocode_change comments. Lines 6, 9, and 17–25 are new Kilo-specific additions but lack markers. Other lines in this file (5, 13, 15, 32–47) already have them.

Consider wrapping this block:

// kilocode_change start - optional project path support
const baseCwd = process.env.PWD ?? process.cwd()
const cwd = args.project ? path.resolve(baseCwd, args.project) : process.cwd()
try {
  process.chdir(cwd)
} catch {
  console.error(`Failed to change directory to ${cwd}`)
  process.exitCode = 1
  return
}
// kilocode_change end

Also add // kilocode_change to the import path on line 6 and the command change on line 9.

const cwd = args.project ? path.resolve(baseCwd, args.project) : process.cwd()
try {
process.chdir(cwd)
} catch {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[SUGGESTION]: Capture the error in the catch clause for better diagnostics

The catch clause discards the error. Including the actual error reason (e.g., ENOENT vs EACCES) in the message would help users debug path issues. The existing pattern in thread.ts:107 captures (e) as well.

Suggested change
} catch {
} catch (e) {

@kiloconnect
Copy link
Contributor

kiloconnect bot commented Feb 22, 2026

Code Review Summary

Status: No New Issues Found | Recommendation: Merge

Overview

This PR adds an optional [project] positional argument to the serve command, allowing users to specify a directory for the Kilo server to run in. The implementation is clean and focused:

  • Uses path.resolve() to handle relative paths correctly
  • process.chdir() changes the working directory before server boot
  • Error handling properly captures and reports chdir failures with informative messages
  • Sets process.exitCode = 1 and returns early on failure (non-throwing pattern)

The 4 existing inline comments from prior reviews have been noted. The current code already addresses the error handling concerns raised — the catch block now properly captures the error, checks instanceof Error, and logs a descriptive message.

Files Reviewed (1 file)
  • packages/opencode/src/cli/cmd/serve.ts - 0 new issues (4 existing comments from prior reviews)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds an optional positional project path argument to the kilo serve command, enabling users to start the server in a specific directory without needing to manually change directories first. This is particularly useful for debugging scenarios where different project directories need to be tested.

Changes:

  • Added optional [project] positional argument to the serve command
  • Implemented path resolution that respects the shell's working directory using process.env.PWD
  • Added error handling for invalid directory paths with graceful exit

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

try {
process.chdir(cwd)
} catch {
console.error(`Failed to change directory to ${cwd}`)
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling in the serve command doesn't match the pattern used elsewhere in the codebase. In the TUI thread command (tui/thread.ts:108), UI.error is used for error messages which provides consistent formatting with the TEXT_DANGER_BOLD style. The serve command should use UI.error instead of console.error for consistency.

Copilot uses AI. Check for mistakes.
Comment on lines 21 to 22
} catch {
console.error(`Failed to change directory to ${cwd}`)
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch block silently ignores the error object. Consider capturing and logging the error for better debugging, similar to how other commands in the codebase handle errors. For example, in tui/thread.ts:107, the error is captured as 'e' even though it's not used in the error message. This helps with debugging if the error needs to be inspected later.

Suggested change
} catch {
console.error(`Failed to change directory to ${cwd}`)
} catch (e) {
console.error(`Failed to change directory to ${cwd}`, e)

Copilot uses AI. Check for mistakes.
@Olusammytee
Copy link
Contributor Author

Pushed follow-up commit 73347af to harden serve [project] path handling on Windows: we now resolve from process.cwd() and only call process.chdir when project is provided, with a clearer error message on failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant