feat: add --include flag to init commands to eliminate redundant file reads
Workflows were calling init commands to get parsed JSON metadata, then immediately reading the same files again with cat to pass raw content to agents. This wastes context tokens. Changes: - Add --include flag to init execute-phase, plan-phase, and progress - Support includes: state, config, roadmap, requirements, context, research, verification, uat, project - Update plan-phase.md to use --include (removes 6 cat calls) - Update execute-phase.md to use --include (removes 2 cat calls) - Update execute-plan.md to use --include (removes 2 cat calls) - Update progress.md to use --include (removes 4 cat calls) - Add 7 tests for --include functionality Token savings: ~5,000-10,000 tokens per plan-phase execution, ~1,500-3,000 per other workflow executions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,14 +13,16 @@ Read STATE.md before any operation to load project context.
|
||||
<process>
|
||||
|
||||
<step name="initialize" priority="first">
|
||||
Load all context in one call:
|
||||
Load all context in one call (include file contents to avoid redundant reads):
|
||||
|
||||
```bash
|
||||
INIT=$(node ~/.claude/get-shit-done/bin/gsd-tools.js init execute-phase "${PHASE_ARG}")
|
||||
INIT=$(node ~/.claude/get-shit-done/bin/gsd-tools.js init execute-phase "${PHASE_ARG}" --include state,config)
|
||||
```
|
||||
|
||||
Parse JSON for: `executor_model`, `verifier_model`, `commit_docs`, `parallelization`, `branching_strategy`, `branch_name`, `phase_found`, `phase_dir`, `phase_number`, `phase_name`, `phase_slug`, `plans`, `incomplete_plans`, `plan_count`, `incomplete_count`, `state_exists`, `roadmap_exists`.
|
||||
|
||||
**File contents (from --include):** `state_content`, `config_content`. These are null if files don't exist.
|
||||
|
||||
**If `phase_found` is false:** Error — phase directory not found.
|
||||
**If `plan_count` is 0:** Error — no plans found in phase.
|
||||
**If `state_exists` is false but `.planning/` exists:** Offer reconstruct or continue.
|
||||
@@ -97,11 +99,13 @@ Execute each wave in sequence. Within a wave: parallel if `PARALLELIZATION=true`
|
||||
2. **Read files and spawn agents:**
|
||||
|
||||
Content must be inlined — `@` syntax doesn't work across Task() boundaries.
|
||||
STATE and CONFIG are already loaded via `--include` in initialize step.
|
||||
|
||||
```bash
|
||||
PLAN_CONTENT=$(cat "{plan_path}")
|
||||
STATE_CONTENT=$(cat .planning/STATE.md)
|
||||
CONFIG_CONTENT=$(cat .planning/config.json 2>/dev/null)
|
||||
# Use state_content and config_content from INIT (no need to re-read)
|
||||
STATE_CONTENT=$(echo "$INIT" | jq -r '.state_content // empty')
|
||||
CONFIG_CONTENT=$(echo "$INIT" | jq -r '.config_content // empty')
|
||||
```
|
||||
|
||||
Each agent prompt:
|
||||
|
||||
@@ -12,17 +12,18 @@ Read config.json for planning behavior settings.
|
||||
<process>
|
||||
|
||||
<step name="init_context" priority="first">
|
||||
Load execution context (uses `init execute-phase` for full context):
|
||||
Load execution context (uses `init execute-phase` for full context, including file contents):
|
||||
|
||||
```bash
|
||||
INIT=$(node ~/.claude/get-shit-done/bin/gsd-tools.js init execute-phase "${PHASE}")
|
||||
INIT=$(node ~/.claude/get-shit-done/bin/gsd-tools.js init execute-phase "${PHASE}" --include state,config)
|
||||
```
|
||||
|
||||
Extract from init JSON: `executor_model`, `commit_docs`, `phase_dir`, `phase_number`, `plans`, `summaries`, `incomplete_plans`.
|
||||
|
||||
Also read STATE.md for current position, decisions, blockers:
|
||||
**File contents (from --include):** `state_content`, `config_content`. Access with:
|
||||
```bash
|
||||
cat .planning/STATE.md 2>/dev/null
|
||||
STATE_CONTENT=$(echo "$INIT" | jq -r '.state_content // empty')
|
||||
CONFIG_CONTENT=$(echo "$INIT" | jq -r '.config_content // empty')
|
||||
```
|
||||
|
||||
If `.planning/` missing: error.
|
||||
@@ -30,7 +31,7 @@ If `.planning/` missing: error.
|
||||
|
||||
<step name="identify_plan">
|
||||
```bash
|
||||
cat .planning/ROADMAP.md
|
||||
# Use plans/summaries from INIT JSON, or list files
|
||||
ls .planning/phases/XX-name/*-PLAN.md 2>/dev/null | sort
|
||||
ls .planning/phases/XX-name/*-SUMMARY.md 2>/dev/null | sort
|
||||
```
|
||||
@@ -39,7 +40,7 @@ Find first PLAN without matching SUMMARY. Decimal phases supported (`01.1-hotfix
|
||||
|
||||
```bash
|
||||
PHASE=$(echo "$PLAN_PATH" | grep -oE '[0-9]+(\.[0-9]+)?-[0-9]+')
|
||||
cat .planning/config.json 2>/dev/null
|
||||
# config_content already loaded via --include config in init_context
|
||||
```
|
||||
|
||||
<if mode="yolo">
|
||||
|
||||
@@ -12,14 +12,16 @@ Read all files referenced by the invoking prompt's execution_context before star
|
||||
|
||||
## 1. Initialize
|
||||
|
||||
Load all context in one call:
|
||||
Load all context in one call (include file contents to avoid redundant reads):
|
||||
|
||||
```bash
|
||||
INIT=$(node ~/.claude/get-shit-done/bin/gsd-tools.js init plan-phase "$PHASE")
|
||||
INIT=$(node ~/.claude/get-shit-done/bin/gsd-tools.js init plan-phase "$PHASE" --include state,roadmap,requirements,context,research,verification,uat)
|
||||
```
|
||||
|
||||
Parse JSON for: `researcher_model`, `planner_model`, `checker_model`, `research_enabled`, `plan_checker_enabled`, `commit_docs`, `phase_found`, `phase_dir`, `phase_number`, `phase_name`, `phase_slug`, `padded_phase`, `has_research`, `has_context`, `has_plans`, `plan_count`, `planning_exists`, `roadmap_exists`.
|
||||
|
||||
**File contents (from --include):** `state_content`, `roadmap_content`, `requirements_content`, `context_content`, `research_content`, `verification_content`, `uat_content`. These are null if files don't exist.
|
||||
|
||||
**If `planning_exists` is false:** Error — run `/gsd:new-project` first.
|
||||
|
||||
## 2. Parse and Normalize Arguments
|
||||
@@ -45,13 +47,11 @@ PHASE_INFO=$(node ~/.claude/get-shit-done/bin/gsd-tools.js roadmap get-phase "${
|
||||
|
||||
## 4. Load CONTEXT.md
|
||||
|
||||
```bash
|
||||
CONTEXT_CONTENT=$(cat "${PHASE_DIR}"/*-CONTEXT.md 2>/dev/null)
|
||||
```
|
||||
Use `context_content` from init JSON (already loaded via `--include context`).
|
||||
|
||||
**CRITICAL:** Store `CONTEXT_CONTENT` now — pass to researcher, planner, checker, and revision agents.
|
||||
**CRITICAL:** Use `context_content` from INIT — pass to researcher, planner, checker, and revision agents.
|
||||
|
||||
If CONTEXT.md exists, display: `Using phase context from: ${PHASE_DIR}/*-CONTEXT.md`
|
||||
If `context_content` is not null, display: `Using phase context from: ${PHASE_DIR}/*-CONTEXT.md`
|
||||
|
||||
## 5. Handle Research
|
||||
|
||||
@@ -74,7 +74,8 @@ Display banner:
|
||||
|
||||
```bash
|
||||
PHASE_DESC=$(node ~/.claude/get-shit-done/bin/gsd-tools.js roadmap get-phase "${PHASE}" | jq -r '.section')
|
||||
REQUIREMENTS=$(cat .planning/REQUIREMENTS.md 2>/dev/null | grep -A100 "## Requirements" | head -50)
|
||||
# Use requirements_content from INIT (already loaded via --include requirements)
|
||||
REQUIREMENTS=$(echo "$INIT" | jq -r '.requirements_content // empty' | grep -A100 "## Requirements" | head -50)
|
||||
STATE_SNAP=$(node ~/.claude/get-shit-done/bin/gsd-tools.js state-snapshot)
|
||||
# Extract decisions from state-snapshot JSON: jq '.decisions[] | "\(.phase): \(.summary) - \(.rationale)"'
|
||||
```
|
||||
@@ -129,17 +130,19 @@ ls "${PHASE_DIR}"/*-PLAN.md 2>/dev/null
|
||||
|
||||
**If exists:** Offer: 1) Add more plans, 2) View existing, 3) Replan from scratch.
|
||||
|
||||
## 7. Read Context Files
|
||||
## 7. Use Context Files from INIT
|
||||
|
||||
Read and store for planner agent (`@` syntax doesn't work across Task() boundaries):
|
||||
All file contents are already loaded via `--include` in step 1 (`@` syntax doesn't work across Task() boundaries):
|
||||
|
||||
```bash
|
||||
STATE_CONTENT=$(cat .planning/STATE.md)
|
||||
ROADMAP_CONTENT=$(cat .planning/ROADMAP.md)
|
||||
REQUIREMENTS_CONTENT=$(cat .planning/REQUIREMENTS.md 2>/dev/null)
|
||||
RESEARCH_CONTENT=$(cat "${PHASE_DIR}"/*-RESEARCH.md 2>/dev/null)
|
||||
VERIFICATION_CONTENT=$(cat "${PHASE_DIR}"/*-VERIFICATION.md 2>/dev/null)
|
||||
UAT_CONTENT=$(cat "${PHASE_DIR}"/*-UAT.md 2>/dev/null)
|
||||
# Extract from INIT JSON (no need to re-read files)
|
||||
STATE_CONTENT=$(echo "$INIT" | jq -r '.state_content // empty')
|
||||
ROADMAP_CONTENT=$(echo "$INIT" | jq -r '.roadmap_content // empty')
|
||||
REQUIREMENTS_CONTENT=$(echo "$INIT" | jq -r '.requirements_content // empty')
|
||||
RESEARCH_CONTENT=$(echo "$INIT" | jq -r '.research_content // empty')
|
||||
VERIFICATION_CONTENT=$(echo "$INIT" | jq -r '.verification_content // empty')
|
||||
UAT_CONTENT=$(echo "$INIT" | jq -r '.uat_content // empty')
|
||||
CONTEXT_CONTENT=$(echo "$INIT" | jq -r '.context_content // empty')
|
||||
```
|
||||
|
||||
## 8. Spawn gsd-planner Agent
|
||||
|
||||
@@ -9,14 +9,16 @@ Read all files referenced by the invoking prompt's execution_context before star
|
||||
<process>
|
||||
|
||||
<step name="init_context">
|
||||
**Load progress context:**
|
||||
**Load progress context (with file contents to avoid redundant reads):**
|
||||
|
||||
```bash
|
||||
INIT=$(node ~/.claude/get-shit-done/bin/gsd-tools.js init progress)
|
||||
INIT=$(node ~/.claude/get-shit-done/bin/gsd-tools.js init progress --include state,roadmap,project,config)
|
||||
```
|
||||
|
||||
Extract from init JSON: `project_exists`, `roadmap_exists`, `state_exists`, `phases`, `current_phase`, `next_phase`, `milestone_version`, `completed_count`, `phase_count`, `paused_at`.
|
||||
|
||||
**File contents (from --include):** `state_content`, `roadmap_content`, `project_content`, `config_content`. These are null if files don't exist.
|
||||
|
||||
If `project_exists` is false (no `.planning/` directory):
|
||||
|
||||
```
|
||||
@@ -37,13 +39,16 @@ If missing both ROADMAP.md and PROJECT.md: suggest `/gsd:new-project`.
|
||||
</step>
|
||||
|
||||
<step name="load">
|
||||
**Load full project context:**
|
||||
**Use project context from INIT:**
|
||||
|
||||
- Read `.planning/STATE.md` for living memory (position, decisions, issues)
|
||||
- Read `.planning/ROADMAP.md` for phase structure and objectives
|
||||
- Read `.planning/PROJECT.md` for current state (What This Is, Core Value, Requirements)
|
||||
- Read `.planning/config.json` for settings (model_profile, workflow toggles)
|
||||
</step>
|
||||
All file contents are already loaded via `--include` in init_context step:
|
||||
- `state_content` — living memory (position, decisions, issues)
|
||||
- `roadmap_content` — phase structure and objectives
|
||||
- `project_content` — current state (What This Is, Core Value, Requirements)
|
||||
- `config_content` — settings (model_profile, workflow toggles)
|
||||
|
||||
No additional file reads needed.
|
||||
</step>
|
||||
|
||||
<step name="recent">
|
||||
**Gather recent work context:**
|
||||
|
||||
Reference in New Issue
Block a user