mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-02 03:35:09 +02:00
feat: session timeline binaries (gstack-timeline-log + gstack-timeline-read)
New binaries for the Session Intelligence Layer. gstack-timeline-log appends JSONL events to ~/.gstack/projects/$SLUG/timeline.jsonl. gstack-timeline-read reads, filters, and formats timeline data for /retro consumption. Timeline is local-only project intelligence, never sent anywhere. Always-on regardless of telemetry setting. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/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"
|
||||
Executable
+94
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env bash
|
||||
# gstack-timeline-read — read and format project timeline
|
||||
# Usage: gstack-timeline-read [--since "7 days ago"] [--limit N] [--branch NAME]
|
||||
#
|
||||
# Session timeline: local-only, never sent anywhere.
|
||||
# Reads ~/.gstack/projects/$SLUG/timeline.jsonl, filters, formats.
|
||||
# Exit 0 silently if no timeline file exists.
|
||||
set -euo pipefail
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
eval "$("$SCRIPT_DIR/gstack-slug" 2>/dev/null)"
|
||||
GSTACK_HOME="${GSTACK_HOME:-$HOME/.gstack}"
|
||||
|
||||
SINCE=""
|
||||
LIMIT=20
|
||||
BRANCH=""
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--since) SINCE="$2"; shift 2 ;;
|
||||
--limit) LIMIT="$2"; shift 2 ;;
|
||||
--branch) BRANCH="$2"; shift 2 ;;
|
||||
*) shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
TIMELINE_FILE="$GSTACK_HOME/projects/$SLUG/timeline.jsonl"
|
||||
|
||||
if [ ! -f "$TIMELINE_FILE" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
cat "$TIMELINE_FILE" 2>/dev/null | bun -e "
|
||||
const lines = (await Bun.stdin.text()).trim().split('\n').filter(Boolean);
|
||||
const since = '${SINCE}';
|
||||
const branch = '${BRANCH}';
|
||||
const limit = ${LIMIT};
|
||||
|
||||
let sinceMs = 0;
|
||||
if (since) {
|
||||
// Parse relative time like '7 days ago'
|
||||
const match = since.match(/(\d+)\s*(day|hour|minute|week|month)s?\s*ago/i);
|
||||
if (match) {
|
||||
const n = parseInt(match[1]);
|
||||
const unit = match[2].toLowerCase();
|
||||
const ms = { minute: 60000, hour: 3600000, day: 86400000, week: 604800000, month: 2592000000 };
|
||||
sinceMs = Date.now() - n * (ms[unit] || 86400000);
|
||||
}
|
||||
}
|
||||
|
||||
const entries = [];
|
||||
for (const line of lines) {
|
||||
try {
|
||||
const e = JSON.parse(line);
|
||||
if (sinceMs && new Date(e.ts).getTime() < sinceMs) continue;
|
||||
if (branch && e.branch !== branch) continue;
|
||||
entries.push(e);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
if (entries.length === 0) process.exit(0);
|
||||
|
||||
// Take last N entries
|
||||
const recent = entries.slice(-limit);
|
||||
|
||||
// Skill counts (completed events only)
|
||||
const counts = {};
|
||||
const branches = new Set();
|
||||
for (const e of entries) {
|
||||
if (e.event === 'completed') {
|
||||
counts[e.skill] = (counts[e.skill] || 0) + 1;
|
||||
}
|
||||
if (e.branch) branches.add(e.branch);
|
||||
}
|
||||
|
||||
// Output summary
|
||||
const countStr = Object.entries(counts)
|
||||
.sort((a, b) => b[1] - a[1])
|
||||
.map(([s, n]) => n + ' /' + s)
|
||||
.join(', ');
|
||||
|
||||
if (countStr) {
|
||||
console.log('TIMELINE: ' + countStr + ' across ' + branches.size + ' branch' + (branches.size !== 1 ? 'es' : ''));
|
||||
}
|
||||
|
||||
// Output recent events
|
||||
console.log('');
|
||||
console.log('## Recent Events');
|
||||
for (const e of recent) {
|
||||
const ts = (e.ts || '').replace('T', ' ').replace(/\.\d+Z$/, 'Z');
|
||||
const dur = e.duration_s ? ' (' + e.duration_s + 's)' : '';
|
||||
const outcome = e.outcome ? ' [' + e.outcome + ']' : '';
|
||||
console.log('- ' + ts + ' /' + e.skill + ' ' + e.event + outcome + dur + (e.branch ? ' on ' + e.branch : ''));
|
||||
}
|
||||
" 2>/dev/null || exit 0
|
||||
Reference in New Issue
Block a user