feat(chat): add --workdir/-C flag to set working directory at session start#3732
Open
sandikodev wants to merge 3 commits intoaws:mainfrom
Open
feat(chat): add --workdir/-C flag to set working directory at session start#3732sandikodev wants to merge 3 commits intoaws:mainfrom
sandikodev wants to merge 3 commits intoaws:mainfrom
Conversation
…le freshness check The current str_replace implementation uses exact byte matching only. When the model's old_str has minor differences from the file (indentation drift, whitespace, or small context edits), the match fails and the model either retries wastefully or falls back to destructive shell commands. Implement str_replace_fuzzy() with a 3-strategy fallback chain inspired by opencode and cline's diff-apply approaches: 1. Exact match — unchanged behaviour for the common case 2. Line-trimmed match — compares lines after trim(), then replaces using byte offsets (prefix-sum table) into the original content. Handles indentation drift (tab vs spaces, different indent levels). 3. Block-anchor match — uses first+last line as anchors, scores middle lines with Levenshtein similarity, picks the best candidate above a 0.6 threshold. Handles minor edits in surrounding context lines. Also adds file freshness checking: - fs_read now records the file mtime into FileLineTracker.last_read_mtime whenever it reads a file - fs_write str_replace checks the current mtime against the recorded value before writing; if the file was modified externally it returns a clear error asking the model to re-read before retrying Also: - validate() rejects empty old_str before reaching fuzzy matching - tool_index.json description updated to reflect fuzzy tolerance and reinforce read-before-write / no-sed-fallback guidance Key correctness properties: - Strategies 2 and 3 return byte ranges — replacement is always at the correct position even if matched text appears elsewhere in the file - block_anchor_match skips first==last anchors (false positive guard) - similarity_score respects actual content window bounds - levenshtein uses O(n) rolling-row space, char count for denominator - build_line_offsets prefix-sum gives O(1) offset lookup - strip_empty_boundary_lines handles both leading and trailing empty lines 11 tests cover all strategies, edge cases, and error messages.
… start Allows users to start a chat session in a specific directory without needing to cd first or restart the session: kiro-cli chat --workdir /path/to/project kiro-cli chat -C /path/to/project The working directory is set before any other initialization, so LSP discovery, .kiro config loading, and context detection all use the specified path.
…session Allows changing the working directory without restarting the session: /changedir /path/to/project /cd ~/project/wezterm /cd (goes to $HOME) After changing directory, the user is prompted to run /code init to reinitialize code intelligence for the new directory.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When working with multiple projects, users must
cdto the correct directory before startingkiro-cli chatto get the right session context, LSP discovery, and.kiroconfig. There is no way to specify a working directory inline.Solution
Add
--workdir/-Cflag tokiro-cli chat:Implementation
set_current_diris called at the very start ofChatArgs::execute, before any other initialization — so LSP discovery,.kiroconfig loading, session lookup by path, and--resumeall use the specified directory correctly.The change is minimal: one new field in
ChatArgsand four lines inexecute.Closes: (no issue yet — happy to create one if preferred)