Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
# data source only, no changes to memsearch itself.
set -euo pipefail

# Avoid recursing into our own hooks when the nested `claude -p` below exits.
if [ "${MEMSEARCH_DISABLE:-}" = "1" ] || [ "${OKF_WIKI_DISABLE:-}" = "1" ]; then
exit 0
fi

OKF_PLUGIN="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
MEMSEARCH_DIR="${MEMSEARCH_DIR:-${HOME}/.memsearch}"
JOURNAL_DIR="${MEMSEARCH_DIR}/memory"
WIKI_DIR="${OKF_WIKI_DIR:-${HOME}/wiki}"
STATE_FILE="${WIKI_DIR}/.okf-wiki-last-run"
LOCK_FILE="${WIKI_DIR}/.okf-wiki-maintenance.lock"
LOG_FILE="${WIKI_DIR}/.okf-wiki-maintenance.log"
PROMPT_FILE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/okf-wiki-review.txt"

[ -d "${JOURNAL_DIR}" ] || exit 0
[ -f "${PROMPT_FILE}" ] || exit 0
[ -d "${OKF_PLUGIN}" ] || exit 0
mkdir -p "${WIKI_DIR}"
command -v claude &>/dev/null || exit 0

Expand All @@ -37,7 +35,7 @@ if [ -f "${STATE_FILE}" ]; then
fi
fi

# Memories since last run, or last 3 days on first run. Always include yesterday (-mtime -1 = <24h).
# Memories since last run, or last 3 days on first run.
if [ -f "${STATE_FILE}" ]; then
recent_memories="$(find "${JOURNAL_DIR}" -maxdepth 1 -name '*.md' \( -newer "${STATE_FILE}" -o -mtime -1 \) 2>/dev/null)"
else
Expand All @@ -46,11 +44,6 @@ fi

[ -n "${recent_memories}" ] || exit 0

export MEMSEARCH_DISABLE=1
export MEMSEARCH_NO_WATCH=1
export OKF_WIKI_DISABLE=1
unset CLAUDECODE # clear CLAUDECODE so the child session doesn't inherit hook context

# hook runs with async:true — Claude Code does not block on this script.
# Run claude -p synchronously so mkdir lock holds for the full duration,
# preventing a concurrent trigger from starting a second run.
Expand All @@ -62,16 +55,22 @@ prompt="$(
printf 'Recent memory:\n%s\n' "${recent_memories}"
)"
if printf '%s' "${prompt}" | claude -p \
--bare \
--strict-mcp-config \
--no-session-persistence \
--model haiku \
--effort low \
--model sonnet \
--effort medium \
--permission-mode acceptEdits \
--allowed-tools "Read,Write,Edit,Glob,Grep" \
--plugin-dir "${OKF_PLUGIN}" \
--exclude-dynamic-system-prompt-sections \
--append-system-prompt-file "${PROMPT_FILE}" \
--add-dir "${WIKI_DIR}" \
--add-dir "${MEMSEARCH_DIR}" \
>/dev/null 2>&1; then
>>"${LOG_FILE}" 2>&1; then
date +%Y-%m-%d >"${STATE_FILE}"
else
printf '%s okf-wiki-maintenance failed (exit %s)\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$?" >>"${LOG_FILE}"
fi

exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ Step 2 — read `<wiki>/index.md` to understand the bundle's current structure.

Step 3 — read the files listed under "Recent memory:" in the user message, plus any user profile and project review files listed.

Step 4 — decide: is there anything worth adding or updating in the wiki?
Lean toward capturing. Capture any of:
Step 4 — extract every distinct topic worth capturing from the memory files. For each topic ask:
- How something works — tools, systems, integrations, flags, invocation patterns
- How something was set up or configured — steps, sequences, decisions made
- Why something was done — rationale, tradeoffs, constraints
- What was found — investigation results, things ruled out, gotchas
- What worked or didn't — patterns, failure modes, workarounds

Only skip if the knowledge is already fully covered by an existing concept, or if it is truly
ephemeral (e.g. a one-line typo fix with no transferable lesson). When in doubt, add it.
Only skip a topic if it is already fully covered by an existing concept, or if it is truly
ephemeral (e.g. a one-line typo fix with no transferable lesson). When in doubt, include it.
Prefer amending an existing concept over creating a new one for incremental additions.

Step 5 — if there is durable knowledge, apply the skill's **maintain** mode.
Step 5 — for each topic identified in Step 4, apply the skill's **maintain** mode. Work through
all topics before finishing — do not stop after the first document. Process every topic.

Constraints:
- Do not touch memsearch-owned files (PROJECT.md, USER.md, memory .md files) — read-only to you.
Expand Down
Loading