64 lines
2.5 KiB
Bash
Executable File
64 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# plan-info.sh — resolve the current Claude Code session id and suggest where to
|
|
# write a plan file for the `plan` skill.
|
|
#
|
|
# Prints (shell-eval friendly `KEY=value` lines + a human hint):
|
|
# SESSION_ID the current conversation's session id (for the frontmatter)
|
|
# SLUG the (sanitized) slug
|
|
# DATE today's date, UTC
|
|
# PLAN_REL data/plans/<date>-<slug>.md (repo-relative — Write to this)
|
|
# PLAN_ABS absolute path to the same file
|
|
# VIEWER_URL <hub>/plugins/plans/plans/<date>-<slug> — <hub> is $AIA_HUB_URL
|
|
# (e.g. https://ai-agent.example.com); unset, a path on the hub
|
|
#
|
|
# Best-effort: never fails its caller.
|
|
#
|
|
# Usage: bash <this skill's dir>/scripts/plan-info.sh <slug>
|
|
set -uo pipefail
|
|
|
|
SLUG_RAW="${1:-plan}"
|
|
# sanitize: lowercase, spaces/underscores → dashes, strip anything else.
|
|
SLUG="$(printf '%s' "$SLUG_RAW" | tr '[:upper:]' '[:lower:]' \
|
|
| sed -E 's/[ _]+/-/g; s/[^a-z0-9-]//g; s/-+/-/g; s/^-|-$//g')"
|
|
[[ -z "$SLUG" ]] && SLUG="plan"
|
|
|
|
DATE="$(date -u +%Y-%m-%d)"
|
|
NAME="$DATE-$SLUG"
|
|
|
|
# Resolve the active session id (env override, else newest transcript under
|
|
# $PWD's encoded project dir — Claude replaces every '/' with '-').
|
|
SESSION="${CLAUDE_SESSION_ID:-}"
|
|
if [[ -z "$SESSION" ]]; then
|
|
enc="$(pwd | sed 's#/#-#g')"
|
|
# any Claude account's tree (~/.claude, the work seat's ~/.claude-work):
|
|
# the hub repo's finder when this machine has it, else the newest by hand.
|
|
finder="$HOME/homelab/.claude/skills/_shared/find-transcript.sh"
|
|
if [[ -f "$finder" ]]; then
|
|
f="$(bash "$finder" --newest "$enc")" || true
|
|
else
|
|
f="$(ls -t "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/projects/$enc"/*.jsonl \
|
|
"$HOME/.claude/projects/$enc"/*.jsonl 2>/dev/null | head -1)" || true
|
|
fi
|
|
[[ -n "$f" ]] && SESSION="$(basename "$f" .jsonl)"
|
|
fi
|
|
|
|
# Plans must land in the CANONICAL checkout's data/plans — that's the tree the
|
|
# ai-agent container mounts (a git worktree's data/ is gitignored + separate, so
|
|
# a plan written there would never show up in the viewer). Default to ~/homelab,
|
|
# overridable with $HOMELAB_ROOT.
|
|
ROOT="${HOMELAB_ROOT:-$HOME/homelab}"
|
|
PLAN_REL="data/plans/$NAME.md"
|
|
PLAN_ABS="$ROOT/$PLAN_REL"
|
|
|
|
printf 'SESSION_ID=%s\n' "$SESSION"
|
|
printf 'SLUG=%s\n' "$NAME"
|
|
printf 'DATE=%s\n' "$DATE"
|
|
printf 'PLAN_REL=%s\n' "$PLAN_REL"
|
|
printf 'PLAN_ABS=%s\n' "$PLAN_ABS"
|
|
HUB_URL="${AIA_HUB_URL:-}"
|
|
printf 'VIEWER_URL=%s\n' "${HUB_URL%/}/plugins/plans/plans/$NAME"
|
|
printf '\n# Write the plan (with the Write tool) to: %s\n' "$PLAN_ABS"
|
|
printf '# then present the summary + viewer URL.\n'
|
|
exit 0
|