fix(okf): fix hook stdin, locking, prompt ordering - #894
Conversation
claude -p fails with multiline positional args; pipe via printf|stdin instead. Remove Skill from --allowed-tools (REPL-only, non-functional in -p mode). Update comments to drop stale PreCompact references. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- Replace flock (Linux-only) with shlock (macOS-native) for exclusive locking; auto-breaks stale locks via PID check - Build prompt via subshell in order: wiki dir, user summary, project summary, recent journals; removes extra_context intermediary - Always include yesterday's journal with -mtime -1 alongside -newer Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 46 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThe OKF wiki maintenance hook now distills recent memsearch memory files using portable atomic locking, structured Claude prompt input, and success-gated state updates. The review prompt aligns its terminology and file-selection instructions with the new memory-based workflow. ChangesOKF wiki maintenance
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Hook as okf-wiki-maintenance.sh
participant Memories as memsearch memory directory
participant Claude as claude -p
participant Wiki as ~/wiki OKF bundle
Hook->>Memories: scan recent memory .md files
Hook->>Claude: pipe structured prompt and context
Claude->>Wiki: maintain wiki bundle
Hook->>Hook: write state after successful execution
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
✅MegaLinter analysis: Success
Notices📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining See detailed reports in MegaLinter artifacts Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining
|
There was a problem hiding this comment.
Code Review
This pull request refactors the okf-wiki-maintenance.sh script to use shlock instead of flock for locking, always include yesterday's journals, and pipe the prompt into claude -p instead of passing it as an argument. Feedback points out that shlock is not widely available on macOS or Linux, which would cause the script to silently exit on most machines, and suggests using atomic directory creation (mkdir) as a portable alternative.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| # shlock is macOS-native (no flock); writes PID and auto-breaks stale locks. | ||
| command -v shlock &>/dev/null || exit 0 | ||
| shlock -f "${LOCK_FILE}" -p $$ || exit 0 | ||
| trap 'rm -f "${LOCK_FILE}"' EXIT |
There was a problem hiding this comment.
shlock is not installed by default on macOS or most Linux distributions (it is historically part of the inn or uucp packages). Because of command -v shlock &>/dev/null || exit 0, this script will silently exit and fail to run on almost all user machines.
To make the locking mechanism portable and zero-dependency across both macOS and Linux, you can use atomic directory creation (mkdir) instead.
| # shlock is macOS-native (no flock); writes PID and auto-breaks stale locks. | |
| command -v shlock &>/dev/null || exit 0 | |
| shlock -f "${LOCK_FILE}" -p $$ || exit 0 | |
| trap 'rm -f "${LOCK_FILE}"' EXIT | |
| # Uses atomic directory creation for a portable, zero-dependency lock. | |
| LOCK_DIR="${LOCK_FILE}.lock" | |
| if ! mkdir "${LOCK_DIR}" 2>/dev/null; then | |
| exit 0 | |
| fi | |
| trap 'rmdir "${LOCK_DIR}"' EXIT |
✅MegaLinter analysis: Success
Notices📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining See detailed reports in MegaLinter artifacts Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining
|
✅
|
| Descriptor | Linter | Files | Fixed | Errors | Warnings | Elapsed time |
|---|---|---|---|---|---|---|
| ✅ ACTION | actionlint | 5 | 0 | 0 | 0.23s | |
| ✅ ACTION | zizmor | 5 | 0 | 0 | 0 | 1.05s |
| ✅ BASH | bash-exec | 5 | 0 | 0 | 0.02s | |
| ✅ BASH | shellcheck | 5 | 0 | 0 | 0.17s | |
| ✅ BASH | shfmt | 5 | 0 | 0 | 0 | 0.01s |
| ✅ COPYPASTE | jscpd | yes | no | no | 0.11s | |
| ✅ EDITORCONFIG | editorconfig-checker | 82 | 0 | 0 | 0.18s | |
| ✅ JSON | prettier | 5 | 0 | 0 | 0 | 0.4s |
| ✅ JSON | v8r | 9 | 0 | 0 | 3.76s | |
| ✅ MARKDOWN | markdownlint | 9 | 0 | 0 | 0 | 0.73s |
| ✅ MARKDOWN | markdown-table-formatter | 11 | 0 | 0 | 0 | 0.23s |
| ✅ REPOSITORY | betterleaks | yes | no | no | 3.6s | |
| ✅ REPOSITORY | checkov | yes | no | no | 25.58s | |
| ✅ REPOSITORY | gitleaks | yes | no | no | 1.57s | |
| ✅ REPOSITORY | git_diff | yes | no | no | 0.01s | |
| ✅ REPOSITORY | grype | yes | no | no | 52.05s | |
| ✅ REPOSITORY | osv-scanner | yes | no | no | 0.21s | |
| ✅ REPOSITORY | secretlint | yes | no | no | 1.32s | |
| ✅ REPOSITORY | syft | yes | no | no | 4.68s | |
| ✅ REPOSITORY | trivy | yes | no | no | 12.7s | |
| ✅ REPOSITORY | trivy-sbom | yes | no | no | 0.17s | |
| ✅ REPOSITORY | trufflehog | yes | no | no | 4.34s | |
| lychee | 32 | 9 | 0 | 1.2s | ||
| ✅ YAML | prettier | 11 | 0 | 0 | 0 | 0.58s |
| ✅ YAML | v8r | 11 | 0 | 0 | 7.15s | |
| ✅ YAML | yamllint | 11 | 0 | 0 | 0.54s |
Detailed Issues
⚠️ SPELL / lychee - 9 errors
📝 Summary
---------------------
🔍 Total...........32
🔗 Unique..........24
✅ Successful......23
⏳ Timeouts.........0
🔀 Redirected.......3
👻 Excluded.........0
❓ Unknown..........0
🚫 Errors...........9
⛔ Unsupported......9
Errors in chezmoi/.chezmoitemplates/mcp_servers.json
[406] https://mcp.deepwiki.com/mcp (at 11:15) | Rejected status code: 406 Not Acceptable
Errors in chezmoi/.chezmoitemplates/opencode.json
[406] https://mcp.deepwiki.com/mcp (at 32:15) | Rejected status code: 406 Not Acceptable
Errors in chezmoi/private_dot_agents/skills/okf/templates/concept.md
[ERROR] file://chezmoi/private_dot_agents/skills/okf/templates/url (at 24:5) | File not found. Check if file exists and path is correct
Errors in chezmoi/private_dot_agents/skills/okf/templates/index.md
[ERROR] file://chezmoi/private_dot_agents/skills/okf/templates/relative-url (at 3:3) | File not found. Check if file exists and path is correct
[ERROR] file://chezmoi/private_dot_agents/skills/okf/templates/relative-url (at 4:3) | File not found. Check if file exists and path is correct
[ERROR] file://chezmoi/private_dot_agents/skills/okf/templates/subdir (at 8:3) | File not found. Check if file exists and path is correct
Errors in chezmoi/private_dot_agents/skills/okf/templates/log.md
[ERROR] file://chezmoi/private_dot_agents/skills/okf/templates/bundle-relative-path (at 5:36) | File not found. Check if file exists and path is correct
[ERROR] file://chezmoi/private_dot_agents/skills/okf/templates/bundle-relative-path (at 6:30) | File not found. Check if file exists and path is correct
[ERROR] file://chezmoi/private_dot_agents/skills/okf/templates/bundle-relative-path (at 7:39) | File not found. Check if file exists and path is correct
Hint: Followed 3 redirects. You might want to consider replacing redirecting URLs with the resolved URLs. Use verbose mode (`-v`/`-vv`) to see redirection details.
Hint: You can configure accepted/rejected response codes with `-a` or `--accept`
Notices
📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining SECURITY_SUGGESTIONS: false)
See detailed reports in MegaLinter artifacts
Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining FLAVOR_SUGGESTIONS: false)
- Documentation: Custom Flavors
- Command:
npx mega-linter-runner@9.6.0 --custom-flavor-setup --custom-flavor-linters ACTION_ACTIONLINT,ACTION_ZIZMOR,BASH_EXEC,BASH_SHELLCHECK,BASH_SHFMT,COPYPASTE_JSCPD,EDITORCONFIG_EDITORCONFIG_CHECKER,JSON_V8R,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_GITLEAKS,REPOSITORY_BETTERLEAKS,REPOSITORY_GRYPE,REPOSITORY_OSV_SCANNER,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY,REPOSITORY_TRIVY_SBOM,REPOSITORY_TRUFFLEHOG,SPELL_LYCHEE,YAML_PRETTIER,YAML_YAMLLINT,YAML_V8R

Show us your support by starring ⭐ the repository
…iew) Rename journal→memory, user summary→user profile, project summary→project review throughout hook script and prompt file to match memsearch's own naming conventions. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…lock - chezmoi statusline script was missing execute bit (bash-exec lint error) - replace shlock with atomic mkdir for POSIX portability (shlock is macOS-only) Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Plugin mechanism requires manual reinstall after each change — not suitable for frequently iterated local hooks. Move maintenance script and prompt into chezmoi/private_dot_claude/okf/ so chezmoi apply keeps them in sync. Remove plugins/okf-wiki and local marketplace. Add cleanup commands to setup script for machines with old install. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
plugins/okf-wiki/hooks/okf-wiki-maintenance.sh (1)
39-46: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winFind/selection logic is correct;
JOURNAL_DIRnaming still lags the terminology alignment.The selection logic (newer-than-state OR last 24h, 3-day fallback on first run) is correct and matches the stated intent. However,
JOURNAL_DIR(used at lines 41 and 43) is the one remaining "journal" name in a file that otherwise consistently renamed everything to "memory"/"memories" — worth renaming toMEMORY_DIRfor consistency with this PR's stated terminology-alignment goal.♻️ Suggested rename
-JOURNAL_DIR="${MEMSEARCH_DIR}/memory" +MEMORY_DIR="${MEMSEARCH_DIR}/memory"(and update the two
${JOURNAL_DIR}references at lines 41 and 43 accordingly)🤖 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 `@plugins/okf-wiki/hooks/okf-wiki-maintenance.sh` around lines 39 - 46, Rename the directory variable from JOURNAL_DIR to MEMORY_DIR in the maintenance script, and update both find-command references in the recent_memories selection logic. Preserve the existing selection conditions and behavior unchanged.
🤖 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 `@plugins/okf-wiki/hooks/okf-wiki-maintenance.sh`:
- Around line 53-56: Update the maintenance hook comment describing synchronous
execution to replace the stale “shlock” terminology with the current atomic
mkdir-based lock terminology, while preserving the explanation that the lock
must remain held for the full run to prevent concurrent triggers.
- Around line 24-28: Update the lock acquisition flow around LOCK_FILE and the
EXIT trap to recover from stale lock directories when the owning process is no
longer running, or otherwise provide an expiry path. Preserve atomic exclusive
locking for active maintenance runs, and ensure later invocations do not exit
silently forever because of a lock left by a killed process.
---
Nitpick comments:
In `@plugins/okf-wiki/hooks/okf-wiki-maintenance.sh`:
- Around line 39-46: Rename the directory variable from JOURNAL_DIR to
MEMORY_DIR in the maintenance script, and update both find-command references in
the recent_memories selection logic. Preserve the existing selection conditions
and behavior unchanged.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 86d1ae2d-914b-48e1-b3d7-fd18aecfb67e
📒 Files selected for processing (3)
chezmoi/private_dot_claude/executable_statusline-command.shplugins/okf-wiki/hooks/okf-wiki-maintenance.shplugins/okf-wiki/prompts/okf-wiki-review.txt
| # Acquire exclusive lock via atomic mkdir — POSIX portable, no flock/shlock needed. | ||
| if ! mkdir "${LOCK_FILE}" 2>/dev/null; then | ||
| exit 0 | ||
| fi | ||
| trap 'rmdir "${LOCK_FILE}"' EXIT |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
set -euo pipefail
printf 'FILES\n'
git ls-files 'plugins/okf-wiki/hooks/okf-wiki-maintenance.sh' 'plugins/okf-wiki/**' | sed -n '1,120p'
printf '\nSCRIPT\n'
wc -l plugins/okf-wiki/hooks/okf-wiki-maintenance.sh
cat -n plugins/okf-wiki/hooks/okf-wiki-maintenance.sh
printf '\nSEARCH LOCK/TIMEOUT\n'
rg -n 'LOCK_FILE|timeout|SessionEnd|flock|mkdir' plugins/okf-wiki -SRepository: yxtay/dotfiles
Length of output: 244
🏁 Script executed:
set -euo pipefail
printf 'HOOK CONFIG\n'
fd -a 'hooks.json' plugins/okf-wiki -t f -g 'hooks.json' -g '*.json' | sed -n '1,20p'
rg -n '"timeout"|SessionEnd|okf-wiki-maintenance|LOCK_FILE' plugins/okf-wiki -SRepository: yxtay/dotfiles
Length of output: 378
🏁 Script executed:
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
p = Path('plugins/okf-wiki/hooks/okf-wiki-maintenance.sh')
print(p.exists(), p)
if p.exists():
txt = p.read_text()
print('contains stale recovery:', any(k in txt for k in ['mmin', 'stale', 'timeout', 'find']))
PYRepository: yxtay/dotfiles
Length of output: 205
🏁 Script executed:
set -euo pipefail
printf 'TOP-LEVEL FILES\n'
git ls-files | sed -n '1,200p'
printf '\nPOSSIBLE OKF WIKI FILES\n'
git ls-files | rg -n 'okf-wiki|maintenance|hooks\.json|\.sh$' -n -S
printf '\nDIRECTORY SNAPSHOT\n'
find . -maxdepth 3 -type d | sed -n '1,200p'Repository: yxtay/dotfiles
Length of output: 4416
🏁 Script executed:
set -euo pipefail
printf 'FILE: chezmoi/private_dot_claude/okf/executable_okf-wiki-maintenance.sh\n'
wc -l chezmoi/private_dot_claude/okf/executable_okf-wiki-maintenance.sh
cat -n chezmoi/private_dot_claude/okf/executable_okf-wiki-maintenance.sh
printf '\nRELATED REFERENCES\n'
rg -n 'okf-wiki-maintenance|LOCK_FILE|flock|mkdir|timeout|SessionEnd|hook' chezmoi -SRepository: yxtay/dotfiles
Length of output: 5420
🏁 Script executed:
set -euo pipefail
printf 'NEARBY FILES\n'
git ls-files 'chezmoi/private_dot_claude/okf/*' | sed -n '1,120p'
printf '\nHOOK/WRAPPER CONTENT\n'
for f in \
chezmoi/private_dot_claude/okf/executable_okf-wiki-maintenance.sh \
chezmoi/private_dot_claude/okf/okf-wiki-review.txt
do
echo "--- $f"
wc -l "$f"
cat -n "$f"
doneRepository: yxtay/dotfiles
Length of output: 6083
mkdir lock can leave the hook disabled forever. If the process is killed before the EXIT trap runs, .okf-wiki-maintenance.lock remains and every later invocation immediately exits 0 with no logging. Add stale-lock recovery or another expiry path.
🤖 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 `@plugins/okf-wiki/hooks/okf-wiki-maintenance.sh` around lines 24 - 28, Update
the lock acquisition flow around LOCK_FILE and the EXIT trap to recover from
stale lock directories when the owning process is no longer running, or
otherwise provide an expiry path. Preserve atomic exclusive locking for active
maintenance runs, and ensure later invocations do not exit silently forever
because of a lock left by a killed process.
| # hook runs with async:true — Claude Code does not block on this script. | ||
| # Run claude -p synchronously so flock holds for the full duration, preventing | ||
| # a concurrent PreCompact trigger from starting a second run. | ||
| # Run claude -p synchronously so shlock holds for the full duration, preventing | ||
| # a concurrent trigger from starting a second run. | ||
| # Write state file only on success so a failed run does not suppress the next. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Stale "shlock" reference — the lock is now mkdir-based.
This comment (line 54) still refers to "shlock," but the actual lock implemented at line 24-28 is an atomic mkdir. Leftover terminology from an earlier implementation iteration; misleading for future readers.
📝 Proposed fix
-# Run claude -p synchronously so shlock holds for the full duration, preventing
+# Run claude -p synchronously so the mkdir lock holds for the full duration, preventing
# a concurrent trigger from starting a second run.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # hook runs with async:true — Claude Code does not block on this script. | |
| # Run claude -p synchronously so flock holds for the full duration, preventing | |
| # a concurrent PreCompact trigger from starting a second run. | |
| # Run claude -p synchronously so shlock holds for the full duration, preventing | |
| # a concurrent trigger from starting a second run. | |
| # Write state file only on success so a failed run does not suppress the next. | |
| # hook runs with async:true — Claude Code does not block on this script. | |
| # Run claude -p synchronously so the mkdir lock holds for the full duration, preventing | |
| # a concurrent trigger from starting a second run. | |
| # Write state file only on success so a failed run does not suppress the next. |
🤖 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 `@plugins/okf-wiki/hooks/okf-wiki-maintenance.sh` around lines 53 - 56, Update
the maintenance hook comment describing synchronous execution to replace the
stale “shlock” terminology with the current atomic mkdir-based lock terminology,
while preserving the explanation that the lock must remain held for the full run
to prevent concurrent triggers.
Summary
claude -pfailing with multiline positional args by piping prompt via stdinflock(Linux-only) withshlock(macOS-native) for exclusive lockingSkillfrom--allowed-tools(REPL-only, non-functional in-pmode)-mtime -1alongside-newer STATE_FILETest plan
bash -xtrace confirmedclaude -preached and state file written)claude plugin install okf-wiki@yxtay🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes