Skip to content

Commit 8aa9c5c

Browse files
authored
refactor: extract magic strings, decompose long functions, standardize error display (#628)
* refactor: extract magic strings, decompose long functions, standardize error display - Add WORKTREE_ADMIN_PREFIX constant to naming.rs alongside KILD_BRANCH_PREFIX - Use kild_branch_name() instead of raw format!("kild/{}") in pr.rs, detail_view.rs - Use KILD_BRANCH_PREFIX in kild_branch_name() function body - Add SHIM_VERSION constant for tmux version string in shim commands - Extract kill_tracked_agents() from destroy_session() (127 lines → helper) - Extract sweep_ui_daemon_sessions() from destroy_session() (55 lines → helper) - Extract resolve_resume_args() from open_session() (46 lines → helper) - Add display_operation_error() helper for consistent CLI error formatting - Standardize error display across open, hide, focus, diff, health, stats, sync, commits, and teammates commands to use color::error() consistently Closes #438 * fix: address PR review — restore comment, tighten visibility, fix test helpers - Restore non-fatal comment on daemon cleanup in kill_tracked_agents() - Change WORKTREE_ADMIN_PREFIX to pub(crate) — no external callers - Replace raw format!("kild/...") in cleanup/handler.rs and overlaps.rs test helpers with kild_branch_name() / kild_worktree_admin_name() * fix: address review feedback from PR review agents - Fix kill_tracked_agents docstring: clarify daemon errors are always non-fatal, not gated on force flag - Fix resolve_resume_args docstring: document is_bare_shell parameter and error return paths - Remove .unwrap() in kill_tracked_agents, use indexing instead - Change display_operation_error to use impl Display over &dyn Display - Inline WORKTREE_ADMIN_PREFIX constant (single use site) - Reuse kild_branch variable in pr.rs no_pr_found path - Use imported color module instead of crate::color in teammates.rs - Add kild-git crate to CLAUDE.md workspace structure
1 parent 9375e68 commit 8aa9c5c

18 files changed

Lines changed: 302 additions & 239 deletions

File tree

CLAUDE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ cargo run -p kild -- complete my-branch # Complete kild (PR clean
136136
- `crates/kild-paths` - Centralized path construction for ~/.kild/ directory layout (KildPaths struct with typed methods for all paths including `tls_cert_path()` and `tls_key_path()` for daemon TLS certs, and `fleet_dir()`, `fleet_project_dir()`, `fleet_dropbox_dir()` for fleet dropbox paths). Single source of truth for KILD filesystem layout.
137137
- `crates/kild-config` - TOML configuration types, loading, validation, and keybindings for ~/.kild/config.toml. Depends only on kild-paths and kild-protocol. Single source of truth for all KildConfig/Config/Keybindings types. Extracted from kild-core to enable fast incremental compilation of config-only changes.
138138
- `crates/kild-protocol` - Shared IPC protocol types (ClientMessage, DaemonMessage, DaemonSessionStatus, SessionStatus, ErrorCode), domain newtypes (SessionId, BranchName, ProjectId), and serde-only domain enums (ForgeType). Also provides `IpcConnection` for JSONL-over-Unix-socket-or-TCP/TLS client used by both kild-core and kild-tmux-shim with connection health checking via `is_alive()` and TLS variant via `connect_tls()`, and `AsyncIpcClient<R, W>` — a generic async JSONL client over any `AsyncBufRead + AsyncWrite` pair used by kild-ui. Also provides `pool` module with `take(socket_path)` and `release(conn)` functions — shared thread-local `IpcConnection` pool used by both kild-core and kild-tmux-shim. All public enums are `#[non_exhaustive]` for forward compatibility. Newtypes defined via `newtype_string!` macro for compile-time type safety. Deps: serde, serde_json, futures (tempfile, smol for tests). No tokio, no kild-core. Single source of truth for daemon wire format and IPC client.
139+
- `crates/kild-git` - Git worktree naming, health, project queries, and CLI helpers. `naming.rs` is the single source of truth for `KILD_BRANCH_PREFIX`, `kild_branch_name()`, and `kild_worktree_admin_name()`. Consumed by kild-core, kild-ui, and kild-tmux-shim.
139140
- `crates/kild-core` - Core library with all business logic, no CLI dependencies
140141
- `crates/kild` - Thin CLI that consumes kild-core (clap for arg parsing, color.rs for Tallinn Night palette output)
141142
- `crates/kild-daemon` - Standalone daemon binary for PTY management (async tokio server, JSONL IPC protocol, portable-pty integration). CLI spawns this as subprocess. Wire types re-exported from kild-protocol. Optionally binds a TLS-wrapped TCP listener (`bind_tcp`) alongside the Unix socket for remote access; self-signed cert auto-generated at `~/.kild/certs/` on first start.
@@ -152,7 +153,7 @@ cargo run -p kild -- complete my-branch # Complete kild (PR clean
152153
- `agents/` - Agent backend system (amp, claude, kiro, gemini, codex, opencode, resume.rs for session continuity)
153154
- `daemon/` - Daemon client for IPC communication with auto-start logic (discovers kild-daemon binary as sibling executable). Connection pooling delegates to `kild_protocol::pool`. `tofu.rs` implements SHA-256 TOFU fingerprint verification for remote TCP/TLS connections. `mod.rs` exposes `set_remote_override()` for `--remote` CLI flag to route connections via TCP/TLS without touching handler signatures.
154155
- `editor/` - Editor backend system (Zed, VS Code, Vim, generic fallback) with registry.rs for detection and resolution chain (CLI > config > $VISUAL > $EDITOR > OS default via duti/xdg-mime > PATH scan)
155-
- `git/` - Git worktree operations via git2
156+
- `git/` - Git worktree operations via git2 (overlaps, removals, CLI shelling). Naming utilities (`kild_branch_name`, `KILD_BRANCH_PREFIX`) live in the separate `kild-git` crate.
156157
- `forge/` - Forge backend system (GitHub, future: GitLab, Bitbucket, Gitea) for PR operations
157158
- `config/` - REMOVED (moved to kild-config crate). kild-core re-exports all types from kild-config.
158159
- `projects/` - Project management (types, validation, persistence, manager)

crates/kild-core/src/cleanup/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,8 @@ mod tests {
10071007

10081008
git::test_support::init_repo_with_commit(repo_dir.path()).unwrap();
10091009

1010-
let branch_name = format!("kild/{branch_suffix}");
1011-
let admin_name = format!("kild-{branch_suffix}");
1010+
let branch_name = git::naming::kild_branch_name(branch_suffix);
1011+
let admin_name = git::naming::kild_worktree_admin_name(branch_suffix);
10121012
git::test_support::create_branch(repo_dir.path(), &branch_name).unwrap();
10131013

10141014
let worktree_path = worktree_base.path().join(&admin_name);

crates/kild-core/src/git/overlaps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ mod tests {
283283
.current_dir(dir)
284284
.output()
285285
.unwrap();
286-
let kild_branch = format!("kild/{}", branch);
286+
let kild_branch = crate::git::naming::kild_branch_name(branch);
287287
Command::new("git")
288288
.args(["checkout", "-b", &kild_branch])
289289
.current_dir(dir)

0 commit comments

Comments
 (0)