Files
agent-skills/bin/hourlog-session.sh
T
naps62 e4ffd5d93d feat: hourlog skill + Friday timer
Turns Claude Code and Codex session activity into a half-day-per-project
proposal, reconciles it against the timesheet API, and submits only what
the user approves in-session.

Activity is measured in 5-minute active slots, deduplicated per project,
not message counts — otherwise one overnight autonomous run outweighs a
real morning's work.

The path-to-project mapping and the API credentials stay in
~/.config/hourlog/ and ~/.env.claude. This repo is public.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-14 17:35:24 +00:00

63 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Friday hour-logging session: create it in Agent of Empires, prompt it with
# /hourlog, ping the phone. Interactive, not `-p`: the run stops for approval
# before writing to the timesheet. See README "Hour log timer".
set -euo pipefail
PROMPT="${HOURLOG_PROMPT:-/hourlog --week this}"
TOPIC="${HOURLOG_NTFY_TOPIC:-homelab}"
AOE="${HOURLOG_AOE:-$HOME/.local/bin/aoe}"
LOG="$HOME/.local/state/hourlog/run.log"
WEEK="$(date +%G-W%V)"
TITLE="hourlog-$WEEK"
mkdir -p "$(dirname "$LOG")"
exec >>"$LOG" 2>&1
echo "=== $(date -Is) starting $TITLE ==="
# NTFY_URL/NTFY_TOKEN and HOURLOG_API/HOURLOG_TOKEN live here; ~/.zshrc only
# sources it for interactive shells.
# shellcheck disable=SC1091
[ -f "$HOME/.env.claude" ] && . "$HOME/.env.claude"
notify() { # notify <title> <priority> <message>
[ -n "${NTFY_URL:-}" ] || { echo "no NTFY_URL, skipping notify"; return 0; }
curl -sS -m 10 -o /dev/null \
-H "Authorization: Bearer ${NTFY_TOKEN:-}" \
-H "Title: $1" -H "Priority: $2" -H "Tags: hourglass_flowing_sand" \
-d "$3" "$NTFY_URL/$TOPIC" || echo "notify failed"
}
if [ -z "${HOURLOG_TOKEN:-}" ] || [ -z "${HOURLOG_API:-}" ]; then
echo "HOURLOG_API/HOURLOG_TOKEN missing from ~/.env.claude"
notify "Hour log not configured" high \
"HOURLOG_API/HOURLOG_TOKEN missing — the session would stall at setup."
exit 1
fi
open="$("$AOE" list 2>/dev/null | awk '$1 ~ /^hourlog-/ { print $1 }' || true)"
if [ -n "$open" ]; then
echo "already open: $open — not starting a second one"
notify "Hour log skipped" default \
"An earlier hour log is still open ($open). Finish or remove it."
exit 0
fi
# --scratch keeps the session's cwd under the agent-of-empires app dir, which
# the hourlog config excludes — otherwise it lands in next week's scan.
"$AOE" add --scratch --title "$TITLE" --cmd claude --yolo --trust-hooks
"$AOE" session start "$TITLE"
# The agent needs its TUI up before it can take a prompt; `send` into a
# still-booting pane is dropped silently.
sleep 25
if "$AOE" send "$TITLE" "$PROMPT"; then
echo "session $TITLE launched and prompted"
notify "Hour log ready" default "aoe: $TITLE — proposal waiting on your OK"
else
echo "failed to send prompt to $TITLE"
notify "Hour log failed to start" high "session $TITLE — see $LOG"
exit 1
fi