@suwujs/codex-vault 0.5.3 → 0.6.0

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,221 +0,0 @@
1
- #!/bin/bash
2
- set -eo pipefail
3
-
4
- # Codex-Vault session-start hook
5
- # Injects vault context into the agent's prompt at session start.
6
- # Works with any agent that supports SessionStart hooks (Claude Code, Codex CLI).
7
- #
8
- # Output contract (matches claude-mem pattern):
9
- # stdout → JSON with hookSpecificOutput.additionalContext (agent context)
10
- # stderr → visible banner (user terminal)
11
- #
12
- # Dynamic context: adapts git log window, reads full North Star,
13
- # shows all active work, and includes uncommitted changes.
14
-
15
- VAULT_DIR="${CLAUDE_PROJECT_DIR:-${CODEX_PROJECT_DIR:-$(pwd)}}"
16
- cd "$VAULT_DIR"
17
-
18
- # Find vault root (look for Home.md or brain/ directory)
19
- if [ ! -f "Home.md" ] && [ ! -d "brain/" ]; then
20
- # Try vault/ subdirectory (integrated layout)
21
- if [ -d "vault/" ]; then
22
- VAULT_DIR="$VAULT_DIR/vault"
23
- cd "$VAULT_DIR"
24
- fi
25
- fi
26
-
27
- # --- Visible banner (stderr → user terminal) ---
28
- {
29
- echo ""
30
- echo " 📚 Codex-Vault · Session Loaded"
31
-
32
- # North Star preview
33
- if [ -f "brain/North Star.md" ]; then
34
- GOAL=$(sed -n '/^## Current Focus/,/^## /{/^- ./{s/^- //;p;q;};}' "brain/North Star.md" | cut -c1-40)
35
- [ -n "$GOAL" ] && echo " 🎯 $GOAL" || echo " 🎯 (set goals in North Star.md)"
36
- else
37
- echo " 🎯 (create brain/North Star.md)"
38
- fi
39
-
40
- # Active work count
41
- WORK_COUNT=$(find work/active -name "*.md" 2>/dev/null | wc -l | tr -d ' ')
42
- echo " 📋 $WORK_COUNT active project(s)"
43
-
44
- # Uncommitted changes count
45
- CHANGE_COUNT=$(git status --short -- . 2>/dev/null | wc -l | tr -d ' ')
46
- if [ "$CHANGE_COUNT" -gt 0 ]; then
47
- echo " ✏️ $CHANGE_COUNT uncommitted change(s)"
48
- else
49
- echo " ✅ working tree clean"
50
- fi
51
- echo ""
52
- } >&2
53
-
54
- # --- Collect context into variable ---
55
- CONTEXT=$(
56
- cat <<'CONTEXT_HEADER'
57
- ## Session Context
58
-
59
- CONTEXT_HEADER
60
-
61
- echo "### Date"
62
- echo "$(date +%Y-%m-%d) ($(date +%A))"
63
- echo ""
64
-
65
- # North Star — full file (should be concise by design)
66
- echo "### North Star"
67
- if [ -f "brain/North Star.md" ]; then
68
- cat "brain/North Star.md"
69
- else
70
- echo "(No North Star found — create brain/North Star.md to set goals)"
71
- fi
72
- echo ""
73
-
74
- # Recent changes — adaptive window
75
- echo "### Recent Changes"
76
- COMMITS_48H=$(git log --oneline --since="48 hours ago" --no-merges 2>/dev/null | wc -l | tr -d ' ')
77
- if [ "$COMMITS_48H" -gt 0 ]; then
78
- echo "(last 48 hours)"
79
- git log --oneline --since="48 hours ago" --no-merges 2>/dev/null | head -15 || true
80
- else
81
- COMMITS_7D=$(git log --oneline --since="7 days ago" --no-merges 2>/dev/null | wc -l | tr -d ' ')
82
- if [ "$COMMITS_7D" -gt 0 ]; then
83
- echo "(nothing in 48h — showing last 7 days)"
84
- git log --oneline --since="7 days ago" --no-merges 2>/dev/null | head -15 || true
85
- else
86
- echo "(nothing recent — showing last 5 commits)"
87
- git log --oneline -5 --no-merges 2>/dev/null || echo "(no git history)"
88
- fi
89
- fi
90
- echo ""
91
-
92
- # Recent operations from log — adaptive
93
- echo "### Recent Operations"
94
- if [ -f "log.md" ]; then
95
- ENTRY_COUNT=$(grep -c "^## \[" "log.md" 2>/dev/null || echo "0")
96
- if [ "$ENTRY_COUNT" -gt 0 ]; then
97
- # Show last 5 entries with full header line (includes date + type)
98
- grep "^## \[" "log.md" | tail -5
99
- else
100
- echo "(no entries in log.md)"
101
- fi
102
- else
103
- echo "(no log.md)"
104
- fi
105
- echo ""
106
-
107
- # Active work — show all (this is the current focus, no truncation)
108
- echo "### Active Work"
109
- if [ -d "work/active" ]; then
110
- WORK_FILES=$(ls work/active/*.md 2>/dev/null || true)
111
- if [ -n "$WORK_FILES" ]; then
112
- echo "$WORK_FILES" | sed 's|work/active/||;s|\.md$||'
113
- else
114
- echo "(none)"
115
- fi
116
- else
117
- echo "(no work/active/ directory)"
118
- fi
119
- echo ""
120
-
121
- # Uncommitted changes — shows agent what's in-flight
122
- echo "### Uncommitted Changes"
123
- CHANGES=$(git status --short -- . 2>/dev/null | head -20 || true)
124
- if [ -n "$CHANGES" ]; then
125
- echo "$CHANGES"
126
- else
127
- echo "(working tree clean)"
128
- fi
129
- echo ""
130
-
131
- # Recently modified brain files — highlights memory that may need review
132
- echo "### Recently Modified Brain Files"
133
- if [ -d "brain" ]; then
134
- GIT_DIR=$(git rev-parse --git-dir 2>/dev/null || echo "")
135
- if [ -n "$GIT_DIR" ] && [ -f "$GIT_DIR/index" ]; then
136
- RECENT_BRAIN=$(find brain/ -name "*.md" -newer "$GIT_DIR/index" 2>/dev/null || true)
137
- else
138
- RECENT_BRAIN=""
139
- fi
140
- if [ -n "$RECENT_BRAIN" ]; then
141
- echo "$RECENT_BRAIN" | sed 's|brain/||;s|\.md$||'
142
- else
143
- # Fallback: show brain files modified in last 7 days
144
- RECENT_BRAIN=$(find brain/ -name "*.md" -mtime -7 2>/dev/null || true)
145
- if [ -n "$RECENT_BRAIN" ]; then
146
- echo "(modified in last 7 days)"
147
- echo "$RECENT_BRAIN" | sed 's|brain/||;s|\.md$||'
148
- else
149
- echo "(no recent changes)"
150
- fi
151
- fi
152
- fi
153
- echo ""
154
-
155
- # Vault file listing — tiered to avoid flooding context in large vaults
156
- echo "### Vault Files"
157
- ALL_FILES=$(find . -name "*.md" -not -path "./.git/*" -not -path "./.obsidian/*" -not -path "./thinking/*" -not -path "./.claude/*" -not -path "./.codex/*" -not -path "./.codex-vault/*" -not -path "./node_modules/*" 2>/dev/null | sort)
158
- FILE_COUNT=$(echo "$ALL_FILES" | grep -c . 2>/dev/null || echo "0")
159
-
160
- _folder_summary() {
161
- echo "$ALL_FILES" | sed 's|^\./||' | cut -d/ -f1 | sort | uniq -c | sort -rn | while read count dir; do
162
- echo " $dir/ ($count files)"
163
- done
164
- }
165
-
166
- _key_files() {
167
- echo "$ALL_FILES" | grep -E "(Home|Index|North Star|Memories|Key Decisions|Patterns|log)\\.md$" || true
168
- }
169
-
170
- if [ "$FILE_COUNT" -le 20 ]; then
171
- echo "$ALL_FILES"
172
-
173
- elif [ "$FILE_COUNT" -le 50 ]; then
174
- HOT_FILES=$(echo "$ALL_FILES" | grep -v -E "^\./sources/|^\./work/archive/" || true)
175
- COLD_COUNT=$(echo "$ALL_FILES" | grep -E "^\./sources/|^\./work/archive/" | grep -c . 2>/dev/null || echo "0")
176
-
177
- if [ -n "$HOT_FILES" ]; then
178
- echo "$HOT_FILES"
179
- fi
180
- if [ "$COLD_COUNT" -gt 0 ]; then
181
- echo ""
182
- echo "(+ $COLD_COUNT files in sources/ and work/archive/ — use /recall to search)"
183
- fi
184
-
185
- elif [ "$FILE_COUNT" -le 150 ]; then
186
- echo "($FILE_COUNT files — showing summary)"
187
- echo ""
188
- _folder_summary
189
- echo ""
190
- echo "Recently modified (7 days):"
191
- find . -name "*.md" -mtime -7 -not -path "./.git/*" -not -path "./.obsidian/*" -not -path "./thinking/*" -not -path "./.claude/*" -not -path "./.codex/*" -not -path "./.codex-vault/*" -not -path "./node_modules/*" 2>/dev/null | sort || echo " (none)"
192
- echo ""
193
- echo "Key files:"
194
- _key_files
195
-
196
- else
197
- echo "($FILE_COUNT files — showing summary)"
198
- echo ""
199
- _folder_summary
200
- echo ""
201
- echo "Recently modified (3 days):"
202
- find . -name "*.md" -mtime -3 -not -path "./.git/*" -not -path "./.obsidian/*" -not -path "./thinking/*" -not -path "./.claude/*" -not -path "./.codex/*" -not -path "./.codex-vault/*" -not -path "./node_modules/*" 2>/dev/null | sort || echo " (none)"
203
- echo ""
204
- echo "Key files:"
205
- _key_files
206
- echo ""
207
- echo "Use /recall <topic> to search the vault."
208
- fi
209
- )
210
-
211
- # --- Output structured JSON (stdout → agent via hookSpecificOutput) ---
212
- python3 -c "
213
- import json, sys
214
- context = sys.stdin.read()
215
- json.dump({
216
- 'hookSpecificOutput': {
217
- 'hookEventName': 'SessionStart',
218
- 'additionalContext': context
219
- }
220
- }, sys.stdout)
221
- " <<< "$CONTEXT"