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/init-session.sh
1#!/usr/bin/env bash2# Initialize planning files for a new session.3#4# Usage:5# ./init-session.sh # legacy: root-level task_plan.md, findings.md, progress.md6# ./init-session.sh [--template TYPE] # legacy with template choice7# ./init-session.sh "Backend Refactor" # slug mode: .planning/<date>-backend-refactor/8# ./init-session.sh --plan-dir # slug mode with auto-generated untitled-<short> name9# ./init-session.sh --plan-dir "Quick Spike" # slug mode, explicit slug10#11# Legacy mode (zero positional args, no --plan-dir) preserves v1.x behavior so12# upgrades stay non-breaking. Slug mode addresses parallel multi-task isolation13# (issue #148) by writing each plan under .planning/<date>-<slug>/ and pinning14# .planning/.active_plan so resolve-plan-dir.sh can find it.1516set -e1718TEMPLATE="default"19PROJECT_NAME=""20USE_PLAN_DIR=02122while [[ $# -gt 0 ]]; do23case "$1" in24--template|-t)25TEMPLATE="$2"26shift 227;;28--plan-dir)29USE_PLAN_DIR=130shift31;;32*)33if [ -z "$PROJECT_NAME" ]; then34PROJECT_NAME="$1"35else36PROJECT_NAME="$PROJECT_NAME $1"37fi38shift39;;40esac41done4243DATE=$(date +%Y-%m-%d)4445SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"46SKILL_ROOT="$(dirname "$SCRIPT_DIR")"47TEMPLATE_DIR="$SKILL_ROOT/templates"4849if [ "$TEMPLATE" != "default" ] && [ "$TEMPLATE" != "analytics" ]; then50echo "Unknown template: $TEMPLATE (available: default, analytics). Using default."51TEMPLATE="default"52fi5354# Slug mode triggers when a project name was given OR --plan-dir was passed.55SLUG_MODE=056if [ -n "$PROJECT_NAME" ] || [ "$USE_PLAN_DIR" -eq 1 ]; then57SLUG_MODE=158fi5960slugify() {61# Lowercase, non-alphanumerics → '-', collapse repeats, trim leading/trailing '-'62printf '%s' "$1" \63| tr '[:upper:]' '[:lower:]' \64| sed -e 's/[^a-z0-9]/-/g' -e 's/-\{2,\}/-/g' -e 's/^-//' -e 's/-$//' \65| cut -c1-4066}6768short_uuid() {69# Probe each candidate: command -v alone is not enough on Windows because70# App Execution Aliases report presence but exit non-zero when run.71_py="${PYTHON_BIN:-}"72if [ -z "$_py" ]; then73for _c in python3 python py; do74if command -v "$_c" >/dev/null 2>&1 && "$_c" -c "import uuid" >/dev/null 2>&1; then75_py="$_c"76break77fi78done79fi80if [ -n "$_py" ]; then81"$_py" -c "import uuid; print(uuid.uuid4().hex[:8])"82return83fi84if command -v uuidgen >/dev/null 2>&1; then85uuidgen | tr '[:upper:]' '[:lower:]' | tr -d '-' | cut -c1-886return87fi88# Last-ditch: seconds timestamp as 8 hex chars89printf '%08x' "$(date +%s)" | cut -c1-890}9192write_default_task_plan() {93cat > "$1" << 'EOF'94# Task Plan: [Brief Description]9596## Goal97[One sentence describing the end state]9899## Current Phase100Phase 1101102## Phases103104### Phase 1: Requirements & Discovery105- [ ] Understand user intent106- [ ] Identify constraints107- [ ] Document in findings.md108- **Status:** in_progress109110### Phase 2: Planning & Structure111- [ ] Define approach112- [ ] Create project structure113- **Status:** pending114115### Phase 3: Implementation116- [ ] Execute the plan117- [ ] Write to files before executing118- **Status:** pending119120### Phase 4: Testing & Verification121- [ ] Verify requirements met122- [ ] Document test results123- **Status:** pending124125### Phase 5: Delivery126- [ ] Review outputs127- [ ] Deliver to user128- **Status:** pending129130## Decisions Made131| Decision | Rationale |132|----------|-----------|133134## Errors Encountered135| Error | Resolution |136|-------|------------|137EOF138}139140write_default_findings() {141cat > "$1" << 'EOF'142# Findings & Decisions143144## Requirements145-146147## Research Findings148-149150## Technical Decisions151| Decision | Rationale |152|----------|-----------|153154## Issues Encountered155| Issue | Resolution |156|-------|------------|157158## Resources159-160EOF161}162163write_default_progress() {164local date_value="$1"165local target="$2"166cat > "$target" << EOF167# Progress Log168169## Session: $date_value170171### Current Status172- **Phase:** 1 - Requirements & Discovery173- **Started:** $date_value174175### Actions Taken176-177178### Test Results179| Test | Expected | Actual | Status |180|------|----------|--------|--------|181182### Errors183| Error | Resolution |184|-------|------------|185EOF186}187188write_analytics_progress() {189local date_value="$1"190local target="$2"191cat > "$target" << EOF192# Progress Log193194## Session: $date_value195196### Current Status197- **Phase:** 1 - Data Discovery198- **Started:** $date_value199200### Actions Taken201-202203### Query Log204| Query | Result Summary | Interpretation |205|-------|---------------|----------------|206207### Errors208| Error | Resolution |209|-------|------------|210EOF211}212213create_files_in() {214local target_dir="$1"215local plan_path="$target_dir/task_plan.md"216local findings_path="$target_dir/findings.md"217local progress_path="$target_dir/progress.md"218219if [ ! -f "$plan_path" ]; then220if [ "$TEMPLATE" = "analytics" ] && [ -f "$TEMPLATE_DIR/analytics_task_plan.md" ]; then221cp "$TEMPLATE_DIR/analytics_task_plan.md" "$plan_path"222else223write_default_task_plan "$plan_path"224fi225echo "Created $plan_path"226else227echo "$plan_path already exists, skipping"228fi229230if [ ! -f "$findings_path" ]; then231if [ "$TEMPLATE" = "analytics" ] && [ -f "$TEMPLATE_DIR/analytics_findings.md" ]; then232cp "$TEMPLATE_DIR/analytics_findings.md" "$findings_path"233else234write_default_findings "$findings_path"235fi236echo "Created $findings_path"237else238echo "$findings_path already exists, skipping"239fi240241if [ ! -f "$progress_path" ]; then242if [ "$TEMPLATE" = "analytics" ]; then243write_analytics_progress "$DATE" "$progress_path"244else245write_default_progress "$DATE" "$progress_path"246fi247echo "Created $progress_path"248else249echo "$progress_path already exists, skipping"250fi251}252253if [ "$SLUG_MODE" -eq 1 ]; then254SLUG="$(slugify "$PROJECT_NAME")"255if [ -z "$SLUG" ]; then256SLUG="untitled-$(short_uuid)"257fi258BASE_ID="${DATE}-${SLUG}"259PLAN_ID="$BASE_ID"260PLAN_ROOT="${PWD}/.planning"261counter=2262while [ -d "${PLAN_ROOT}/${PLAN_ID}" ]; do263PLAN_ID="${BASE_ID}-${counter}"264counter=$((counter + 1))265done266PLAN_DIR="${PLAN_ROOT}/${PLAN_ID}"267mkdir -p "$PLAN_DIR"268269echo "Initializing planning files for: ${PROJECT_NAME:-untitled} (template: $TEMPLATE)"270echo "PLAN_ID=$PLAN_ID"271create_files_in "$PLAN_DIR"272printf "%s\n" "$PLAN_ID" > "${PLAN_ROOT}/.active_plan"273echo ""274echo "Active plan recorded: ${PLAN_ROOT}/.active_plan"275echo "Pin this terminal to the plan for parallel sessions:"276echo " export PLAN_ID=$PLAN_ID"277else278PROJECT_NAME="${PROJECT_NAME:-project}"279echo "Initializing planning files for: $PROJECT_NAME (template: $TEMPLATE)"280create_files_in "$(pwd)"281echo ""282echo "Planning files initialized!"283echo "Files: task_plan.md, findings.md, progress.md"284fi285