@suwujs/codex-vault 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,123 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Post-write validation for vault notes — Claude Code version.
3
-
4
- Checks frontmatter and wikilinks on any .md file written to the vault.
5
- Outputs hookSpecificOutput with systemMessage for Claude Code terminal display.
6
- """
7
- import json
8
- import re
9
- import sys
10
- import os
11
- from pathlib import Path
12
-
13
-
14
- def _check_log_format(content):
15
- """Validate log.md entry format: ## [YYYY-MM-DD] <type> | <title>"""
16
- warnings = []
17
- for i, line in enumerate(content.splitlines(), 1):
18
- if line.startswith("## ") and not line.startswith("## ["):
19
- # Heading that looks like a log entry but missing date brackets
20
- if any(t in line.lower() for t in ["ingest", "session", "query", "maintenance", "decision", "archive"]):
21
- warnings.append(f"Line {i}: log entry missing date format — expected `## [YYYY-MM-DD] <type> | <title>`")
22
- elif line.startswith("## ["):
23
- if not re.match(r"^## \[\d{4}-\d{2}-\d{2}\] \w+", line):
24
- warnings.append(f"Line {i}: malformed log entry — expected `## [YYYY-MM-DD] <type> | <title>`")
25
- return warnings
26
-
27
-
28
- def main():
29
- try:
30
- input_data = json.load(sys.stdin)
31
- except (ValueError, EOFError, OSError):
32
- sys.exit(0)
33
-
34
- tool_input = input_data.get("tool_input")
35
- if not isinstance(tool_input, dict):
36
- sys.exit(0)
37
-
38
- file_path = tool_input.get("file_path", "")
39
- if not isinstance(file_path, str) or not file_path:
40
- sys.exit(0)
41
-
42
- if not file_path.endswith(".md"):
43
- sys.exit(0)
44
-
45
- normalized = file_path.replace("\\", "/")
46
- basename = os.path.basename(normalized)
47
-
48
- # Skip non-vault files
49
- skip_names = {"README.md", "CHANGELOG.md", "CONTRIBUTING.md", "CLAUDE.md", "AGENTS.md", "LICENSE"}
50
- if basename in skip_names:
51
- sys.exit(0)
52
- if basename.startswith("README.") and basename.endswith(".md"):
53
- sys.exit(0)
54
-
55
- skip_paths = [".claude/", ".codex/", ".codex-vault/", ".mind/", "templates/", "thinking/", "node_modules/", "plugin/", "docs/"]
56
- if any(skip in normalized for skip in skip_paths):
57
- sys.exit(0)
58
-
59
- warnings = []
60
-
61
- try:
62
- content = Path(file_path).read_text(encoding="utf-8")
63
-
64
- if not content.startswith("---"):
65
- warnings.append("Missing YAML frontmatter")
66
- else:
67
- parts = content.split("---", 2)
68
- if len(parts) >= 3:
69
- fm = parts[1]
70
- if "date:" not in fm and basename != "log.md":
71
- warnings.append("Missing `date` in frontmatter")
72
- if "tags:" not in fm:
73
- warnings.append("Missing `tags` in frontmatter")
74
- if "description:" not in fm:
75
- warnings.append("Missing `description` in frontmatter (~150 chars)")
76
-
77
- if len(content) > 300 and "[[" not in content:
78
- warnings.append("No [[wikilinks]] found — every note should link to at least one other note")
79
-
80
- # Check for unfilled template placeholders
81
- placeholders = re.findall(r"\{\{[^}]+\}\}", content)
82
- if placeholders:
83
- examples = ", ".join(placeholders[:3])
84
- warnings.append(f"Unfilled template placeholders found: {examples}")
85
-
86
- # Validate log.md format
87
- if basename == "log.md":
88
- log_warnings = _check_log_format(content)
89
- warnings.extend(log_warnings)
90
-
91
- except Exception:
92
- sys.exit(0)
93
-
94
- if warnings:
95
- hint_list = "\n".join(f" - {w}" for w in warnings)
96
- count = len(warnings)
97
- first = warnings[0]
98
- if count == 1:
99
- feedback = f"\u26a0\ufe0f vault: {basename} — {first}"
100
- else:
101
- feedback = f"\u26a0\ufe0f vault: {basename} — {first} (+{count - 1} more)"
102
-
103
- # Hook trigger notification
104
- print(f" {feedback}")
105
-
106
- output = {
107
- "hookSpecificOutput": {
108
- "hookEventName": "PostToolUse",
109
- "additionalContext": f"Vault warnings for `{basename}`:\n{hint_list}\nFix these before moving on."
110
- },
111
- "systemMessage": feedback
112
- }
113
- json.dump(output, sys.stdout)
114
- sys.stdout.flush()
115
-
116
- sys.exit(0)
117
-
118
-
119
- if __name__ == "__main__":
120
- try:
121
- main()
122
- except Exception:
123
- sys.exit(0)
@@ -1,301 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Classify user messages and inject routing hints — Codex CLI version.
3
-
4
- Lightweight version: 5 core signals + session-end vault integrity check.
5
- Outputs hookSpecificOutput for Codex CLI. Feedback via stderr
6
- (Codex CLI does not render systemMessage).
7
- """
8
- import json
9
- import os
10
- import subprocess
11
- import sys
12
- import re
13
- from pathlib import Path
14
-
15
-
16
- SIGNALS = [
17
- {
18
- "name": "DECISION",
19
- "skill": "/dump",
20
- "message": "DECISION detected — suggest the user run /dump to capture this decision",
21
- "auto_message": "DECISION detected — execute /dump now to capture this decision from the user's message",
22
- "patterns": [
23
- "decided", "deciding", "decision", "we chose", "agreed to",
24
- "let's go with", "the call is", "we're going with",
25
- ],
26
- },
27
- {
28
- "name": "WIN",
29
- "skill": "/dump",
30
- "message": "WIN detected — suggest the user run /dump to record this achievement",
31
- "auto_message": "WIN detected — execute /dump now to record this achievement from the user's message",
32
- "patterns": [
33
- "achieved", "won", "praised",
34
- "kudos", "shoutout", "great feedback", "recognized",
35
- ],
36
- },
37
- {
38
- "name": "PROJECT UPDATE",
39
- "skill": "/dump",
40
- "message": "PROJECT UPDATE detected — suggest the user run /dump to log this progress",
41
- "auto_message": "PROJECT UPDATE detected — execute /dump now to log this progress from the user's message",
42
- "patterns": [
43
- "project update", "sprint", "milestone",
44
- "shipped", "shipping", "launched", "launching",
45
- "completed", "completing", "released", "releasing",
46
- "deployed", "deploying",
47
- "went live", "rolled out", "merged", "cut the release",
48
- ],
49
- },
50
- {
51
- "name": "QUERY",
52
- "skill": "/recall",
53
- "message": "QUERY detected — suggest the user run /recall to check existing knowledge first",
54
- "auto_message": "QUERY detected — execute /recall now to search vault for relevant information before answering",
55
- "patterns": [
56
- "what is", "how does", "why did", "compare", "analyze",
57
- "explain the", "what's the difference", "summarize the",
58
- "relationship between",
59
- ],
60
- },
61
- {
62
- "name": "INGEST",
63
- "skill": "/ingest",
64
- "message": "INGEST detected — suggest the user run /ingest to process the source",
65
- "auto_message": "INGEST detected — execute /ingest now to process the source from the user's message",
66
- "patterns": [
67
- "ingest", "process this", "read this article",
68
- "summarize this", "new source", "clip this", "web clip",
69
- ],
70
- },
71
- ]
72
-
73
- SESSION_END_PATTERNS = [
74
- "wrap up", "wrapping up", "that's all", "that's it",
75
- "done for now", "done for today", "i'm done", "call it a day",
76
- "end session", "bye", "goodbye", "good night", "see you",
77
- "结束", "收工", "今天到这", "就这样",
78
- ]
79
-
80
-
81
- def _match(patterns, text):
82
- for phrase in patterns:
83
- if re.search(r'(?<![a-zA-Z])' + re.escape(phrase) + r'(?![a-zA-Z])', text):
84
- return True
85
- return False
86
-
87
-
88
- def _find_vault_root():
89
- """Find vault root from CWD — check for Home.md/brain/, then vault/ subdir."""
90
- cwd = os.environ.get("CODEX_PROJECT_DIR", os.getcwd())
91
- if os.path.isfile(os.path.join(cwd, "Home.md")) or os.path.isdir(os.path.join(cwd, "brain")):
92
- return cwd
93
- vault_sub = os.path.join(cwd, "vault")
94
- if os.path.isdir(vault_sub) and (
95
- os.path.isfile(os.path.join(vault_sub, "Home.md")) or
96
- os.path.isdir(os.path.join(vault_sub, "brain"))
97
- ):
98
- return vault_sub
99
- return None
100
-
101
-
102
- def _read_mode():
103
- """Read classify mode from vault config. Default: suggest."""
104
- vault_root = _find_vault_root()
105
- if not vault_root:
106
- return "suggest"
107
- config_path = os.path.join(vault_root, ".codex-vault", "config.json")
108
- try:
109
- with open(config_path) as f:
110
- config = json.load(f)
111
- mode = config.get("classify_mode", "suggest")
112
- if mode in ("suggest", "auto"):
113
- return mode
114
- except (OSError, ValueError, KeyError):
115
- pass
116
- return "suggest"
117
-
118
-
119
- def _get_changed_files(vault_root):
120
- """Get list of changed/new .md files relative to vault root."""
121
- files = set()
122
- try:
123
- # Staged + unstaged changes
124
- result = subprocess.run(
125
- ["git", "diff", "--name-only", "HEAD"],
126
- capture_output=True, text=True, cwd=vault_root, timeout=5,
127
- )
128
- for f in result.stdout.strip().splitlines():
129
- if f.endswith(".md"):
130
- files.add(f)
131
-
132
- # Untracked files
133
- result = subprocess.run(
134
- ["git", "ls-files", "--others", "--exclude-standard"],
135
- capture_output=True, text=True, cwd=vault_root, timeout=5,
136
- )
137
- for f in result.stdout.strip().splitlines():
138
- if f.endswith(".md"):
139
- files.add(f)
140
- except Exception:
141
- pass
142
- return files
143
-
144
-
145
- def _check_vault_integrity(vault_root):
146
- """Check for common memory-write omissions."""
147
- warnings = []
148
- changed = _get_changed_files(vault_root)
149
- if not changed:
150
- return warnings
151
-
152
- # Check 1: New work notes but Index.md not updated
153
- new_work = [f for f in changed if f.startswith("work/active/") and f != "work/Index.md"]
154
- index_updated = "work/Index.md" in changed
155
- if new_work and not index_updated:
156
- names = ", ".join(os.path.basename(f).replace(".md", "") for f in new_work)
157
- warnings.append(f"New work notes ({names}) but work/Index.md not updated")
158
-
159
- # Check 2: Decision content written but brain/Key Decisions.md not updated
160
- decision_keywords = ["decided", "decision", "agreed to", "we chose", "the call is"]
161
- brain_decisions_updated = "brain/Key Decisions.md" in changed
162
- if not brain_decisions_updated:
163
- for f in changed:
164
- if f.endswith(".md") and not f.startswith("brain/"):
165
- try:
166
- content = Path(os.path.join(vault_root, f)).read_text(encoding="utf-8").lower()
167
- if any(kw in content for kw in decision_keywords):
168
- warnings.append(
169
- f"'{f}' contains decision content but brain/Key Decisions.md not updated"
170
- )
171
- break
172
- except Exception:
173
- pass
174
-
175
- # Check 3: Pattern content written but brain/Patterns.md not updated
176
- pattern_keywords = ["pattern", "convention", "always do", "never do", "recurring"]
177
- brain_patterns_updated = "brain/Patterns.md" in changed
178
- if not brain_patterns_updated:
179
- for f in changed:
180
- if f.endswith(".md") and not f.startswith("brain/"):
181
- try:
182
- content = Path(os.path.join(vault_root, f)).read_text(encoding="utf-8").lower()
183
- if any(kw in content for kw in pattern_keywords):
184
- warnings.append(
185
- f"'{f}' contains pattern content but brain/Patterns.md not updated"
186
- )
187
- break
188
- except Exception:
189
- pass
190
-
191
- # Check 4: operation log not updated after significant changes
192
- log_updated = "log.md" in changed
193
- significant_changes = len([f for f in changed
194
- if f.startswith(("work/", "reference/", "brain/"))]) >= 2
195
- if significant_changes and not log_updated:
196
- warnings.append("Multiple vault changes but log.md not updated")
197
-
198
- return warnings
199
-
200
-
201
- def classify(prompt, mode="suggest"):
202
- p = prompt.lower()
203
- key = "auto_message" if mode == "auto" else "message"
204
- return [s[key] for s in SIGNALS if _match(s["patterns"], p)]
205
-
206
-
207
- def is_session_end(prompt):
208
- p = prompt.lower()
209
- return _match(SESSION_END_PATTERNS, p)
210
-
211
-
212
- def main():
213
- try:
214
- input_data = json.load(sys.stdin)
215
- except (ValueError, EOFError, OSError):
216
- sys.exit(0)
217
-
218
- prompt = input_data.get("prompt", "")
219
- if not isinstance(prompt, str) or not prompt:
220
- sys.exit(0)
221
-
222
- signal_messages = []
223
- session_end_messages = []
224
-
225
- try:
226
- mode = _read_mode()
227
-
228
- # Regular signal classification
229
- signals = classify(prompt, mode)
230
- signal_messages.extend(signals)
231
-
232
- # Session-end check (always suggest mode — never auto-execute wrap-up)
233
- if is_session_end(prompt):
234
- vault_root = _find_vault_root()
235
- if vault_root:
236
- integrity_warnings = _check_vault_integrity(vault_root)
237
- if integrity_warnings:
238
- session_end_messages.append(
239
- "SESSION END — vault integrity check found issues:\n"
240
- + "\n".join(f" - {w}" for w in integrity_warnings)
241
- + "\nFix these before wrapping up."
242
- )
243
- else:
244
- session_end_messages.append("SESSION END — vault integrity check passed.")
245
- except Exception:
246
- sys.exit(0)
247
-
248
- parts = []
249
-
250
- if signal_messages:
251
- hints = "\n".join(f"- {s}" for s in signal_messages)
252
- if mode == "auto":
253
- parts.append(
254
- "Auto-execute the following skills based on user intent:\n"
255
- + hints
256
- + "\n\nExecute the skill immediately with the user's message as input. Do not ask for confirmation."
257
- )
258
- else:
259
- parts.append(
260
- "Skill suggestions (do NOT auto-execute — suggest the skill to the user and let them decide):\n"
261
- + hints
262
- + "\n\nWait for the user to invoke the skill. Do not create vault notes without explicit user action."
263
- )
264
-
265
- if session_end_messages:
266
- hints = "\n".join(f"- {s}" for s in session_end_messages)
267
- parts.append(
268
- "Skill suggestions (do NOT auto-execute — suggest the skill to the user and let them decide):\n"
269
- + hints
270
- + "\n\nWait for the user to invoke the skill. Do not create vault notes without explicit user action."
271
- )
272
-
273
- if parts:
274
- context = "\n\n".join(parts)
275
-
276
- # Build feedback label
277
- matched = [s for s in SIGNALS if _match(s["patterns"], prompt.lower())]
278
- feedback_parts = []
279
- for s in matched:
280
- feedback_parts.append(f"{s['name']} → {s['skill']}")
281
- if is_session_end(prompt):
282
- feedback_parts.append("SESSION END → /wrap-up")
283
- icon = "\U0001f504" if mode == "auto" else "\U0001f4a1"
284
- label = ", ".join(feedback_parts) if feedback_parts else "intent detected"
285
-
286
- # stdout print → directly displayed to user
287
- print(f" {icon} vault: {label}")
288
-
289
- # systemMessage → injected into LLM context
290
- result = {"systemMessage": context}
291
- sys.stdout.write(json.dumps(result))
292
- sys.stdout.flush()
293
-
294
- sys.exit(0)
295
-
296
-
297
- if __name__ == "__main__":
298
- try:
299
- main()
300
- except Exception:
301
- sys.exit(0)