Skip to content

Commit 2611695

Browse files
committed
chore(agents): add rules for branch verification and stale git lock files
1 parent 901df93 commit 2611695

2 files changed

Lines changed: 62 additions & 3 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{{ if eq .chezmoi.os "windows" -}}
2+
# Komorebi config hashes (trigger re-run when configs change):
3+
# komorebi.json: {{ include "dot_config/komorebi/komorebi.json" | sha256sum }}
4+
# whkdrc: {{ include "dot_config/whkdrc" | sha256sum }}
5+
6+
$ErrorActionPreference = "Stop"
7+
8+
function Resolve-KomorebicPath {
9+
$cmd = Get-Command komorebic.exe -ErrorAction SilentlyContinue
10+
if (-not $cmd) {
11+
$cmd = Get-Command komorebic -ErrorAction SilentlyContinue
12+
}
13+
if ($cmd -and -not [string]::IsNullOrWhiteSpace($cmd.Source)) {
14+
return $cmd.Source
15+
}
16+
17+
$candidates = @(
18+
"$env:USERPROFILE\scoop\shims\komorebic.exe",
19+
"$env:LOCALAPPDATA\Microsoft\WinGet\Links\komorebic.exe",
20+
"$env:ProgramFiles\komorebi\bin\komorebic.exe"
21+
)
22+
return ($candidates | Where-Object {
23+
-not [string]::IsNullOrWhiteSpace($_) -and (Test-Path $_)
24+
} | Select-Object -First 1)
25+
}
26+
27+
$komorebic = Resolve-KomorebicPath
28+
29+
if (Get-Process -Name "komorebi" -ErrorAction SilentlyContinue) {
30+
if (-not $komorebic) {
31+
Write-Host "Komorebi process found but komorebic could not be resolved; skipping reload." -ForegroundColor DarkGray
32+
return
33+
}
34+
Write-Host "Reloading Komorebi configuration..."
35+
& $komorebic reload-configuration
36+
if ($LASTEXITCODE -ne 0) {
37+
throw "Komorebi reload failed (exit code $LASTEXITCODE)."
38+
}
39+
40+
# whkd has no live-reload — restart it so new whkdrc takes effect.
41+
if (Get-Process -Name "whkd" -ErrorAction SilentlyContinue) {
42+
Write-Host "Restarting whkd to pick up new keybindings..."
43+
Stop-Process -Name "whkd" -Force -ErrorAction SilentlyContinue
44+
Start-Sleep -Milliseconds 500
45+
$whkdCmd = Get-Command whkd.exe -ErrorAction SilentlyContinue
46+
if ($whkdCmd) {
47+
Start-Process -FilePath $whkdCmd.Source -WindowStyle Hidden
48+
}
49+
}
50+
} else {
51+
if (-not $komorebic) {
52+
Write-Host "Komorebi not found; skipping reload." -ForegroundColor DarkGray
53+
return
54+
}
55+
Write-Host "Komorebi is installed but not running; skipping reload." -ForegroundColor DarkGray
56+
}
57+
{{- end }}

home/dot_agents/AGENTS.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ These constraints are unconditional. Apply them without being asked.
1919

2020
## Session close: mandatory
2121

22-
After every non-trivial task, load the `retrospective` skill and follow it before closing out.
22+
After every non-trivial task, run a retrospective before closing out.
2323

2424
---
2525

@@ -28,7 +28,7 @@ After every non-trivial task, load the `retrospective` skill and follow it befor
2828
Global memory is `~/.agents/AGENTS.md` (source: `~/.local/share/chezmoi/home/dot_agents/AGENTS.md`).
2929
Local memory is the `AGENTS.md` in the current project root (or nearest ancestor).
3030

31-
Never edit `~/.agents/AGENTS.md` directly; it is chezmoi-managed. Load the `memory` skill for all writes.
31+
Never edit `~/.agents/AGENTS.md` directly; it is chezmoi-managed.
3232

3333
For rules specific to the chezmoi dotfiles repo itself, the target is `~/.local/share/chezmoi/AGENTS.md`.
3434

@@ -38,9 +38,11 @@ When updating any memory file: review nearby rules for contradictions, duplicati
3838

3939
## Git and commits
4040

41-
- Load `git-commit-push` for commit or push operations.
4241
- Before committing, run `git diff --staged` and confirm the change is atomic and in-scope. Do not commit unrelated modifications.
4342
- Commit message format: `type(scope): description`. Types: `feat`, `fix`, `chore`. Check `git log --oneline` to match repo style.
43+
- After any branch switch (including `gh pr checkout`), immediately verify with `git branch --show-current`. `gh pr checkout` can silently leave you on the wrong branch when the local tracking branch has diverged; if it fails or the branch is wrong, use `git checkout <branch-name>` directly.
44+
- A stale `.git/index.lock` blocks all git operations. Remove it with `rm -f .git/index.lock` before retrying the blocked command.
45+
- **Worktree context.** When the cwd is inside a Claude Code worktree (e.g. `.claude/worktrees/<id>`), git and gh commands operate on the worktree branch, not the main repo. To check out a PR or named branch in the main repo, use an explicit path: `git -C /path/to/main-repo checkout <branch>`. Always confirm the active branch with `git branch --show-current` before reading or editing files.
4446

4547
---
4648

0 commit comments

Comments
 (0)