Skip to content

feat: shell hook for auto-context loading - #72

Merged
ajianaz merged 1 commit into
developfrom
feat/shell-hook
May 30, 2026
Merged

ajianaz merged 1 commit into
developfrom
feat/shell-hook

Conversation

@ajianaz

@ajianaz ajianaz commented May 30, 2026 •

Copy link
Copy Markdown
Collaborator

Changes

  • Add scripts/shell/uteke-hook.bash — Bash PROMPT_COMMAND hook
  • Add scripts/shell/uteke-hook.zsh — Zsh chpwd_functions hook
  • Add scripts/shell/uteke-hook.fish — Fish --on-variable PWD hook
  • Add uteke hook <bash|zsh|fish> CLI subcommand
  • Hooks detect .uteke/uteke.db in cwd, set/unset UTEKE_PROJECT_STORE

Usage

# Bash — add to ~/.bashrc
eval "$(uteke hook bash)"

# Zsh — add to ~/.zshrc
eval "$(uteke hook zsh)"

# Fish — add to ~/.config/fish/config.fish
uteke hook fish | source

Verification

  • cargo check ✓
  • cargo clippy ✓
  • cargo test — 18/18 ✓
  • cargo fmt ✓

Closes #47

Summary by CodeRabbit

  • New Features
    • Added shell hook support via uteke hook <shell> command for bash, zsh, and fish.
    • Hooks automatically manage environment configuration based on project directory detection.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 30, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@ajianaz, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 47 minutes and 10 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: da9ac884-475a-411a-aa7e-b0511021f218

📥 Commits

Reviewing files that changed from the base of the PR and between 29d8f8e and 3a5ecf3.

📒 Files selected for processing (4)
  • crates/uteke-cli/src/main.rs
  • scripts/shell/uteke-hook.bash
  • scripts/shell/uteke-hook.fish
  • scripts/shell/uteke-hook.zsh
📝 Walkthrough

Walkthrough

Added a new uteke hook <shell> CLI subcommand that dynamically outputs shell-specific hook scripts. Implemented hook scripts for Bash, Zsh, and Fish that detect directory changes and automatically manage the UTEKE_PROJECT_STORE environment variable based on the presence of .uteke/uteke.db in the current directory.

Changes

Shell Integration Hook

Layer / File(s) Summary
Hook CLI command and dispatcher
crates/uteke-cli/src/main.rs
New Hook { shell: String } variant added to the Commands enum. The run_command dispatcher pattern-matches on the requested shell (bash, zsh, fish) and prints the corresponding embedded hook script to stdout; unsupported shells return an error.
Shell-specific hook implementations
scripts/shell/uteke-hook.bash, scripts/shell/uteke-hook.zsh, scripts/shell/uteke-hook.fish
Bash hook uses PROMPT_COMMAND and _uteke_prev_dir tracking; Zsh hook registers uteke_chpwd in chpwd_functions; Fish hook responds to PWD variable changes. All three detect directory changes and set UTEKE_PROJECT_STORE=$PWD/.uteke when .uteke/uteke.db exists, otherwise unset the variable.

🎯 2 (Simple) | ⏱️ ~12 minutes

🐰 A rabbit hops from bash to zsh with glee,
Fish swimming in the shell hook sea,
Directories change, the context knows—
UTEKE_PROJECT_STORE blooms and goes! 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR partially addresses issue #47: it implements shell hooks (bash, zsh, fish) and a CLI subcommand to emit them, and sets UTEKE_PROJECT_STORE on directory changes. However, it does not implement automatic context recall or optional context summary display as specified in the issue. Implement automatic recall of project memories via 'uteke recall' and optionally display context summary. Add support for .uteke-context configuration file to drive recall behavior per issue #47 requirements.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: shell hook for auto-context loading' clearly and concisely summarizes the main change: adding shell hooks for automatic context loading when changing directories.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing shell hooks for auto-context loading as specified in issue #47. The additions to CLI and shell scripts are in scope and support the primary objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/shell-hook

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (6)
scripts/shell/uteke-hook.zsh (2)

1-10: ⚠️ Potential issue | 🟠 Major

Standalone script file is not currently used.

This file is duplicated inline in crates/uteke-cli/src/main.rs (lines 881-893). See the main.rs review comment about using include_str!.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/shell/uteke-hook.zsh` around lines 1 - 10, This standalone Zsh hook
is duplicated inline in main.rs; remove the duplicate by consolidating the
source to a single canonical string and use include_str! in
crates/uteke-cli/src/main.rs to embed it. Specifically, keep the utek-hook.zsh
file as the single source containing the chpwd_functions+=(uteke_chpwd) and the
utek_chpwd() function that sets/unsets UTEKE_PROJECT_STORE, then update main.rs
to load that content with include_str! and stop duplicating the utek_chpwd
snippet inline.

5-5: ⚠️ Potential issue | 🟠 Major

Missing parent directory search.

Same issue as flagged in main.rs and bash script: should search parent directories.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/shell/uteke-hook.zsh` at line 5, The check if [[ -f ".uteke/uteke.db"
]]; then should be replaced with a parent-directory search: implement a loop in
uweke-hook.zsh that walks up from the current directory (e.g., while [ "$dir" !=
"/" ]) checking each ancestor for ".uteke/uteke.db", set a variable like
UTEKE_DB_PATH when found and break, and then use that variable (or a boolean)
instead of the direct -f check; update any subsequent code that assumes
".uteke/uteke.db" to use the discovered path or abort if not found.
scripts/shell/uteke-hook.fish (2)

1-9: ⚠️ Potential issue | 🟠 Major

Standalone script file is not currently used.

This file is duplicated inline in crates/uteke-cli/src/main.rs (lines 894-905). See the main.rs review comment about using include_str!.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/shell/uteke-hook.fish` around lines 1 - 9, The Fish hook script is
duplicated inline in crates/uteke-cli/src/main.rs (the __uteke_directory_change
function block); remove the inline duplicate and load the canonical script file
instead by replacing the hard-coded string in main.rs with an include_str!()
that points to this scripts/shell/uteke-hook.fish file (e.g.
include_str!(concat!(env!("CARGO_MANIFEST_DIR"),
"/scripts/shell/uteke-hook.fish")) or an appropriate relative path), so the
__uteke_directory_change hook is sourced from the single file rather than
duplicated in code.

4-4: ⚠️ Potential issue | 🟠 Major

Missing parent directory search.

Same issue as flagged in main.rs, bash, and zsh scripts: should search parent directories.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/shell/uteke-hook.fish` at line 4, The hook currently checks only the
current directory with the line "if test -f .uteke/uteke.db" and must instead
search parent directories for ".uteke/uteke.db"; update the fish script
(uteke-hook.fish) to walk up the directory tree (e.g., loop while not root)
checking each ancestor for ".uteke/uteke.db", stop when found, set the resolved
path into the variable used by the hook, and only proceed if that file is found;
ensure you replace the direct "if test -f .uteke/uteke.db" check with this
ancestor-search logic so behavior matches main.rs, bash, and zsh
implementations.
scripts/shell/uteke-hook.bash (2)

7-7: ⚠️ Potential issue | 🟠 Major

Missing parent directory search.

Same issue as flagged in main.rs: the hook should search parent directories to detect when you're in a subdirectory of a uteke project.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/shell/uteke-hook.bash` at line 7, The hook currently only checks for
".uteke/uteke.db" in the current directory; update uteke-hook.bash to search
parent directories upward until root to detect being inside a uteke project.
Replace the single-file test with a loop that walks up parents (e.g., using a
variable like dir="$PWD" and repeatedly testing [[ -f "$dir/.uteke/uteke.db" ]]
and setting dir="$(dirname "$dir")" until found or dir is "/" ), and ensure the
logic sets a flag or exits the loop when the file is found so the rest of the
hook behaves the same.

1-14: ⚠️ Potential issue | 🟠 Major

Standalone script file is not currently used.

This file is duplicated inline in crates/uteke-cli/src/main.rs (lines 864-880). If you adopt the include_str! approach suggested in the main.rs review, this file will become the canonical source. Until then, changes here won't affect the CLI output.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/shell/uteke-hook.bash` around lines 1 - 14, The shell hook logic in
the repository is duplicated: the standalone script defining _uteke_prev_dir,
the function uteke_prompt_hook, and the PROMPT_COMMAND assignment is also
embedded inline in main.rs; switch main.rs to load this canonical script via
include_str! instead of the duplicated hardcoded string, replacing the inline
copy with include_str!("...") (pointing to the canonical script) and using that
runtime string where the embedded hook is registered, so updates to
uteke_prompt_hook, _uteke_prev_dir, or PROMPT_COMMAND only need to be made in
this single script file.
🧹 Nitpick comments (2)
scripts/shell/uteke-hook.zsh (1)

3-3: 💤 Low value

Consider defining function before registering it.

While appending to chpwd_functions before defining uteke_chpwd works in Zsh (due to lazy evaluation), the conventional order is to define the function first for clarity.

♻️ Suggested reordering
 # Uteke shell hook for Zsh
 # Add to ~/.zshrc: eval "$(uteke hook zsh)"
-chpwd_functions+=(uteke_chpwd)
 uteke_chpwd() {
     if [[ -f ".uteke/uteke.db" ]]; then
         export UTEKE_PROJECT_STORE="$PWD/.uteke"
     else
         unset UTEKE_PROJECT_STORE
     fi
 }
+chpwd_functions+=(uteke_chpwd)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/shell/uteke-hook.zsh` at line 3, Move the utekе_chpwd function
definition so it appears before the line that registers it in chpwd_functions;
specifically, define the function named utekе_chpwd first, then append it to
chpwd_functions (chpwd_functions+=(uteke_chpwd)) to improve clarity and follow
conventional ordering.
crates/uteke-cli/src/main.rs (1)

293-297: ⚡ Quick win

Consider using an enum for shell type validation at parse time.

The shell field accepts any String, with validation deferred to runtime (line 863+). Using a Clap-compatible enum would catch invalid shell names earlier and provide better help text.

♻️ Proposed refactor using enum
+#[derive(Clone, Copy, clap::ValueEnum)]
+enum SupportedShell {
+    Bash,
+    Zsh,
+    Fish,
+}
+
 #[derive(Subcommand)]
 enum Commands {
     // ... other variants ...
     /// Output shell hook script for auto-context loading
     Hook {
         /// Shell type: bash, zsh, fish
-        shell: String,
+        shell: SupportedShell,
     },

Then update the match arm:

-        Commands::Hook { shell } => {
-            match shell.as_str() {
-                "bash" => print!(/* ... */),
-                "zsh" => print!(/* ... */),
-                "fish" => print!(/* ... */),
-                other => {
-                    return Err(format!(
-                        "Unknown shell: {other}. Supported shells: bash, zsh, fish"
-                    ))
-                }
-            }
+        Commands::Hook { shell } => {
+            match shell {
+                SupportedShell::Bash => print!(/* ... */),
+                SupportedShell::Zsh => print!(/* ... */),
+                SupportedShell::Fish => print!(/* ... */),
+            }
             Ok(())
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/uteke-cli/src/main.rs` around lines 293 - 297, Replace the Hook.shell
String with a Clap-backed enum (e.g., enum Shell: ValueEnum/ArgEnum with
variants Bash, Zsh, Fish) so invalid shell names are rejected at parse time;
update the struct Hook to use this Shell enum and derive the appropriate Clap
trait, then change the runtime match on the shell string (the match arm handling
bash/zsh/fish) to match on the Shell enum variants instead and adjust any places
that call .as_str() or expect a String accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/uteke-cli/src/main.rs`:
- Line 871: The hook currently checks only "$PWD/.uteke/uteke.db" and unsets
UTEKE_PROJECT_STORE when in a subdirectory; update the shell hook logic (e.g.,
the Bash function uteke_prompt_hook and the corresponding zsh/fish hook
functions) to walk up parent directories from $PWD to "/" and set
UTEKE_PROJECT_STORE to the first matching "<dir>/.uteke" when
"<dir>/.uteke/uteke.db" exists, returning immediately; if no match is found
unset UTEKE_PROJECT_STORE. Ensure the exported value is the .uteke directory
path (not the db file) and apply the same upward-search logic to the other shell
hook occurrences referenced in the diff.
- Around line 862-913: Replace the inline raw strings in the Commands::Hook
match arm (the branches for "bash", "zsh", "fish") with include_str! macros that
load the corresponding files in scripts/shell/uteke-hook.bash, ut eke-hook.zsh,
and ut eke-hook.fish so the compiled binary uses the canonical script sources;
update the match to call print!(include_str!("...")) (or use println! as
currently appropriate) for each shell branch instead of the large r#"... "#
literals, and also remove the doubled-brace escaping ({{ -> { and }}) from the
standalone script files so the embedded scripts contain the intended
single-brace shell functions/blocks.

---

Duplicate comments:
In `@scripts/shell/uteke-hook.bash`:
- Line 7: The hook currently only checks for ".uteke/uteke.db" in the current
directory; update uteke-hook.bash to search parent directories upward until root
to detect being inside a uteke project. Replace the single-file test with a loop
that walks up parents (e.g., using a variable like dir="$PWD" and repeatedly
testing [[ -f "$dir/.uteke/uteke.db" ]] and setting dir="$(dirname "$dir")"
until found or dir is "/" ), and ensure the logic sets a flag or exits the loop
when the file is found so the rest of the hook behaves the same.
- Around line 1-14: The shell hook logic in the repository is duplicated: the
standalone script defining _uteke_prev_dir, the function uteke_prompt_hook, and
the PROMPT_COMMAND assignment is also embedded inline in main.rs; switch main.rs
to load this canonical script via include_str! instead of the duplicated
hardcoded string, replacing the inline copy with include_str!("...") (pointing
to the canonical script) and using that runtime string where the embedded hook
is registered, so updates to uteke_prompt_hook, _uteke_prev_dir, or
PROMPT_COMMAND only need to be made in this single script file.

In `@scripts/shell/uteke-hook.fish`:
- Around line 1-9: The Fish hook script is duplicated inline in
crates/uteke-cli/src/main.rs (the __uteke_directory_change function block);
remove the inline duplicate and load the canonical script file instead by
replacing the hard-coded string in main.rs with an include_str!() that points to
this scripts/shell/uteke-hook.fish file (e.g.
include_str!(concat!(env!("CARGO_MANIFEST_DIR"),
"/scripts/shell/uteke-hook.fish")) or an appropriate relative path), so the
__uteke_directory_change hook is sourced from the single file rather than
duplicated in code.
- Line 4: The hook currently checks only the current directory with the line "if
test -f .uteke/uteke.db" and must instead search parent directories for
".uteke/uteke.db"; update the fish script (uteke-hook.fish) to walk up the
directory tree (e.g., loop while not root) checking each ancestor for
".uteke/uteke.db", stop when found, set the resolved path into the variable used
by the hook, and only proceed if that file is found; ensure you replace the
direct "if test -f .uteke/uteke.db" check with this ancestor-search logic so
behavior matches main.rs, bash, and zsh implementations.

In `@scripts/shell/uteke-hook.zsh`:
- Around line 1-10: This standalone Zsh hook is duplicated inline in main.rs;
remove the duplicate by consolidating the source to a single canonical string
and use include_str! in crates/uteke-cli/src/main.rs to embed it. Specifically,
keep the utek-hook.zsh file as the single source containing the
chpwd_functions+=(uteke_chpwd) and the utek_chpwd() function that sets/unsets
UTEKE_PROJECT_STORE, then update main.rs to load that content with include_str!
and stop duplicating the utek_chpwd snippet inline.
- Line 5: The check if [[ -f ".uteke/uteke.db" ]]; then should be replaced with
a parent-directory search: implement a loop in uweke-hook.zsh that walks up from
the current directory (e.g., while [ "$dir" != "/" ]) checking each ancestor for
".uteke/uteke.db", set a variable like UTEKE_DB_PATH when found and break, and
then use that variable (or a boolean) instead of the direct -f check; update any
subsequent code that assumes ".uteke/uteke.db" to use the discovered path or
abort if not found.

---

Nitpick comments:
In `@crates/uteke-cli/src/main.rs`:
- Around line 293-297: Replace the Hook.shell String with a Clap-backed enum
(e.g., enum Shell: ValueEnum/ArgEnum with variants Bash, Zsh, Fish) so invalid
shell names are rejected at parse time; update the struct Hook to use this Shell
enum and derive the appropriate Clap trait, then change the runtime match on the
shell string (the match arm handling bash/zsh/fish) to match on the Shell enum
variants instead and adjust any places that call .as_str() or expect a String
accordingly.

In `@scripts/shell/uteke-hook.zsh`:
- Line 3: Move the utekе_chpwd function definition so it appears before the line
that registers it in chpwd_functions; specifically, define the function named
utekе_chpwd first, then append it to chpwd_functions
(chpwd_functions+=(uteke_chpwd)) to improve clarity and follow conventional
ordering.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 42bc48a1-4af9-4d7e-9a19-88eb72f19c50

📥 Commits

Reviewing files that changed from the base of the PR and between aecc1ed and 29d8f8e.

📒 Files selected for processing (4)
  • crates/uteke-cli/src/main.rs
  • scripts/shell/uteke-hook.bash
  • scripts/shell/uteke-hook.fish
  • scripts/shell/uteke-hook.zsh

Comment on lines +862 to +913
Commands::Hook { shell } => {
match shell.as_str() {
"bash" => print!(
r#"# Uteke shell hook for Bash
# Add to ~/.bashrc: eval "$(uteke hook bash)"
_uteke_prev_dir="$PWD"
uteke_prompt_hook() {{
if [[ "$PWD" != "$_uteke_prev_dir" ]]; then
_uteke_prev_dir="$PWD"
if [[ -f ".uteke/uteke.db" ]]; then
export UTEKE_PROJECT_STORE="$PWD/.uteke"
else
unset UTEKE_PROJECT_STORE
fi
fi
}}
PROMPT_COMMAND="uteke_prompt_hook;${{PROMPT_COMMAND}}"
"#
),
"zsh" => print!(
r#"# Uteke shell hook for Zsh
# Add to ~/.zshrc: eval "$(uteke hook zsh)"
chpwd_functions+=(uteke_chpwd)
uteke_chpwd() {{
if [[ -f ".uteke/uteke.db" ]]; then
export UTEKE_PROJECT_STORE="$PWD/.uteke"
else
unset UTEKE_PROJECT_STORE
fi
}}
"#
),
"fish" => print!(
r#"# Uteke shell hook for Fish
# Add to ~/.config/fish/config.fish: uteke hook fish | source
function __uteke_directory_change --on-variable PWD
if test -f .uteke/uteke.db
set -gx UTEKE_PROJECT_STORE "$PWD/.uteke"
else
set -e UTEKE_PROJECT_STORE
end
end
"#
),
other => {
return Err(format!(
"Unknown shell: {other}. Supported shells: bash, zsh, fish"
))
}
}
Ok(())
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use include_str! to avoid duplication with script files.

The inline raw strings duplicate scripts/shell/uteke-hook.{bash,zsh,fish}. Maintaining two copies creates risk of divergence. Use include_str! to embed the actual script files at compile time.

♻️ Proposed fix using include_str!
         Commands::Hook { shell } => {
             match shell.as_str() {
-                "bash" => print!(
-                    r#"# Uteke shell hook for Bash
-# Add to ~/.bashrc: eval "$(uteke hook bash)"
-_uteke_prev_dir="$PWD"
-uteke_prompt_hook() {{
-    if [[ "$PWD" != "$_uteke_prev_dir" ]]; then
-        _uteke_prev_dir="$PWD"
-        if [[ -f ".uteke/uteke.db" ]]; then
-            export UTEKE_PROJECT_STORE="$PWD/.uteke"
-        else
-            unset UTEKE_PROJECT_STORE
-        fi
-    fi
-}}
-PROMPT_COMMAND="uteke_prompt_hook;${{PROMPT_COMMAND}}"
-"#
-                ),
+                "bash" => print!("{}", include_str!("../../../scripts/shell/uteke-hook.bash")),
-                "zsh" => print!(
-                    r#"# Uteke shell hook for Zsh
-# Add to ~/.zshrc: eval "$(uteke hook zsh)"
-chpwd_functions+=(uteke_chpwd)
-uteke_chpwd() {{
-    if [[ -f ".uteke/uteke.db" ]]; then
-        export UTEKE_PROJECT_STORE="$PWD/.uteke"
-    else
-        unset UTEKE_PROJECT_STORE
-    fi
-}}
-"#
-                ),
+                "zsh" => print!("{}", include_str!("../../../scripts/shell/uteke-hook.zsh")),
-                "fish" => print!(
-                    r#"# Uteke shell hook for Fish
-# Add to ~/.config/fish/config.fish: uteke hook fish | source
-function __uteke_directory_change --on-variable PWD
-    if test -f .uteke/uteke.db
-        set -gx UTEKE_PROJECT_STORE "$PWD/.uteke"
-    else
-        set -e UTEKE_PROJECT_STORE
-    end
-end
-"#
-                ),
+                "fish" => print!("{}", include_str!("../../../scripts/shell/uteke-hook.fish")),
                 other => {

Then remove the {{ double-brace escaping from the standalone script files (they should use single {}).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/uteke-cli/src/main.rs` around lines 862 - 913, Replace the inline raw
strings in the Commands::Hook match arm (the branches for "bash", "zsh", "fish")
with include_str! macros that load the corresponding files in
scripts/shell/uteke-hook.bash, ut eke-hook.zsh, and ut eke-hook.fish so the
compiled binary uses the canonical script sources; update the match to call
print!(include_str!("...")) (or use println! as currently appropriate) for each
shell branch instead of the large r#"... "# literals, and also remove the
doubled-brace escaping ({{ -> { and }}) from the standalone script files so the
embedded scripts contain the intended single-brace shell functions/blocks.

uteke_prompt_hook() {{
if [[ "$PWD" != "$_uteke_prev_dir" ]]; then
_uteke_prev_dir="$PWD"
if [[ -f ".uteke/uteke.db" ]]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Hooks only check current directory, not parent directories.

Issue #47 specifies: "detect project context files in the target directory or parent directories." The current implementation only checks .uteke/uteke.db in $PWD, so changing into a subdirectory of a uteke project will unset UTEKE_PROJECT_STORE.

🔍 Example fix for Bash (similar logic needed for zsh/fish)
uteke_prompt_hook() {
    if [[ "$PWD" != "$_uteke_prev_dir" ]]; then
        _uteke_prev_dir="$PWD"
        # Search current and parent directories
        local dir="$PWD"
        while [[ "$dir" != "/" ]]; do
            if [[ -f "$dir/.uteke/uteke.db" ]]; then
                export UTEKE_PROJECT_STORE="$dir/.uteke"
                return
            fi
            dir="$(dirname "$dir")"
        done
        unset UTEKE_PROJECT_STORE
    fi
}

Also applies to: 886-886, 898-898

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/uteke-cli/src/main.rs` at line 871, The hook currently checks only
"$PWD/.uteke/uteke.db" and unsets UTEKE_PROJECT_STORE when in a subdirectory;
update the shell hook logic (e.g., the Bash function uteke_prompt_hook and the
corresponding zsh/fish hook functions) to walk up parent directories from $PWD
to "/" and set UTEKE_PROJECT_STORE to the first matching "<dir>/.uteke" when
"<dir>/.uteke/uteke.db" exists, returning immediately; if no match is found
unset UTEKE_PROJECT_STORE. Ensure the exported value is the .uteke directory
path (not the db file) and apply the same upward-search logic to the other shell
hook occurrences referenced in the diff.

- Add hook scripts for bash, zsh, fish in scripts/shell/
- Add 'uteke hook <shell>' CLI subcommand
- Hooks detect .uteke/uteke.db and set UTEKE_PROJECT_STORE env var
- bash: PROMPT_COMMAND, zsh: chpwd_functions, fish: --on-variable PWD

Closes #47
@ajianaz
ajianaz force-pushed the feat/shell-hook branch from 29d8f8e to 3a5ecf3 Compare May 30, 2026 00:15
@ajianaz
ajianaz merged commit 368b18b into develop May 30, 2026
6 checks passed
@ajianaz ajianaz mentioned this pull request May 30, 2026
5 tasks done
ajianaz added a commit that referenced this pull request May 30, 2026
Tags management (list/rename/delete) was accidentally dropped during
the PR #72 rebase conflict resolution. This restores:
- TagInfo type in types.rs
- tags_with_counts, rename_tag, delete_tag in store.rs
- Tags CLI subcommand with List/Rename/Delete variants
- Uteke wrapper methods

All features verified with stress test: 50 write, recall, search,
tags, aging, export/import, cleanup — all passing.
@ajianaz
ajianaz deleted the feat/shell-hook branch May 30, 2026 04:55
KazamiHazaki pushed a commit to KazamiHazaki/uteke that referenced this pull request May 31, 2026
- Add parent directory search to all hook scripts (walk up to root)
- Use include_str! to load scripts from canonical files (no duplication)
- Add SupportedShell enum for parse-time validation
- Reorder zsh: define function before registering in chpwd_functions

See: codecoradev#72
ajianaz added a commit that referenced this pull request Aug 13, 2026
feat: shell hook for auto-context loading
ajianaz added a commit that referenced this pull request Aug 13, 2026
- Add parent directory search to all hook scripts (walk up to root)
- Use include_str! to load scripts from canonical files (no duplication)
- Add SupportedShell enum for parse-time validation
- Reorder zsh: define function before registering in chpwd_functions

See: #72
ajianaz added a commit that referenced this pull request Aug 13, 2026
Tags management (list/rename/delete) was accidentally dropped during
the PR #72 rebase conflict resolution. This restores:
- TagInfo type in types.rs
- tags_with_counts, rename_tag, delete_tag in store.rs
- Tags CLI subcommand with List/Rename/Delete variants
- Uteke wrapper methods

All features verified with stress test: 50 write, recall, search,
tags, aging, export/import, cleanup — all passing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: shell hook for auto-context loading

1 participant