Skip to content

Commit 171fc72

Browse files
author
SIN-Agent
committed
fix: pcpm-after-run hook PROJECT_ID + Box-Storage auto-upload (conditional)
1 parent 11df8c5 commit 171fc72

1 file changed

Lines changed: 37 additions & 3 deletions

File tree

.opencode/hooks/pcpm-after-run.sh

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
# Extracts knowledge from the completed session transcript and
44
# writes it back into the persistent brain stores.
55
# ALSO runs sin-brain auto-sync to keep global and local brain in sync.
6+
# ALSO optionally uploads session artifacts to Box.com
67

78
BRAIN_CLI="/Users/jeremy/dev/global-brain/src/cli.js"
89
BRAIN_ROOT="/Users/jeremy/dev/global-brain"
9-
PROJECT_ID="opensin-docs"
10+
PROJECT_ID="OpenSIN-documentation"
1011
SESSION_ID="session-$(date +%s)"
12+
LOG_DIR="/Users/jeremy/Library/Logs/com.sin.global-brain-sync"
13+
BOX_UPLOAD_ENABLED="${BOX_STORAGE_ENABLED:-false}"
14+
15+
# Ensure log directory exists
16+
mkdir -p "$LOG_DIR"
1117

1218
# Extract knowledge from the session transcript (runs LLM extraction)
1319
node "$BRAIN_CLI" extract-knowledge \
@@ -22,7 +28,7 @@ if [ -n "$PROJECT_ROOT" ]; then
2228
--root "$BRAIN_ROOT" \
2329
--project "$PROJECT_ID" \
2430
--project-root "$PROJECT_ROOT" \
25-
2>/dev/null
31+
2>/dev/null
2632
fi
2733

2834
# SIN-BRAIN: Auto-sync after every chat turn — no manual intervention needed
@@ -31,4 +37,32 @@ node "$BRAIN_CLI" sync-chat-turn 2>/dev/null
3137
# SIN-BRAIN: Check if new rules were discovered and add them to global brain
3238
echo "[SIN-BRAIN] Auto-sync complete after chat turn."
3339

34-
echo "PCPM_AFTERRUN_COMPLETE=true"
40+
# Box-Storage: Upload session artifacts if enabled
41+
if [ "$BOX_UPLOAD_ENABLED" = "true" ] && [ -n "$BOX_STORAGE_API_KEY" ]; then
42+
ARTIFACT_FILE="/tmp/pcpm-artifact-${PROJECT_ID}-$(date +%Y%m%d-%H%M%S).tar.gz"
43+
ARTIFACT_LOG="$LOG_DIR/box-upload-$(date +%Y-%m-%d).log"
44+
45+
# Gather artifacts to upload
46+
(
47+
cd /Users/jeremy/dev/OpenSIN-documentation 2>/dev/null || exit 0
48+
tar -czf "$ARTIFACT_FILE" \
49+
.pcpm/active-context.json \
50+
.pcpm/knowledge-summary.json \
51+
.pcpm/rules.md \
52+
2>/dev/null
53+
)
54+
55+
if [ -f "$ARTIFACT_FILE" ] && [ -s "$ARTIFACT_FILE" ]; then
56+
UPLOAD_RESULT=$(curl -s --connect-timeout 10 \
57+
-X POST "http://room-09-box-storage:3000/api/v1/upload" \
58+
-H "X-Box-Storage-Key: $BOX_STORAGE_API_KEY" \
59+
-F "folder_id=${BOX_CACHE_FOLDER_ID:-376701205578}" \
60+
-F "file=@${ARTIFACT_FILE}" \
61+
2>&1)
62+
63+
echo "[$(date '+%Y-%m-%dT%H-%M-%S')] Box-Storage upload: $UPLOAD_RESULT" >> "$ARTIFACT_LOG" 2>/dev/null
64+
rm -f "$ARTIFACT_FILE"
65+
fi
66+
fi
67+
68+
echo "PCPM_AFTERRUN_COMPLETE=true"

0 commit comments

Comments
 (0)