Guidance for AI coding agents working in this repository.
current-location is a Rust CLI that resolves the "Current Working File" of the currently active
window (Hyprland). Integrating programs (zsh, NeoVim) record their location via
current-location write; current-location get walks the process tree from the active window to
find the nearest known process and prints its recorded location as JSON on stdout. See README.md
for the user facing description and integration examples.
- Build:
cargo build - Test:
cargo test(unit tests live insrc/tosubstr.rs,src/process.rs,src/lib.rs) - Lint:
cargo clippy --all-targets(keep clean) - Format:
cargo fmt/ check withcargo fmt --check(keep clean) - Dev shell: Nix flake + direnv (
.envrc). Shells:pinned(default, matchesrust-toolchain.toml),msrv,stable-latest,nightly-latest(nix develop --shell <name>). Includescargo-flamegraphandheaptrack. - Profiling:
cargo build --profile profiling(line-tables-only debuginfo).
- Pinned to
nightly-2026-08-30viarust-toolchain.toml.src/lib.rsuses nightly-only std features (slice_range); Do not introduce new nightly-only features unless a user explicitly asks to.
src/main.rs--- clap CLI (get/write/clear). Async main uses#[tokio::main(flavor = "current_thread")]deliberately for fast startup --- do not switch to multi-thread.src/lib.rs--- core logic.search()resolves the active window PID (Hyprland, or--active-pid/CURRENT_LOCATION_ACTIVE_PID), builds the process tree, then callsfind_location_process--- the pure algorithm (BFS for the nearest process inKNOWN_PROCS) --- and reads the registry entry.write()/clear()manage the registry. The algorithm is tested without real processes: tests build synthetic trees withprocess::test_tree(&[(pid, name, ppid), ...])and callfind_location_processdirectly. Keep new algorithm changes covered there.src/process.rs--- builds the process tree from/proc(procfs). Processes that die mid-scan are skipped; children of PID 1 are skipped on purpose (huge, useless vec). Process names come from theName:line of/proc/<pid>/status.src/walk.rs--- generic, zero-allocation-per-node BFS/DFS tree walker.Walkerreuses oneVecDeque(workhorse pattern); visitor callbacks returnControlFlow<R, ContinueFlow>for early exit (Break) and pruning (Skip).src/tosubstr.rs--- in-placeStringsubstring (to_substr) to avoid reallocation; panics on invalid ranges by design.
Location registry: /tmp/current-location-<uid>/ (dir 0700, files 0600), one file per (name,
pid). Per-user by design for privacy --- keep it that way.
- Errors:
anyhowwith.context()at each layer; no custom error types. - Performance-conscious code: prefer reusing collections over allocating (workhorse pattern in
walk.rs). Release profile useslto = "fat",codegen-units = 1--- keep it. - Debug output is gated behind
cfg!(debug_assertions). - Commits: conventional commits (
feat(scope):,fix(scope):,chore(scope):).
KNOWN_PROCS(["zsh", "nvim"]) inlib.rsis the list of processes the walker looks for; a new integration adds its process name here.getprintsLocationData::fallback()JSON (with"fallback": true), not an error, when there is no active window, no known process, or no registry file --- callers depend on this behavior.