Init: Second Brain vault with dream-sync system
This commit is contained in:
Executable
+160
@@ -0,0 +1,160 @@
|
||||
#!/bin/bash
|
||||
# Dream Sync: Extended thinking pass over vault
|
||||
# Reads second-brain vault, synthesizes insights, updates MEMORY.md
|
||||
# Can run: nightly, on-idle, or on-demand
|
||||
|
||||
set -e
|
||||
|
||||
# Load config
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "${SCRIPT_DIR}/.dreamrc"
|
||||
|
||||
# Create checkpoint directory if needed
|
||||
mkdir -p "$(dirname "$CHECKPOINT")"
|
||||
|
||||
# Color codes
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
log_info() {
|
||||
echo -e "${GREEN}[dream-sync]${NC} $1"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[dream-sync]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[dream-sync]${NC} $1"
|
||||
}
|
||||
|
||||
# Check if we should run
|
||||
check_should_run() {
|
||||
if [ ! -f "$CHECKPOINT" ]; then
|
||||
log_info "First run, proceeding..."
|
||||
return 0
|
||||
fi
|
||||
|
||||
local last_run=$(jq -r '.lastRun' "$CHECKPOINT" 2>/dev/null || echo "")
|
||||
if [ -z "$last_run" ]; then
|
||||
log_info "No last run recorded, proceeding..."
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Calculate time since last run (in minutes)
|
||||
local last_timestamp=$(date -d "$last_run" +%s 2>/dev/null || echo 0)
|
||||
local now=$(date +%s)
|
||||
local minutes_since=$((($now - $last_timestamp) / 60))
|
||||
|
||||
if [ $minutes_since -lt $MIN_HOURS_BETWEEN_DREAMS ]; then
|
||||
minutes_since=$((MIN_HOURS_BETWEEN_DREAMS * 60 - $minutes_since))
|
||||
log_warn "Last dream was recent, next eligible in ${minutes_since}m. Use --force to override."
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Main dream-sync process
|
||||
run_dream_sync() {
|
||||
log_info "Starting dream synthesis..."
|
||||
log_info "Reading vault from: $VAULT_PATH"
|
||||
|
||||
# Count files in vault
|
||||
local file_count=$(find "$VAULT_PATH" -type f -name "*.md" | wc -l)
|
||||
log_info "Found $file_count markdown files in vault"
|
||||
|
||||
# Create temporary synthesis file
|
||||
local synthesis_file="/tmp/dream-synthesis-$(date +%s).md"
|
||||
|
||||
cat > "$synthesis_file" << 'EOF'
|
||||
# Dream Synthesis Session
|
||||
|
||||
**Generated:** $(date -Iseconds)
|
||||
**Vault Files Scanned:** [file_count]
|
||||
|
||||
## Key Patterns Identified
|
||||
|
||||
This is where the extended thinking pass would analyze:
|
||||
- Recurring themes across projects
|
||||
- Connections between learnings
|
||||
- Architecture patterns
|
||||
- Team dynamics and lessons
|
||||
- Actionable insights from vault
|
||||
|
||||
## Vault Summary
|
||||
|
||||
### Projects Status
|
||||
(Summary of 02-projects/* status)
|
||||
|
||||
### Recent Learnings
|
||||
(Top insights from 03-learnings/*)
|
||||
|
||||
### Architecture Decisions
|
||||
(Summary of 04-architecture/*)
|
||||
|
||||
### Action Items
|
||||
(Extracted from daily notes and projects)
|
||||
|
||||
---
|
||||
|
||||
[[dream-synthesized]]
|
||||
EOF
|
||||
|
||||
log_info "Synthesis prepared: $synthesis_file"
|
||||
|
||||
# In a real implementation, we would:
|
||||
# 1. Read all vault files
|
||||
# 2. Generate extended thinking prompt
|
||||
# 3. Call Claude with /dream mode
|
||||
# 4. Parse results
|
||||
# 5. Update MEMORY.md with key insights
|
||||
|
||||
# For now, log the path
|
||||
log_info "Synthesis would be processed and indexed into MEMORY.md"
|
||||
echo "$synthesis_file"
|
||||
}
|
||||
|
||||
# Update checkpoint
|
||||
update_checkpoint() {
|
||||
local status=$1
|
||||
local result=$2
|
||||
|
||||
cat > "$CHECKPOINT" << EOF
|
||||
{
|
||||
"lastRun": "$(date -Iseconds)",
|
||||
"status": "$status",
|
||||
"result": "$result",
|
||||
"nextCheck": "$(date -Iseconds -d '+4 hours')",
|
||||
"fileCount": $(find "$VAULT_PATH" -type f -name "*.md" | wc -l)
|
||||
}
|
||||
EOF
|
||||
|
||||
log_info "Checkpoint updated: $status"
|
||||
}
|
||||
|
||||
# Main
|
||||
main() {
|
||||
local force=0
|
||||
if [ "$1" = "--force" ]; then
|
||||
force=1
|
||||
log_info "Force mode: ignoring time threshold"
|
||||
fi
|
||||
|
||||
if [ $force -eq 0 ] && ! check_should_run; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if run_dream_sync; then
|
||||
update_checkpoint "completed" "Dream synthesis completed successfully"
|
||||
log_info "Dream synthesis complete ✨"
|
||||
else
|
||||
update_checkpoint "error" "Dream synthesis failed"
|
||||
log_error "Dream synthesis failed"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user