From 85ee92a47a18d288762abba97cc70cdd3d168f61 Mon Sep 17 00:00:00 2001 From: AINative Admin Date: Fri, 24 Apr 2026 20:07:39 -0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20Status=20bar=20widget=20=E2=80=94?= =?UTF-8?q?=20memory=20count=20and=20sync=20state=20via=20statusline=20scr?= =?UTF-8?q?ipt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add statusline/zerodb-status.sh: cache-based status widget with four display states (saving, synced, 0 memories, offline/error) - Register statusline script in .claude-plugin/plugin.json - Update hooks/session-end.sh to write saving state to status cache before persist - Update hooks/session-start.sh to write synced state to status cache after recall - Cache lives at ${TMPDIR:-/tmp}/zerodb-status/status.json to avoid API polling Refs #11 --- .claude-plugin/plugin.json | 3 ++- hooks/session-end.sh | 5 +++++ hooks/session-start.sh | 5 +++++ statusline/zerodb-status.sh | 41 +++++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 statusline/zerodb-status.sh diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 5146cc8..954667e 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -15,5 +15,6 @@ "hooks": { "Stop": "hooks/session-end.sh", "PreToolUse": "hooks/session-start.sh" - } + }, + "statusline": "statusline/zerodb-status.sh" } diff --git a/hooks/session-end.sh b/hooks/session-end.sh index 7996ea5..7cd8526 100755 --- a/hooks/session-end.sh +++ b/hooks/session-end.sh @@ -38,6 +38,11 @@ fi # Read hook input (Claude Code passes event context via stdin) INPUT=$(cat 2>/dev/null || echo "{}") +# Update status cache — mark as saving while persist runs +CACHE_DIR="${TMPDIR:-/tmp}/zerodb-status" +mkdir -p "$CACHE_DIR" +echo '{"count": null, "state": "saving", "last_updated": "'"$(date -u +%Y-%m-%dT%H:%M:%SZ)"'"}' > "${CACHE_DIR}/status.json" + # Output the trigger payload for Claude to act on. # Claude Code's Stop hook output is surfaced to Claude, which will then # use the zerodb-memory-guide skill to run the actual memory extraction diff --git a/hooks/session-start.sh b/hooks/session-start.sh index 885fb45..29473a7 100755 --- a/hooks/session-start.sh +++ b/hooks/session-start.sh @@ -49,6 +49,11 @@ if git rev-parse --git-dir > /dev/null 2>&1; then fi fi +# Update status cache — mark as synced after recall completes +CACHE_DIR="${TMPDIR:-/tmp}/zerodb-status" +mkdir -p "$CACHE_DIR" +echo '{"count": null, "state": "synced", "last_updated": "'"$(date -u +%Y-%m-%dT%H:%M:%SZ)"'"}' > "${CACHE_DIR}/status.json" + # Output trigger payload. Claude will call zerodb_get_context and # zerodb_semantic_search via MCP, then inject memories as context. cat </dev/null || echo "?") + STATE=$(python3 -c "import json,sys; d=json.load(open('$CACHE_FILE')); print(d.get('state', 'synced'))" 2>/dev/null || echo "synced") + + case "$STATE" in + saving) + echo "ZeroDB: saving..." + ;; + synced) + if [ "$COUNT" = "0" ] || [ "$COUNT" = "None" ]; then + echo "ZeroDB: 0 memories" + else + echo "ZeroDB: $COUNT memories ✓" + fi + ;; + error) + echo "ZeroDB: offline" + ;; + *) + echo "ZeroDB: $COUNT memories" + ;; + esac +else + # No cache yet — first session, show ready state + echo "ZeroDB: ready" +fi