Files
gstack/bin/gstack-timeline-log
T
Garry Tan fc7e9d3b89 feat: weekly activity index for cross-runtime diarization
Timeline-log now writes completed events to weekly rollup files at
~/.gstack/activity/activity-YYYY-WNN.jsonl. Wintermute answering
"what did I ship this week" reads one file, not 6 months of history.

Only completed events go to the activity index (not started events).
Old weeks are immutable. ls ~/.gstack/activity/ gives the full timeline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 22:10:19 -07:00

46 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# gstack-timeline-log — append a timeline event to the project timeline
# Usage: gstack-timeline-log '{"skill":"review","event":"started","branch":"main"}'
#
# Session timeline: local-only, never sent anywhere.
# Required fields: skill, event (started|completed).
# Optional: branch, outcome, duration_s, session, ts.
# Validation failure → skip silently (non-blocking).
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
eval "$("$SCRIPT_DIR/gstack-slug" 2>/dev/null)"
GSTACK_HOME="${GSTACK_HOME:-$HOME/.gstack}"
mkdir -p "$GSTACK_HOME/projects/$SLUG"
INPUT="$1"
# Validate: input must be parseable JSON with required fields
if ! printf '%s' "$INPUT" | bun -e "
const j = JSON.parse(await Bun.stdin.text());
if (!j.skill || !j.event) process.exit(1);
" 2>/dev/null; then
exit 0 # skip silently, non-blocking
fi
# Inject timestamp if not present
if ! printf '%s' "$INPUT" | bun -e "const j=JSON.parse(await Bun.stdin.text()); if(!j.ts) process.exit(1)" 2>/dev/null; then
INPUT=$(printf '%s' "$INPUT" | bun -e "
const j = JSON.parse(await Bun.stdin.text());
j.ts = new Date().toISOString();
console.log(JSON.stringify(j));
" 2>/dev/null) || true
fi
echo "$INPUT" >> "$GSTACK_HOME/projects/$SLUG/timeline.jsonl"
# Activity index: write to weekly rollup file for cross-runtime diarization
# Only log "completed" events to the activity index (not "started")
EVENT_TYPE=$(printf '%s' "$INPUT" | bun -e "const j=JSON.parse(await Bun.stdin.text()); console.log(j.event||'')" 2>/dev/null) || true
if [ "$EVENT_TYPE" = "completed" ]; then
ACTIVITY_DIR="$GSTACK_HOME/activity"
mkdir -p "$ACTIVITY_DIR"
# ISO week number: YYYY-WNN
WEEK_FILE="$ACTIVITY_DIR/activity-$(date +%G-W%V).jsonl"
echo "$INPUT" >> "$WEEK_FILE"
fi