Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Structured planning workflow that uses files to track tasks, decisions, and project progress.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/resolve-plan-dir.sh
1#!/bin/sh2# planning-with-files: resolve active plan directory.3#4# Resolution order:5# 1. $PLAN_ID env var → ./.planning/$PLAN_ID/ if exists6# 2. ./.planning/.active_plan content → matching dir if exists7# 3. Newest ./.planning/<dir>/ by mtime8# 4. Otherwise empty stdout (caller falls back to legacy ./task_plan.md)9#10# Always exits 0. Never errors out the agent loop.11#12# Usage:13# PLAN_DIR="$(sh scripts/resolve-plan-dir.sh)"14# PLAN_FILE="${PLAN_DIR:+$PLAN_DIR/}task_plan.md"1516set -u1718PLAN_ROOT="${1:-${PWD}/.planning}"19ACTIVE_FILE="${PLAN_ROOT}/.active_plan"2021resolve_from_env() {22plan_id="${PLAN_ID:-}"23[ -z "${plan_id}" ] && return 124candidate="${PLAN_ROOT}/${plan_id}"25if [ -d "${candidate}" ]; then26printf "%s\n" "${candidate}"27return 028fi29return 130}3132resolve_from_active_file() {33[ -f "${ACTIVE_FILE}" ] || return 134plan_id="$(tr -d '\r\n' < "${ACTIVE_FILE}")"35[ -z "${plan_id}" ] && return 136candidate="${PLAN_ROOT}/${plan_id}"37if [ -d "${candidate}" ]; then38printf "%s\n" "${candidate}"39return 040fi41return 142}4344resolve_latest_dir() {45[ -d "${PLAN_ROOT}" ] || return 146# Portable newest-mtime selector. Avoid `ls -t` BSD/GNU drift.47# Only consider dirs that contain task_plan.md — skips system dirs like sessions/.48latest=""49latest_mtime=050for entry in "${PLAN_ROOT}"/*/; do51[ -d "${entry}" ] || continue52# Strip trailing slash53clean="${entry%/}"54# Skip hidden dirs55case "$(basename "${clean}")" in56.*) continue ;;57esac58# Skip dirs that are not plan dirs59[ -f "${clean}/task_plan.md" ] || continue60mtime="$(date -r "${clean}" +%s 2>/dev/null || stat -c '%Y' "${clean}" 2>/dev/null || echo 0)"61if [ "${mtime}" -gt "${latest_mtime}" ] 2>/dev/null; then62latest_mtime="${mtime}"63latest="${clean}"64fi65done66if [ -n "${latest}" ]; then67printf "%s\n" "${latest}"68return 069fi70return 171}7273if resolve_from_env; then exit 0; fi74if resolve_from_active_file; then exit 0; fi75if resolve_latest_dir; then exit 0; fi76exit 077