Skip to content

fix(okf): fix hook stdin, locking, prompt ordering - #894

Merged
yxtay merged 6 commits into
mainfrom
fix/okf-wiki-stdin-prompt
Jul 14, 2026
Merged

fix(okf): fix hook stdin, locking, prompt ordering#894
yxtay merged 6 commits into
mainfrom
fix/okf-wiki-stdin-prompt

Conversation

@yxtay

@yxtay yxtay commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fix claude -p failing with multiline positional args by piping prompt via stdin
  • Replace flock (Linux-only) with shlock (macOS-native) for exclusive locking
  • Remove invalid Skill from --allowed-tools (REPL-only, non-functional in -p mode)
  • Reorder prompt: wiki dir → user summary → project summary → recent journals
  • Always include yesterday's journal via -mtime -1 alongside -newer STATE_FILE

Test plan

  • Hook ran successfully end-to-end manually (bash -x trace confirmed claude -p reached and state file written)
  • Reinstall plugin after session close: claude plugin install okf-wiki@yxtay

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Wiki maintenance now distills recent memory files into the OKF wiki bundle.
    • Reviews include synthesized project and user context when available.
  • Bug Fixes

    • Improved maintenance reliability and cleanup when multiple runs overlap.
    • Avoids unnecessary processing when no new or recent memories are available.
    • Ensures state is updated only after successful wiki maintenance.

yxtay and others added 2 commits July 14, 2026 13:27
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>
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@yxtay, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 547d6dcb-0704-4297-806b-11acb3084fe1

📥 Commits

Reviewing files that changed from the base of the PR and between 23c7d90 and ea166b8.

📒 Files selected for processing (6)
  • chezmoi/.chezmoiscripts/run_onchange_after_setup_claude.sh.tmpl
  • chezmoi/private_dot_claude/okf/executable_okf-wiki-maintenance.sh
  • chezmoi/private_dot_claude/okf/okf-wiki-review.txt
  • plugins/.claude-plugin/marketplace.json
  • plugins/okf-wiki/.claude-plugin/plugin.json
  • plugins/okf-wiki/hooks/hooks.json
📝 Walkthrough

Walkthrough

The 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.

Changes

OKF wiki maintenance

Layer / File(s) Summary
Memory selection and maintenance execution
plugins/okf-wiki/hooks/okf-wiki-maintenance.sh
The hook uses an atomic mkdir lock, scans recent memsearch memory files, passes structured context to claude -p, and writes state only after successful execution.
Review prompt terminology
plugins/okf-wiki/prompts/okf-wiki-review.txt
Prompt instructions now refer to memory files, synthesized context, and files listed under “Recent memory:”.

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
Loading

Possibly related PRs

  • yxtay/dotfiles#891: Updates the same maintenance script’s SessionEnd Claude invocation and state behavior.

Poem

I’m a bunny with memories, hopping through files,
Locking the burrow in portable style.
Claude reads the fresh notes, the wiki grows bright,
State waits for success before saying goodnight.
Hop-hop—old journals now rest out of sight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main changes: stdin piping, locking, and prompt ordering fixes in the OKF hook.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/okf-wiki-stdin-prompt

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the fix label Jul 14, 2026
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ BASH shfmt 5 0 0 0 0.02s
✅ JSON prettier 5 0 0 0 0.37s
✅ MARKDOWN markdownlint 9 0 0 0 0.7s
✅ MARKDOWN markdown-table-formatter 11 0 0 0 0.15s
✅ YAML prettier 11 0 0 0 0.46s

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 BASH_SHFMT,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,YAML_PRETTIER

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +25 to +28
# 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
# 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

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ BASH bash-exec 5 0 0 0.01s
✅ BASH shellcheck 5 0 0 0.21s
✅ REPOSITORY betterleaks yes no no 2.67s
✅ REPOSITORY checkov yes no no 22.84s
✅ REPOSITORY devskim yes no no 2.27s
✅ REPOSITORY dustilock yes no no 0.01s
✅ REPOSITORY gitleaks yes no no 1.54s
✅ REPOSITORY grype yes no no 49.78s
✅ REPOSITORY kingfisher yes no no 11.35s
✅ REPOSITORY osv-scanner yes no no 0.14s
✅ REPOSITORY secretlint yes no no 1.73s
✅ REPOSITORY syft yes no no 1.87s
✅ REPOSITORY trivy yes no no 10.92s
✅ REPOSITORY trivy-sbom yes no no 0.17s
✅ REPOSITORY trufflehog yes no no 4.45s

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 BASH_EXEC,BASH_SHELLCHECK,REPOSITORY_CHECKOV,REPOSITORY_DEVSKIM,REPOSITORY_DUSTILOCK,REPOSITORY_GITLEAKS,REPOSITORY_BETTERLEAKS,REPOSITORY_GRYPE,REPOSITORY_OSV_SCANNER,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY,REPOSITORY_TRIVY_SBOM,REPOSITORY_TRUFFLEHOG,REPOSITORY_KINGFISHER

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

⚠️MegaLinter analysis: Success with warnings

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
⚠️ SPELL 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

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

yxtay and others added 3 commits July 14, 2026 13:49
…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>
@github-actions github-actions Bot added size/L and removed size/M labels Jul 14, 2026
@yxtay
yxtay merged commit 7f0a0f4 into main Jul 14, 2026
31 of 32 checks passed
@yxtay
yxtay deleted the fix/okf-wiki-stdin-prompt branch July 14, 2026 06:19

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
plugins/okf-wiki/hooks/okf-wiki-maintenance.sh (1)

39-46: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Find/selection logic is correct; JOURNAL_DIR naming 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 to MEMORY_DIR for 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0da70ab and 23c7d90.

📒 Files selected for processing (3)
  • chezmoi/private_dot_claude/executable_statusline-command.sh
  • plugins/okf-wiki/hooks/okf-wiki-maintenance.sh
  • plugins/okf-wiki/prompts/okf-wiki-review.txt

Comment on lines +24 to +28
# 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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 -S

Repository: 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 -S

Repository: 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']))
PY

Repository: 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 -S

Repository: 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"
done

Repository: 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.

Comment on lines 53 to 56
# 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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.

Suggested change
# 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant