A self-organizing Obsidian vault that gives AI coding agents persistent memory.
TypeScript ai-agentsclaude-codecodex-cligemini-cliknowledge-managementobsidianobsidian-vaultpersistent-memorysecond-braintemplate
Fix hook crashes and config issues (#10)
Brenno Ferrarie6fb84c2ce39
diff --git a/.claude/scripts/classify-message.py b/.claude/scripts/classify-message.pyindex 7923533..31d6612 100755--- a/.claude/scripts/classify-message.py+++ b/.claude/scripts/classify-message.py@@ -1,57 +1,126 @@#!/usr/bin/env python3-"""Classify user messages and inject routing hints for Claude."""+"""Classify user messages and inject routing hints for Claude.++Architecture: data-driven signal matching. Each signal has a list of trigger+patterns checked via word-boundary regex. Words can appear in multiple signals+(explicit overlaps) because the cost of a false positive hint is ~0 (Claude+ignores irrelevant hints) while a false negative means missed routing.+"""import jsonimport sysimport re+# Each signal: name, routing message, and trigger patterns.+# Patterns are checked with \b word boundaries — safe for CJK/Latin mixed text.+# Words MAY appear in multiple signals to express natural category overlaps.+SIGNALS = [+ {+ "name": "DECISION",+ "message": "DECISION detected — consider creating a Decision Record in work/active/ and logging in work/Index.md Decisions Log",+ "patterns": [+ "decided", "decision", "we chose", "agreed to",+ "let's go with", "the call is", "we're going with",+ ],+ },+ {+ "name": "INCIDENT",+ "message": "INCIDENT detected — consider using /incident-capture or creating an incident note in work/incidents/",+ "patterns": [+ "incident", "outage", "pagerduty", "severity",+ "p0", "p1", "p2", "sev1", "sev2", "postmortem", "rca",+ ],+ },+ {+ "name": "1:1 CONTENT",+ "message": "1:1 CONTENT detected — consider creating a 1-on-1 note in work/1-1/ and updating the person note in org/people/",+ "patterns": [+ "1:1", "1-1", "1-on-1", "one on one", "1on1",+ "catch up with", "sync with",+ ],+ },+ {+ "name": "WIN",+ "message": "WIN detected — consider adding to perf/Brag Doc.md with a link to the evidence note",+ "patterns": [+ # Delivery (shared with PROJECT UPDATE)+ "shipped", "launched", "completed", "released", "deployed",+ # Achievement-specific+ "achieved", "won", "promoted", "praised", "win",+ "kudos", "shoutout", "great feedback", "recognized",+ ],+ },+ {+ "name": "ARCHITECTURE",+ "message": "ARCHITECTURE discussion — consider creating a reference note in reference/ or a decision record",+ "patterns": [+ "architecture", "system design", "rfc", "tech spec",+ "trade-off", "design doc", "adr",+ ],+ },+ {+ "name": "PERSON CONTEXT",+ "message": "PERSON CONTEXT detected — consider updating the relevant person note in org/people/ and linking from the conversation note",+ "patterns": [+ "told me", "said that", "feedback from", "met with",+ "talked to", "spoke with",+ "mentioned that", "mentioned the", "mentioned a",+ ],+ },+ {+ "name": "PROJECT UPDATE",+ "message": "PROJECT UPDATE detected — consider updating the active work note in work/active/ and checking if wins should go to brag doc",+ "patterns": [+ "project update", "sprint", "milestone",+ # Delivery (shared with WIN)+ "shipped", "shipped feature", "launched", "completed",+ "released", "deployed",+ # Delivery-only (not wins on their own)+ "went live", "rolled out", "merged", "cut the release",+ ],+ },+]++def _any_word_match(pattern_words: list, text: str) -> bool:- """Check if any phrase appears as a whole word/phrase in text (not substring)."""+ """Check if any phrase appears as a whole word/phrase in text.++ Uses Latin-letter boundaries instead of \\b. Python's \\b treats CJK+ characters as word characters (\\w), so \\bdecision\\b fails to match+ in "のdecisionについて" (no boundary between Hiragana and Latin).++ (?<![a-zA-Z]) and (?![a-zA-Z]) ensure English keywords aren't part of+ a larger English word, while allowing CJK adjacency.+ """for phrase in pattern_words:- if re.search(r'\b' + re.escape(phrase) + r'\b', text):+ if re.search(r'(?<![a-zA-Z])' + re.escape(phrase) + r'(?![a-zA-Z])', text):return Truereturn False-def classify(prompt: str) -> list[str]:+def classify(prompt: str) -> list:p = prompt.lower()signals = []-- if _any_word_match(["decided", "decision", "we chose", "agreed to", "let's go with", "the call is", "we're going with"], p):- signals.append("DECISION detected — consider creating a Decision Record in work/active/ and logging in work/Index.md Decisions Log")-- if _any_word_match(["incident", "outage", "down", "pagerduty", "severity", "p0", "p1", "p2", "sev1", "sev2", "postmortem", "rca"], p):- signals.append("INCIDENT detected — consider using /incident-capture or creating an incident note in work/incidents/")-- if _any_word_match(["1:1", "1-on-1", "one on one", "1on1", "catch up with", "sync with"], p):- signals.append("1:1 CONTENT detected — consider creating a 1-on-1 note in work/1-1/ and updating the person note in org/people/")-- if _any_word_match(["shipped", "launched", "completed", "achieved", "won", "promoted", "kudos", "shoutout", "great feedback", "recognized"], p):- signals.append("WIN detected — consider adding to perf/Brag Doc.md with a link to the evidence note")-- if _any_word_match(["architecture", "system design", "rfc", "tech spec", "trade-off", "design doc", "adr"], p):- signals.append("ARCHITECTURE discussion — consider creating a reference note in reference/ or a decision record")-- if _any_word_match(["told me", "said that", "feedback from", "met with", "talked to", "spoke with", "mentioned that"], p):- signals.append("PERSON CONTEXT detected — consider updating the relevant person note in org/people/ and linking from the conversation note")-- if _any_word_match(["project update", "sprint", "milestone", "shipped feature", "released", "deployed"], p):- signals.append("PROJECT UPDATE detected — consider updating the active work note in work/active/ and checking if wins should go to brag doc")-+ for sig in SIGNALS:+ if _any_word_match(sig["patterns"], p):+ signals.append(sig["message"])return signalsdef main():try:input_data = json.load(sys.stdin)- except (json.JSONDecodeError, EOFError):+ except (json.JSONDecodeError, ValueError, EOFError):sys.exit(0)prompt = input_data.get("prompt", "")- if not prompt:+ if not isinstance(prompt, str) or not prompt:sys.exit(0)- signals = classify(prompt)+ try:+ signals = classify(prompt)+ except Exception:+ sys.exit(0)if signals:hints = "\n".join(f"- {s}" for s in signals)diff --git a/.claude/scripts/validate-write.py b/.claude/scripts/validate-write.pyindex 80e4a34..bdab9b0 100755--- a/.claude/scripts/validate-write.py+++ b/.claude/scripts/validate-write.py@@ -8,11 +8,16 @@ from pathlib import Pathdef main():try:input_data = json.load(sys.stdin)- except (json.JSONDecodeError, EOFError):+ except (json.JSONDecodeError, ValueError, EOFError):+ sys.exit(0)++ tool_input = input_data.get("tool_input")+ if not isinstance(tool_input, dict):sys.exit(0)- tool_input = input_data.get("tool_input", {})file_path = tool_input.get("file_path", "")+ if not isinstance(file_path, str) or not file_path:+ sys.exit(0)# Only validate markdown files in the vault, skip dotfiles and templatesif not file_path.endswith(".md"):@@ -24,6 +29,9 @@ def main():root_files = {"README.md", "CHANGELOG.md", "CONTRIBUTING.md", "CLAUDE.md"}if basename in root_files:sys.exit(0)+ # Also skip translated READMEs (README.ja.md, README.zh-CN.md, etc.)+ if basename.startswith("README.") and basename.endswith(".md"):+ sys.exit(0)if any(skip in normalized for skip in [".claude/", ".obsidian/", "templates/", "thinking/"]):sys.exit(0)@@ -54,7 +62,6 @@ def main():sys.exit(0)if warnings:- basename = os.path.basename(file_path)hint_list = "\n".join(f" - {w}" for w in warnings)output = {"hookSpecificOutput": {diff --git a/.claude/settings.json b/.claude/settings.jsonindex 3f55eb4..54fe40c 100644--- a/.claude/settings.json+++ b/.claude/settings.json@@ -2,7 +2,7 @@"hooks": {"SessionStart": [{- "matcher": "startup|resume|clear",+ "matcher": "startup|resume|clear|compact","hooks": [{"type": "command",@@ -25,7 +25,7 @@],"PostToolUse": [{- "matcher": "Write|Edit|MultiEdit",+ "matcher": "Write|Edit","hooks": [{"type": "command",@@ -48,12 +48,11 @@],"Stop": [{- "matcher": "","hooks": [{"type": "command",- "command": "echo 'Session end checklist:\n- Archive completed projects? (work/active/ → work/archive/YYYY/)\n- Update indexes? (Index.md, Memories.md, People & Context, Brag Doc)\n- New notes linked? (orphans are bugs)\n- Run /vault-audit if many notes were created/modified'",- "timeout": 2+ "command": "bash -c 'INPUT=$(cat); ACTIVE=$(printf \"%s\" \"$INPUT\" | bash .claude/scripts/find-python.sh -c \"import json,sys; print(json.load(sys.stdin).get(\\\"stop_hook_active\\\",False))\" 2>/dev/null || echo False); [ \"$ACTIVE\" = \"True\" ] && exit 0; echo \"Session end checklist:\n- Archive completed projects? (work/active/ -> work/archive/YYYY/)\n- Update indexes? (Index.md, Memories.md, People & Context, Brag Doc)\n- New notes linked? (orphans are bugs)\n- Run /vault-audit if many notes were created/modified\"'",+ "timeout": 5}]}diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f7da74d..960bf21 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,5 +1,24 @@# Changelog+## v3.3.1 — 2026-04-05++### Fixed+- `classify-message.py`: crash (rc=1) when `prompt` is non-string type (int, None, bool, list) — now validates type before processing+- `classify-message.py`: `\b` word boundaries failed with CJK text — `\bdecision\b` did not match in `のdecisionについて` because Python treats CJK characters as `\w`. Replaced with Latin-letter lookaround `(?<![a-zA-Z])` / `(?![a-zA-Z])`+- `classify-message.py`: missing detection patterns — added `1-1`, `praised`, `win`, `mentioned the`, `mentioned a` to classifiers+- `classify-message.py`: delivery words (`shipped`, `launched`, `released`, `deployed`, `completed`) now trigger both WIN and PROJECT UPDATE (categories were incorrectly mutually exclusive)+- `classify-message.py`: added new PROJECT UPDATE patterns — `went live`, `rolled out`, `merged`, `cut the release`+- `classify-message.py`: changed `list[str]` return annotation to `list` for Python 3.8 compatibility+- `validate-write.py`: crash (rc=1) when `tool_input` is null or `file_path` is non-string — now validates types before processing+- `validate-write.py`: translated READMEs (README.ja.md, README.zh-CN.md, etc.) were validated as vault notes — now skipped+- `settings.json`: removed `MultiEdit` from PostToolUse matcher (not a valid Claude Code tool name)+- `settings.json`: removed unsupported `matcher` field from Stop hook (Stop event does not support matchers)+- `settings.json`: added `compact` to SessionStart matcher (hook was not firing after context compaction)+- `settings.json`: added `stop_hook_active` re-entry guard to Stop hook (prevents infinite loop when Claude acts on checklist output)++### Changed+- `classify-message.py`: refactored from 7 hardcoded if-blocks to data-driven `SIGNALS` list — patterns are now declarative, overlaps between categories are explicit and visible+## v3.3 — 2026-03-29### Added