Repository: aws/amazon-q-developer-cli
Pull request #1649: feat: integrate git-aware file selection in fuzzy finder
Author: login: h16rkim
Created: 2025-05-04T08:58:39Z | Merged: 2025-05-07T02:12:28Z

## Description of changes:

Hello. I actively use the amazon-q-developer CLI and find the Agent Coding features very helpful. While trying out the recently added `/context add` fuzzy finder(skim) feature, I noticed one issue that could be improved, which led me to open this Pull Request.

When opening the fuzzy finder, I found that files and directories listed in `.gitignore` — such as `node_modules`, `dist`, and `build` — were still appearing in the file list. I believe that only valid files authored by developers should appear in the fuzzy finder’s list. Since files under `dist`, `node_modules`, `build` are typically generated or compiled artifacts rather than developer-authored source code, it would be helpful to exclude them from the fuzzy finder. Especially in the case of TypeScript, **the transpiled JavaScript file names are very similar to the original TypeScript file names**. As a result, **if developers don’t carefully check the paths in the fuzzy finder, they may accidentally select the wrong file** when using `/context add`.

## Changed feature:

This Pull Request modifies the code so that files specified in `.gitignore` are ignored by the fuzzy finder(skim), as shown in the image below. Here are two images showing the results of searching for `build/` using the fuzzy finder in the amazon-q-developer-cli project.

**[AS-IS]**

<img src="https://github.com/user-attachments/assets/99ec9d62-1741-4d61-a49e-fc647bea2279" width="500" />

**[TO-BE]**

<img src="https://github.com/user-attachments/assets/e10e3cc0-150f-49fb-919d-19f46f859ba5" width="500" />



If my code needs any adjustments, please feel free to modify it.

## Linked Issue
https://github.com/aws/amazon-q-developer-cli/issues/1650




Diff:
diff --git a/crates/chat-cli/src/cli/chat/skim_integration.rs b/crates/chat-cli/src/cli/chat/skim_integration.rs
index 026576be14..87a7826b0f 100644
--- a/crates/chat-cli/src/cli/chat/skim_integration.rs
+++ b/crates/chat-cli/src/cli/chat/skim_integration.rs
@@ -135,8 +135,18 @@ pub fn select_files_with_skim() -> Result<Option<Vec<String>>> {
     let options = create_skim_options("Select files: ", true)?;
 
     // Create a command that will be executed by skim
-    // This avoids loading all files into memory at once
-    let find_cmd = "find . -type f -not -path '*/\\.*'";
+    // This command checks if git is installed and if we're in a git repo
+    // Otherwise falls back to find command
+    let find_cmd = r#"
+    # Check if git is available and we're in a git repo
+    if command -v git >/dev/null 2>&1 && git rev-parse --is-inside-work-tree &>/dev/null; then
+        # Git repository - respect .gitignore
+        { git ls-files; git ls-files --others --exclude-standard; } | sort | uniq
+    else
+        # Not a git repository or git not installed - use find command
+        find . -type f -not -path '*/\.*'
+    fi
+    "#;
 
     // Create a command collector that will execute the find command
     let item_reader = SkimItemReader::default();
diff --git a/crates/fig_os_shim/src/fs.rs b/crates/fig_os_shim/src/fs.rs
index 041a838661..95d3783b15 100644
--- a/crates/fig_os_shim/src/fs.rs
+++ b/crates/fig_os_shim/src/fs.rs
@@ -3,8 +3,14 @@ use std::fs::Permissions;
 use std::io;
 #[cfg(unix)]
 use std::os::unix::ffi::OsStrExt;
-use std::path::{Path, PathBuf};
-use std::sync::{Arc, Mutex};
+use std::path::{
+    Path,
+    PathBuf,
+};
+use std::sync::{
+    Arc,
+    Mutex,
+};
 
 use tempfile::TempDir;
 use tokio::fs;
@@ -17,7 +23,10 @@ pub struct Fs(inner::Inner);
 mod inner {
     use std::collections::HashMap;
     use std::path::PathBuf;
-    use std::sync::{Arc, Mutex};
+    use std::sync::{
+        Arc,
+        Mutex,
+    };
 
     use tempfile::TempDir;
 
@@ -365,8 +374,9 @@ impl Fs {
     /// On Windows, it automatically detects whether the target is a file or directory
     /// and uses the appropriate system call.
     ///
-    /// This is a proxy to [`std::os::windows::fs::symlink_file`] or [`std::os::windows::fs::symlink_dir`] on Windows,
-    /// and [`std::os::unix::fs::symlink`] on Unix.
+    /// This is a proxy to [`std::os::windows::fs::symlink_file`] or
+    /// [`std::os::windows::fs::symlink_dir`] on Windows, and [`std::os::unix::fs::symlink`] on
+    /// Unix.
     #[cfg(windows)]
     pub fn symlink_sync(&self, original: impl AsRef<Path>, link: impl AsRef<Path>) -> io::Result<()> {
         use inner::Inner;
diff --git a/crates/fig_os_shim/src/process_info/pid.rs b/crates/fig_os_shim/src/process_info/pid.rs
index c7f1e7f831..50e9833bda 100644
--- a/crates/fig_os_shim/src/process_info/pid.rs
+++ b/crates/fig_os_shim/src/process_info/pid.rs
@@ -1,16 +1,34 @@
 use std::path::PathBuf;
 use std::sync::Weak;
-use std::{fmt, str};
+use std::{
+    fmt,
+    str,
+};
 
 use cfg_if::cfg_if;
 
 // Platform-specific implementations
 #[cfg(target_os = "linux")]
-use super::linux::{cmdline, current, exe, parent};
+use super::linux::{
+    cmdline,
+    current,
+    exe,
+    parent,
+};
 #[cfg(target_os = "macos")]
-use super::macos::{cmdline, current, exe, parent};
+use super::macos::{
+    cmdline,
+    current,
+    exe,
+    parent,
+};
 #[cfg(windows)]
-use super::windows::{cmdline, current, exe, parent};
+use super::windows::{
+    cmdline,
+    current,
+    exe,
+    parent,
+};
 use crate::Context;
 
 #[derive(Default, Debug, Clone)]
diff --git a/crates/fig_os_shim/src/process_info/windows.rs b/crates/fig_os_shim/src/process_info/windows.rs
index a662447914..cfc9a39b33 100644
--- a/crates/fig_os_shim/src/process_info/windows.rs
+++ b/crates/fig_os_shim/src/process_info/windows.rs
@@ -1,9 +1,15 @@
 use std::path::PathBuf;
 use std::sync::Weak;
 
-use sysinfo::{ProcessesToUpdate, System};
-
-use super::pid::{Pid, RawPid};
+use sysinfo::{
+    ProcessesToUpdate,
+    System,
+};
+
+use super::pid::{
+    Pid,
+    RawPid,
+};
 use crate::Context;
 
 pub fn current(ctx: Weak<Context>) -> Pid {


Reviews:
user: login: brandonskiser
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-05-07T00:45:20Z
user: login: h16rkim
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-07T02:11:35Z
user: login: h16rkim
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-07T02:11:48Z
user: login: h16rkim
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-07T02:11:55Z

Review comments:
diff_hunk: @@ -3,8 +3,14 @@ use std::fs::Permissions;
 use std::io;
 #[cfg(unix)]
 use std::os::unix::ffi::OsStrExt;
-use std::path::{Path, PathBuf};
-use std::sync::{Arc, Mutex};
+use std::path::{
path: crates/fig_os_shim/src/fs.rs
user: login: h16rkim
body: The changes in this diff were produced by executing `cargo +nightly fmt`.
It includes no functional modifications.
created_at: 2025-05-07T02:11:35Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,16 +1,34 @@
 use std::path::PathBuf;
 use std::sync::Weak;
-use std::{fmt, str};
+use std::{
path: crates/fig_os_shim/src/process_info/pid.rs
user: login: h16rkim
body: The changes in this diff were produced by executing `cargo +nightly fmt`.
It includes no functional modifications.
created_at: 2025-05-07T02:11:48Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,9 +1,15 @@
 use std::path::PathBuf;
 use std::sync::Weak;
 
-use sysinfo::{ProcessesToUpdate, System};
-
-use super::pid::{Pid, RawPid};
+use sysinfo::{
path: crates/fig_os_shim/src/process_info/windows.rs
user: login: h16rkim
body: The changes in this diff were produced by executing `cargo +nightly fmt`.
It includes no functional modifications.
created_at: 2025-05-07T02:11:55Z
author_association: CONTRIBUTOR

PR comments:
user: login: brandonskiser
created_at: 2025-05-07T00:47:22Z
body: Thank you for the contribution! There seems to be a merge conflict though, this file was moved to `crates/chat-cli/src/cli/chat/skim_integration.rs` since a recent refactor, can you fix and push again?
author_association: CONTRIBUTOR
user: login: h16rkim
created_at: 2025-05-07T01:41:15Z
body: @brandonskiser 

Thanks. I’ve resolved the conflict.
Is it okay if I merge this PR myself, or would you prefer to merge it directly as the contributor?
author_association: CONTRIBUTOR
user: login: codecov-commenter
created_at: 2025-05-07T02:06:08Z
body: ## [Codecov](https://app.codecov.io/gh/aws/amazon-q-developer-cli/pull/1649?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 16.75%. Comparing base [(`aa58632`)](https://app.codecov.io/gh/aws/amazon-q-developer-cli/commit/aa586324ba15030e082f6c7ecfdd8cd2e2d41d56?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws) to head [(`f8978b3`)](https://app.codecov.io/gh/aws/amazon-q-developer-cli/commit/f8978b3459e2e46caef57a0af1eed155f52eb9e2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main    #1649   +/-   ##
=======================================
  Coverage   16.75%   16.75%           
=======================================
  Files         213      213           
  Lines       20704    20704           
  Branches      871      871           
=======================================
  Hits         3468     3468           
  Misses      17236    17236           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/aws/amazon-q-developer-cli/pull/1649?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws).

<details><summary> :rocket: New features to boost your workflow: </summary>

- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
author_association: NONE
user: login: brandonskiser
created_at: 2025-05-07T02:12:44Z
body: Thank you for the contribution!
author_association: CONTRIBUTOR