vault-sync: 2026-09-16 12:01 (jimmy)
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
# =============================================================================
|
||||
# Hook: Desktop Notification (Notification event)
|
||||
# =============================================================================
|
||||
# Sends a macOS/Linux desktop notification when your agent platform needs attention.
|
||||
# Useful during long agent chains that can take several minutes.
|
||||
#
|
||||
# macOS: uses osascript (built-in)
|
||||
# Linux: uses notify-send (install with: sudo apt install libnotify-bin)
|
||||
# =============================================================================
|
||||
|
||||
INPUT=$(cat)
|
||||
TITLE=$(echo "$INPUT" | jq -r '.args.title // "Second Brain Crew"' 2>/dev/null)
|
||||
MESSAGE=$(echo "$INPUT" | jq -r '.args.message // "Your obsidian crew needs your attention"' 2>/dev/null)
|
||||
|
||||
if [[ "$(uname)" == "Darwin" ]]; then
|
||||
osascript -e "display notification \"$MESSAGE\" with title \"$TITLE\"" 2>/dev/null
|
||||
elif command -v notify-send &>/dev/null; then
|
||||
notify-send "$TITLE" "$MESSAGE" 2>/dev/null
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
# =============================================================================
|
||||
# Hook: Protect System Files (PreToolUse on Write/Edit)
|
||||
# =============================================================================
|
||||
# Prevents agents from accidentally overwriting core crew files at runtime.
|
||||
# Custom agents in the platform agents directory are allowed (the Architect
|
||||
# creates them). User-mutable references (agents-registry.md, agents.md) are
|
||||
# also allowed.
|
||||
#
|
||||
# Reads platform_dir and dispatcher_name from the neutral JSON input to
|
||||
# determine which paths to protect. Falls back to .claude / CLAUDE.md if
|
||||
# the fields are missing (backward compatibility).
|
||||
#
|
||||
# Exit codes:
|
||||
# 0 = allow the operation
|
||||
# 2 = block the operation (hard reject)
|
||||
# =============================================================================
|
||||
|
||||
INPUT=$(cat)
|
||||
FILE=$(echo "$INPUT" | jq -r '.args.file_path // .args.command // ""' 2>/dev/null)
|
||||
|
||||
# If we can't extract a file path, allow the operation
|
||||
[[ -z "$FILE" ]] && exit 0
|
||||
|
||||
BASENAME=$(basename "$FILE")
|
||||
PLATFORM_DIR=$(echo "$INPUT" | jq -r '.platform_dir // ".claude"' 2>/dev/null)
|
||||
DISPATCHER_NAME=$(echo "$INPUT" | jq -r '.dispatcher_name // "CLAUDE.md"' 2>/dev/null)
|
||||
|
||||
# ── Dispatcher file: never modify at runtime ──────────────────────────────
|
||||
if [[ "$BASENAME" == "$DISPATCHER_NAME" && "$FILE" != *"$PLATFORM_DIR/"* ]]; then
|
||||
echo "BLOCKED: $DISPATCHER_NAME is a system file. Update it in the repo and run updateme.sh."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# ── Core agent definitions: never modify at runtime ─────────────────────────
|
||||
CORE_AGENTS="architect.md scribe.md sorter.md seeker.md connector.md librarian.md transcriber.md postman.md"
|
||||
if [[ "$FILE" == *"$PLATFORM_DIR/agents/"* ]]; then
|
||||
for core in $CORE_AGENTS; do
|
||||
if [[ "$BASENAME" == "$core" ]]; then
|
||||
echo "BLOCKED: $BASENAME is a core agent definition. Update it in the repo and run updateme.sh."
|
||||
exit 2
|
||||
fi
|
||||
done
|
||||
# Custom agents are allowed through
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ── Skills: never modify at runtime ─────────────────────────────────────────
|
||||
if [[ "$FILE" == *"$PLATFORM_DIR/skills/"* ]]; then
|
||||
echo "BLOCKED: Skill files are managed by the repo. Update them in the repo and run updateme.sh."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# ── Core references: block all except user-mutable ones ─────────────────────
|
||||
if [[ "$FILE" == *"$PLATFORM_DIR/references/"* ]]; then
|
||||
USER_MUTABLE="agents-registry.md agents.md"
|
||||
for allowed in $USER_MUTABLE; do
|
||||
[[ "$BASENAME" == "$allowed" ]] && exit 0
|
||||
done
|
||||
echo "BLOCKED: $BASENAME is a core reference file. Update it in the repo and run updateme.sh."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Everything else is allowed
|
||||
exit 0
|
||||
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
# =============================================================================
|
||||
# Hook: Validate Frontmatter (PostToolUse on Write)
|
||||
# =============================================================================
|
||||
# After writing a .md file to the vault, checks that YAML frontmatter is
|
||||
# properly formed. Obsidian relies on frontmatter for metadata, Dataview
|
||||
# queries, tags, and search. Broken frontmatter silently breaks all of this.
|
||||
#
|
||||
# Checks:
|
||||
# 1. If the file starts with ---, there must be a closing ---
|
||||
# 2. No tabs in frontmatter (YAML uses spaces only)
|
||||
# 3. Colons in values must be quoted
|
||||
#
|
||||
# Exit codes:
|
||||
# 0 = all good
|
||||
# 1 = warning (issue found, but operation is not blocked)
|
||||
# =============================================================================
|
||||
|
||||
INPUT=$(cat)
|
||||
PLATFORM_DIR=$(echo "$INPUT" | jq -r '.platform_dir // ".claude"' 2>/dev/null)
|
||||
FILE=$(echo "$INPUT" | jq -r '.args.file_path // ""' 2>/dev/null)
|
||||
|
||||
# Skip if we can't extract a path
|
||||
[[ -z "$FILE" ]] && exit 0
|
||||
|
||||
# Only check .md files
|
||||
[[ "$FILE" == *.md ]] || exit 0
|
||||
|
||||
# Skip system files (agents, skills, references)
|
||||
[[ "$FILE" == *"$PLATFORM_DIR/"* ]] && exit 0
|
||||
|
||||
# Skip if file doesn't exist (deleted or moved)
|
||||
[[ -f "$FILE" ]] || exit 0
|
||||
|
||||
# ── Check 1: frontmatter delimiters ─────────────────────────────────────────
|
||||
FIRST_LINE=$(head -1 "$FILE")
|
||||
if [[ "$FIRST_LINE" == "---" ]]; then
|
||||
# Count opening and closing delimiters (lines that are exactly ---)
|
||||
DELIMITER_COUNT=$(grep -c "^---$" "$FILE" 2>/dev/null || echo "0")
|
||||
if [[ "$DELIMITER_COUNT" -lt 2 ]]; then
|
||||
echo "WARNING: Frontmatter in $(basename "$FILE") is missing the closing '---' delimiter. Obsidian will not parse metadata correctly."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract frontmatter content (between first and second ---)
|
||||
FRONTMATTER=$(sed -n '2,/^---$/p' "$FILE" | head -n -1)
|
||||
|
||||
# ── Check 2: tabs in frontmatter ────────────────────────────────────────
|
||||
TAB_CHAR="$(printf '\t')"
|
||||
if echo "$FRONTMATTER" | grep -q "$TAB_CHAR"; then
|
||||
TAB_LINES=$(echo "$FRONTMATTER" | grep -n "$TAB_CHAR" | head -3)
|
||||
echo "WARNING: Frontmatter in $(basename "$FILE") contains tabs. YAML requires spaces for indentation. Lines with tabs: $TAB_LINES"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ── Check 3: common YAML errors ────────────────────────────────────────
|
||||
# Unquoted values with colons (e.g., "title: My Note: Part 2" breaks YAML)
|
||||
if echo "$FRONTMATTER" | grep -qE '^[a-zA-Z_-]+: .+: '; then
|
||||
PROBLEM_LINES=$(echo "$FRONTMATTER" | grep -nE '^[a-zA-Z_-]+: .+: ' | head -3)
|
||||
echo "WARNING: Frontmatter in $(basename "$FILE") may have unquoted colons in values. Wrap the value in quotes to avoid YAML parse errors. Problem lines: $PROBLEM_LINES"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user