Skip to content

Commit 17f53ed

Browse files
authored
Merge pull request #70 from snipcodeit/issue/58-template-generation-should-use-project-h
feat: inject project history context into extend-mode template generation
2 parents 1689f45 + bf0c8a9 commit 17f53ed

File tree

3 files changed

+333
-0
lines changed

3 files changed

+333
-0
lines changed

.claude/commands/mgw/project.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,46 @@ fi
106106
# Prefix: default v1
107107
PREFIX="v1"
108108
```
109+
110+
**In extend mode, load existing metadata and ask for new milestones:**
111+
112+
When `EXTEND_MODE=true`, skip the questions above and instead:
113+
114+
```bash
115+
if [ "$EXTEND_MODE" = true ]; then
116+
# Load existing project metadata — name, repo, stack, prefix are already known
117+
PROJECT_NAME=$(python3 -c "import json; print(json.load(open('${REPO_ROOT}/.mgw/project.json'))['project']['name'])")
118+
STACK=$(python3 -c "import json; print(json.load(open('${REPO_ROOT}/.mgw/project.json'))['project'].get('stack','unknown'))")
119+
PREFIX=$(python3 -c "import json; print(json.load(open('${REPO_ROOT}/.mgw/project.json'))['project'].get('prefix','v1'))")
120+
EXISTING_MILESTONE_NAMES=$(python3 -c "import json; p=json.load(open('${REPO_ROOT}/.mgw/project.json')); print(', '.join(m['name'] for m in p['milestones']))")
121+
122+
# Assemble project history context for the template generator
123+
MILESTONE_HISTORY=$(python3 -c "
124+
import json
125+
p = json.load(open('${REPO_ROOT}/.mgw/project.json'))
126+
lines = []
127+
for m in p['milestones']:
128+
lines.append(f\"Milestone: {m['name']}\")
129+
for i in m.get('issues', []):
130+
lines.append(f\" - {i['title']} ({i.get('pipeline_stage','unknown')})\")
131+
print('\n'.join(lines))
132+
")
133+
134+
GSD_DIGEST=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs history-digest 2>/dev/null || echo "")
135+
136+
HISTORY_CONTEXT="Previous milestones and issues built so far:
137+
${MILESTONE_HISTORY}
138+
139+
GSD build history (phases and decisions already made):
140+
${GSD_DIGEST:-No GSD history available.}"
141+
142+
# Ask only for the new work — different question for extend mode
143+
# Ask: "What new milestones should we add to ${PROJECT_NAME}?"
144+
# Capture as EXTENSION_DESCRIPTION
145+
146+
DESCRIPTION="Extension of existing project. Existing milestones: ${EXISTING_MILESTONE_NAMES}. New work: ${EXTENSION_DESCRIPTION}"
147+
fi
148+
```
109149
</step>
110150

111151
<step name="generate_template">
@@ -144,6 +184,13 @@ The project details for generation:
144184
- **Repo:** `$REPO`
145185
- **Prefix:** `$PREFIX`
146186

187+
<project_history>
188+
${HISTORY_CONTEXT:-No prior history available.}
189+
</project_history>
190+
191+
When in extend mode (HISTORY_CONTEXT is populated): do NOT suggest features or systems that already
192+
appear in the project history above. Build new milestones that complement and extend what exists.
193+
147194
After generating the JSON, extract it and write to a temp file:
148195

149196
```bash
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
---
2+
phase: quick-3
3+
plan: 01
4+
type: execute
5+
wave: 1
6+
depends_on: []
7+
files_modified:
8+
- commands/project.md
9+
- .claude/commands/mgw/project.md
10+
autonomous: true
11+
requirements:
12+
- ISSUE-58
13+
must_haves:
14+
truths:
15+
- "In extend mode, the template generator receives a <project_history> block listing previous milestone names, issue titles, and pipeline stages"
16+
- "In extend mode, the template generator receives a GSD history digest (if available) so it knows what was already built"
17+
- "Generated milestones build on existing architecture rather than re-suggesting completed work"
18+
artifacts:
19+
- path: "commands/project.md"
20+
provides: "Source-of-truth command — extend-mode gather_inputs step assembles HISTORY_CONTEXT"
21+
contains: "project_history"
22+
- path: ".claude/commands/mgw/project.md"
23+
provides: "Deployed command — identical change"
24+
contains: "project_history"
25+
key_links:
26+
- from: "gather_inputs extend-mode block"
27+
to: "generate_template AI prompt"
28+
via: "HISTORY_CONTEXT variable injected as <project_history> block"
29+
pattern: "HISTORY_CONTEXT"
30+
---
31+
32+
<objective>
33+
Inject project history context into the `generate_template` step when mgw:project runs in extend mode,
34+
so the AI template generator knows what milestones, issues, and systems already exist.
35+
36+
Purpose: Prevents the generator from suggesting features already built in previous milestones,
37+
and ensures new milestones build on existing architecture decisions.
38+
39+
Output: Updated `commands/project.md` and `.claude/commands/mgw/project.md` with history
40+
assembly and `<project_history>` injection added to the extend-mode section of `gather_inputs`.
41+
</objective>
42+
43+
<execution_context>
44+
@/home/hat/.claude/get-shit-done/workflows/execute-plan.md
45+
</execution_context>
46+
47+
<context>
48+
## Pattern to copy: mgw:issue history injection
49+
50+
From `commands/issue.md` (spawn_analysis step), the established pattern is:
51+
52+
```bash
53+
# Gather GSD project history for context (if available):
54+
HISTORY=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs history-digest 2>/dev/null || echo "")
55+
```
56+
57+
Then inject into the AI prompt as:
58+
```
59+
<project_history>
60+
${HISTORY}
61+
</project_history>
62+
```
63+
64+
## Where to add it in project.md
65+
66+
The change goes inside the `gather_inputs` step's `EXTEND_MODE=true` block, after loading
67+
existing metadata (PROJECT_NAME, STACK, PREFIX, EXISTING_MILESTONE_NAMES) and before
68+
assembling the final DESCRIPTION variable. This new block assembles `HISTORY_CONTEXT` and
69+
is later injected into the `generate_template` step's AI prompt.
70+
71+
### Current extend-mode block (lines ~130-148 in commands/project.md):
72+
73+
```bash
74+
if [ "$EXTEND_MODE" = true ]; then
75+
PROJECT_NAME=$(python3 ...)
76+
STACK=$(python3 ...)
77+
PREFIX=$(python3 ...)
78+
EXISTING_MILESTONE_NAMES=$(python3 ...)
79+
80+
# Ask only for the new work — different question for extend mode
81+
# Ask: "What new milestones should we add to ${PROJECT_NAME}?"
82+
# Capture as EXTENSION_DESCRIPTION
83+
84+
DESCRIPTION="Extension of existing project. Existing milestones: ${EXISTING_MILESTONE_NAMES}. New work: ${EXTENSION_DESCRIPTION}"
85+
fi
86+
```
87+
88+
### After the change, extend-mode block becomes:
89+
90+
```bash
91+
if [ "$EXTEND_MODE" = true ]; then
92+
PROJECT_NAME=$(python3 ...)
93+
STACK=$(python3 ...)
94+
PREFIX=$(python3 ...)
95+
EXISTING_MILESTONE_NAMES=$(python3 ...)
96+
97+
# Assemble project history context for the template generator
98+
MILESTONE_HISTORY=$(python3 -c "
99+
import json
100+
p = json.load(open('${REPO_ROOT}/.mgw/project.json'))
101+
lines = []
102+
for m in p['milestones']:
103+
lines.append(f\"Milestone: {m['name']}\")
104+
for i in m.get('issues', []):
105+
lines.append(f\" - {i['title']} ({i.get('pipeline_stage','unknown')})\")
106+
print('\n'.join(lines))
107+
")
108+
109+
GSD_DIGEST=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs history-digest 2>/dev/null || echo "")
110+
111+
HISTORY_CONTEXT="Previous milestones and issues built so far:
112+
${MILESTONE_HISTORY}
113+
114+
GSD build history (phases and decisions already made):
115+
${GSD_DIGEST:-No GSD history available.}"
116+
117+
# Ask only for the new work — different question for extend mode
118+
# Ask: "What new milestones should we add to ${PROJECT_NAME}?"
119+
# Capture as EXTENSION_DESCRIPTION
120+
121+
DESCRIPTION="Extension of existing project. Existing milestones: ${EXISTING_MILESTONE_NAMES}. New work: ${EXTENSION_DESCRIPTION}"
122+
fi
123+
```
124+
125+
### generate_template step: inject HISTORY_CONTEXT into the AI prompt
126+
127+
In the `generate_template` step, the project details block that currently reads:
128+
129+
```
130+
The project details for generation:
131+
- **Project name:** `$PROJECT_NAME`
132+
- **Description:** `$DESCRIPTION`
133+
- **Stack:** `$STACK`
134+
- **Repo:** `$REPO`
135+
- **Prefix:** `$PREFIX`
136+
```
137+
138+
Becomes (add the history block after the project details — only rendered in extend mode):
139+
140+
```
141+
The project details for generation:
142+
- **Project name:** `$PROJECT_NAME`
143+
- **Description:** `$DESCRIPTION`
144+
- **Stack:** `$STACK`
145+
- **Repo:** `$REPO`
146+
- **Prefix:** `$PREFIX`
147+
148+
<project_history>
149+
${HISTORY_CONTEXT:-No prior history available.}
150+
</project_history>
151+
152+
When in extend mode (HISTORY_CONTEXT is populated): do NOT suggest features or systems that already
153+
appear in the project history above. Build new milestones that complement and extend what exists.
154+
```
155+
156+
`HISTORY_CONTEXT` is only set when `EXTEND_MODE=true`, so the block gracefully falls back to
157+
"No prior history available." in normal (non-extend) mode — no conditional needed.
158+
</context>
159+
160+
<tasks>
161+
162+
<task type="auto">
163+
<name>Task 1: Add history assembly to extend-mode block and inject into generate_template prompt</name>
164+
<files>
165+
commands/project.md
166+
.claude/commands/mgw/project.md
167+
</files>
168+
<action>
169+
Make two targeted edits to `commands/project.md` (source of truth):
170+
171+
**Edit 1: gather_inputs step — add HISTORY_CONTEXT assembly inside the EXTEND_MODE block**
172+
173+
Find the line:
174+
```
175+
DESCRIPTION="Extension of existing project. Existing milestones: ${EXISTING_MILESTONE_NAMES}. New work: ${EXTENSION_DESCRIPTION}"
176+
```
177+
178+
Insert the following block immediately BEFORE that line (after EXISTING_MILESTONE_NAMES is set and before DESCRIPTION is assembled):
179+
180+
```bash
181+
# Assemble project history context for the template generator
182+
MILESTONE_HISTORY=$(python3 -c "
183+
import json
184+
p = json.load(open('${REPO_ROOT}/.mgw/project.json'))
185+
lines = []
186+
for m in p['milestones']:
187+
lines.append(f\"Milestone: {m['name']}\")
188+
for i in m.get('issues', []):
189+
lines.append(f\" - {i['title']} ({i.get('pipeline_stage','unknown')})\")
190+
print('\n'.join(lines))
191+
")
192+
193+
GSD_DIGEST=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs history-digest 2>/dev/null || echo "")
194+
195+
HISTORY_CONTEXT="Previous milestones and issues built so far:
196+
${MILESTONE_HISTORY}
197+
198+
GSD build history (phases and decisions already made):
199+
${GSD_DIGEST:-No GSD history available.}"
200+
```
201+
202+
**Edit 2: generate_template step — inject HISTORY_CONTEXT into the AI prompt**
203+
204+
Find the block that ends with:
205+
```
206+
- **Prefix:** `$PREFIX`
207+
```
208+
(just before "After generating the JSON, extract it and write to a temp file:")
209+
210+
Append after `- **Prefix:** \`$PREFIX\``:
211+
212+
```
213+
<project_history>
214+
${HISTORY_CONTEXT:-No prior history available.}
215+
</project_history>
216+
217+
When in extend mode (HISTORY_CONTEXT is populated): do NOT suggest features or systems that already
218+
appear in the project history above. Build new milestones that complement and extend what exists.
219+
```
220+
221+
Then apply the IDENTICAL edits to `.claude/commands/mgw/project.md`.
222+
223+
Note: `.claude/commands/mgw/project.md` is an older version — apply the two targeted edits
224+
to its equivalent locations (same step names: `gather_inputs` extend-mode block and
225+
`generate_template` project details block). The exact line numbers may differ from the source file.
226+
</action>
227+
<verify>
228+
<automated>grep -n "HISTORY_CONTEXT" /hd1/repos/mgw/.worktrees/issue/58-template-generation-should-use-project-h/commands/project.md && grep -n "HISTORY_CONTEXT" /hd1/repos/mgw/.worktrees/issue/58-template-generation-should-use-project-h/.claude/commands/mgw/project.md && grep -n "project_history" /hd1/repos/mgw/.worktrees/issue/58-template-generation-should-use-project-h/commands/project.md && grep -n "project_history" /hd1/repos/mgw/.worktrees/issue/58-template-generation-should-use-project-h/.claude/commands/mgw/project.md</automated>
229+
</verify>
230+
<done>
231+
Both files contain HISTORY_CONTEXT assembly (MILESTONE_HISTORY + GSD_DIGEST) in the extend-mode block,
232+
and both contain a &lt;project_history&gt; injection in the generate_template prompt.
233+
</done>
234+
</task>
235+
236+
</tasks>
237+
238+
<verification>
239+
After task completion:
240+
1. `grep -c "HISTORY_CONTEXT" commands/project.md` returns >= 3 (set, used in HISTORY_CONTEXT=, and referenced in prompt)
241+
2. `grep -c "HISTORY_CONTEXT" .claude/commands/mgw/project.md` returns >= 3
242+
3. `grep "project_history" commands/project.md` shows the XML tag in the generate_template section
243+
4. `grep "project_history" .claude/commands/mgw/project.md` shows the XML tag in the generate_template section
244+
5. `grep "MILESTONE_HISTORY" commands/project.md` confirms the python3 block that reads project.json milestones
245+
6. `grep "history-digest" commands/project.md` confirms the gsd-tools call
246+
</verification>
247+
248+
<success_criteria>
249+
- extend mode assembles MILESTONE_HISTORY from project.json (milestone names + issue titles + pipeline stages)
250+
- extend mode calls gsd-tools history-digest for GSD artifact context
251+
- both are combined into HISTORY_CONTEXT variable
252+
- HISTORY_CONTEXT is injected as &lt;project_history&gt; block in the generate_template AI prompt
253+
- template generator receives explicit instruction not to re-suggest already-built features
254+
- changes applied identically to both commands/project.md and .claude/commands/mgw/project.md
255+
</success_criteria>
256+
257+
<output>
258+
No SUMMARY.md required for quick plans. Changes go directly to the two command files.
259+
</output>

commands/project.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,26 @@ if [ "$EXTEND_MODE" = true ]; then
139139
PREFIX=$(python3 -c "import json; print(json.load(open('${REPO_ROOT}/.mgw/project.json'))['project'].get('prefix','v1'))")
140140
EXISTING_MILESTONE_NAMES=$(python3 -c "import json; p=json.load(open('${REPO_ROOT}/.mgw/project.json')); print(', '.join(m['name'] for m in p['milestones']))")
141141

142+
# Assemble project history context for the template generator
143+
MILESTONE_HISTORY=$(python3 -c "
144+
import json
145+
p = json.load(open('${REPO_ROOT}/.mgw/project.json'))
146+
lines = []
147+
for m in p['milestones']:
148+
lines.append(f\"Milestone: {m['name']}\")
149+
for i in m.get('issues', []):
150+
lines.append(f\" - {i['title']} ({i.get('pipeline_stage','unknown')})\")
151+
print('\n'.join(lines))
152+
")
153+
154+
GSD_DIGEST=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs history-digest 2>/dev/null || echo "")
155+
156+
HISTORY_CONTEXT="Previous milestones and issues built so far:
157+
${MILESTONE_HISTORY}
158+
159+
GSD build history (phases and decisions already made):
160+
${GSD_DIGEST:-No GSD history available.}"
161+
142162
# Ask only for the new work — different question for extend mode
143163
# Ask: "What new milestones should we add to ${PROJECT_NAME}?"
144164
# Capture as EXTENSION_DESCRIPTION
@@ -184,6 +204,13 @@ The project details for generation:
184204
- **Repo:** `$REPO`
185205
- **Prefix:** `$PREFIX`
186206

207+
<project_history>
208+
${HISTORY_CONTEXT:-No prior history available.}
209+
</project_history>
210+
211+
When in extend mode (HISTORY_CONTEXT is populated): do NOT suggest features or systems that already
212+
appear in the project history above. Build new milestones that complement and extend what exists.
213+
187214
After generating the JSON, extract it and write to a temp file:
188215

189216
```bash

0 commit comments

Comments
 (0)