Skip to content

Latest commit

 

History

History
67 lines (53 loc) · 3.49 KB

AGENTS.md

File metadata and controls

67 lines (53 loc) · 3.49 KB

AGENTS.md

Guidance for AI coding agents working in this repository.

Project

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.

Commands

  • Build: cargo build
  • Test: cargo test (unit tests live in src/tosubstr.rs, src/process.rs, src/lib.rs)
  • Lint: cargo clippy --all-targets (keep clean)
  • Format: cargo fmt / check with cargo fmt --check (keep clean)
  • Dev shell: Nix flake + direnv (.envrc). Shells: pinned (default, matches rust-toolchain.toml), msrv, stable-latest, nightly-latest (nix develop --shell <name>). Includes cargo-flamegraph and heaptrack.
  • Profiling: cargo build --profile profiling (line-tables-only debuginfo).

Toolchain

  • Pinned to nightly-2026-08-30 via rust-toolchain.toml. src/lib.rs uses nightly-only std features (slice_range); Do not introduce new nightly-only features unless a user explicitly asks to.

Architecture

  • 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 calls find_location_process --- the pure algorithm (BFS for the nearest process in KNOWN_PROCS) --- and reads the registry entry. write()/clear() manage the registry. The algorithm is tested without real processes: tests build synthetic trees with process::test_tree(&[(pid, name, ppid), ...]) and call find_location_process directly. 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 the Name: line of /proc/<pid>/status.
  • src/walk.rs --- generic, zero-allocation-per-node BFS/DFS tree walker. Walker reuses one VecDeque (workhorse pattern); visitor callbacks return ControlFlow<R, ContinueFlow> for early exit (Break) and pruning (Skip).
  • src/tosubstr.rs --- in-place String substring (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.

Conventions

  • Errors: anyhow with .context() at each layer; no custom error types.
  • Performance-conscious code: prefer reusing collections over allocating (workhorse pattern in walk.rs). Release profile uses lto = "fat", codegen-units = 1 --- keep it.
  • Debug output is gated behind cfg!(debug_assertions).
  • Commits: conventional commits (feat(scope):, fix(scope):, chore(scope):).

Gotchas

  • KNOWN_PROCS (["zsh", "nvim"]) in lib.rs is the list of processes the walker looks for; a new integration adds its process name here.
  • get prints LocationData::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.