@snipcodeit/mgw 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,377 @@
1
+ <purpose>
2
+ Shared GSD agent spawn patterns for MGW commands. Every Task() spawn MUST use
3
+ these templates to ensure CLAUDE.md injection and consistent subagent configuration.
4
+ MGW delegates all code-touching work to GSD agents — this file defines how.
5
+ </purpose>
6
+
7
+ ## Mandatory Context Injection
8
+
9
+ Every Task() spawn from an MGW command MUST include project context in its prompt.
10
+ No exceptions. This ensures every subagent operates within the project's conventions,
11
+ security requirements, and coding standards.
12
+
13
+ **Copy this block into every Task() prompt:**
14
+
15
+ ```markdown
16
+ <files_to_read>
17
+ - ./CLAUDE.md (Project instructions — if exists, follow all guidelines)
18
+ - .agents/skills/ (Project skills — if dir exists, list skills, read SKILL.md for each, follow relevant rules)
19
+ </files_to_read>
20
+ ```
21
+
22
+ This block MUST appear at the START of the Task() prompt, before any agent-specific content.
23
+
24
+ ## Standard Task() Spawn Template
25
+
26
+ All GSD agent spawns MUST use Task() with explicit subagent_type. Never use Skill
27
+ invocation or inline execution.
28
+
29
+ ```
30
+ Task(
31
+ prompt="
32
+ <files_to_read>
33
+ - ./CLAUDE.md (Project instructions — if exists, follow all guidelines)
34
+ - .agents/skills/ (Project skills — if dir exists, list skills, read SKILL.md for each, follow relevant rules)
35
+ {additional files specific to this agent}
36
+ </files_to_read>
37
+
38
+ {agent-specific prompt here}
39
+ ",
40
+ subagent_type="{type}",
41
+ model="{resolved_model}",
42
+ description="{short description}"
43
+ )
44
+ ```
45
+
46
+ ## Model Resolution
47
+
48
+ Resolve model strings before spawning agents. Never hardcode model names.
49
+
50
+ ```bash
51
+ PLANNER_MODEL=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs resolve-model gsd-planner --raw)
52
+ EXECUTOR_MODEL=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs resolve-model gsd-executor --raw)
53
+ VERIFIER_MODEL=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs resolve-model gsd-verifier --raw)
54
+ CHECKER_MODEL=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs resolve-model gsd-plan-checker --raw)
55
+ ```
56
+
57
+ ## Valid subagent_types
58
+
59
+ | Type | Use For | Example |
60
+ |------|---------|---------|
61
+ | `gsd-planner` | Planning agents that create PLAN.md files | Issue-to-plan in /mgw:run |
62
+ | `gsd-executor` | Agents that write application code | Plan task execution |
63
+ | `gsd-verifier` | Post-execution verification agents | Goal achievement checks |
64
+ | `gsd-plan-checker` | Plan quality review agents | Plan structure and coverage review |
65
+ | `general-purpose` | Utility agents (no code execution) | Comments, PR body, analysis, triage, comment classification |
66
+
67
+ ## Comment Classification Pattern
68
+
69
+ Used by `/mgw:run` (pre-flight check) and `/mgw:review` (standalone) to classify
70
+ new comments as material, informational, or blocking.
71
+
72
+ ```
73
+ Task(
74
+ prompt="
75
+ <files_to_read>
76
+ - ./CLAUDE.md (Project instructions — if exists, follow all guidelines)
77
+ </files_to_read>
78
+
79
+ Classify new comments on GitHub issue #${ISSUE_NUMBER}.
80
+
81
+ <issue_context>
82
+ Title: ${issue_title}
83
+ Current pipeline stage: ${pipeline_stage}
84
+ GSD Route: ${gsd_route}
85
+ Triage scope: ${triage.scope}
86
+ </issue_context>
87
+
88
+ <new_comments>
89
+ ${NEW_COMMENTS}
90
+ </new_comments>
91
+
92
+ <classification_rules>
93
+ - material — changes scope, requirements, acceptance criteria, or design
94
+ - informational — status update, acknowledgment, question, +1
95
+ - blocking — explicit instruction to stop or wait
96
+
97
+ Priority: blocking > material > informational
98
+ </classification_rules>
99
+
100
+ <output_format>
101
+ Return ONLY valid JSON with: classification, reasoning, new_requirements, blocking_reason
102
+ </output_format>
103
+ ",
104
+ subagent_type="general-purpose",
105
+ description="Classify comments on #${ISSUE_NUMBER}"
106
+ )
107
+ ```
108
+
109
+ ## GSD Quick Pipeline Pattern
110
+
111
+ Used by `/mgw:run` for small/medium issues (gsd:quick and gsd:quick --full routes).
112
+
113
+ ```bash
114
+ # 1. Init quick task
115
+ INIT=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs init quick "$DESCRIPTION")
116
+ # Parse: planner_model, executor_model, checker_model, verifier_model,
117
+ # next_num, slug, date, quick_dir, task_dir, roadmap_exists
118
+
119
+ # 2. Handle missing .planning/ (quick tasks in non-GSD repos)
120
+ # MGW never writes config.json, ROADMAP.md, or STATE.md — those are GSD-owned.
121
+ # Only create the quick task directory (GSD agents need it).
122
+ if [ "$roadmap_exists" = "false" ]; then
123
+ echo "NOTE: No .planning/ directory found. GSD manages its own state files."
124
+ echo " To create a ROADMAP.md, run /gsd:new-milestone after this pipeline."
125
+ mkdir -p .planning/quick
126
+ fi
127
+
128
+ # 3. Create task directory
129
+ QUICK_DIR=".planning/quick/${next_num}-${slug}"
130
+ mkdir -p "$QUICK_DIR"
131
+
132
+ # 4. Spawn planner → (if --full) checker → executor → (if --full) verifier
133
+ # See run.md for full spawn sequence with templates
134
+ ```
135
+
136
+ ## GSD Milestone Pipeline Pattern
137
+
138
+ Used by `/mgw:run` for large issues (gsd:new-milestone route) and `/mgw:milestone` for
139
+ milestone-level orchestration. This is the full lifecycle — each phase goes through
140
+ plan -> execute -> verify before moving to the next.
141
+
142
+ ```bash
143
+ # 1. Init milestone
144
+ MILESTONE_INIT=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs init new-milestone 2>/dev/null)
145
+
146
+ # 2. Create ROADMAP (autonomous from issue data, or interactive fallback)
147
+ # Spawn roadmapper agent -> user confirmation checkpoint -> proceed
148
+
149
+ # 3. Resolve models
150
+ PLANNER_MODEL=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs resolve-model gsd-planner --raw)
151
+ EXECUTOR_MODEL=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs resolve-model gsd-executor --raw)
152
+ VERIFIER_MODEL=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs resolve-model gsd-verifier --raw)
153
+
154
+ # 4. Discover phases from ROADMAP
155
+ ROADMAP_ANALYSIS=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs roadmap analyze)
156
+ # Extract: phase list with numbers, names, slugs
157
+
158
+ # 5. Per-phase lifecycle loop:
159
+ # for each phase:
160
+ # a. Init phase and create directory
161
+ PHASE_INIT=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs init plan-phase "${PHASE_NUM}")
162
+ mkdir -p "${phase_dir}"
163
+
164
+ # b. Spawn planner (gsd-planner) -> creates PLAN.md files
165
+ # Task(subagent_type="gsd-planner", ...)
166
+
167
+ # c. Init execute-phase
168
+ EXEC_INIT=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs init execute-phase "${PHASE_NUM}")
169
+
170
+ # d. Spawn executor (gsd-executor) -> creates SUMMARY.md files
171
+ # Task(subagent_type="gsd-executor", ...)
172
+
173
+ # e. Spawn verifier (gsd-verifier) -> creates VERIFICATION.md
174
+ # Task(subagent_type="gsd-verifier", ...)
175
+
176
+ # f. Post phase-complete comment on issue
177
+ # gh issue comment ...
178
+
179
+ # 6. Complete milestone (archive phases, clean ROADMAP, tag release)
180
+ # Called from milestone.md post_loop when all issues finish
181
+ # Follows gsd:complete-milestone workflow
182
+ ```
183
+
184
+ **Artifacts created per phase:**
185
+ ```
186
+ .planning/phases/{NN}-{slug}/
187
+ {phase}-{plan}-PLAN.md (from planner)
188
+ {phase}-{plan}-SUMMARY.md (from executor)
189
+ {phase}-VERIFICATION.md (from verifier)
190
+ ```
191
+
192
+ **Artifacts created on milestone completion:**
193
+ ```
194
+ .planning/milestones/
195
+ v{X.Y}-ROADMAP.md (archived roadmap)
196
+ v{X.Y}-REQUIREMENTS.md (archived requirements)
197
+ ```
198
+
199
+ ## GSD Debug Pipeline Pattern
200
+
201
+ Used by `/mgw:run` when triage recommends `gsd:diagnose-issues`. This route investigates
202
+ a bug's root cause before planning a fix. It is a two-step process: diagnose, then fix.
203
+
204
+ The GSD debug workflow is `diagnose-issues.md` -- it spawns parallel debug agents per
205
+ symptom/gap, each investigating autonomously, returning root causes.
206
+
207
+ ```bash
208
+ # 1. Gather symptoms from the issue body
209
+ # Extract: what's broken, error messages, reproduction steps, expected vs actual
210
+
211
+ # 2. Create debug directory
212
+ mkdir -p .planning/debug
213
+
214
+ # 3. Spawn diagnosis agent
215
+ Task(
216
+ prompt="
217
+ <files_to_read>
218
+ - ./CLAUDE.md (Project instructions -- if exists, follow all guidelines)
219
+ - .planning/STATE.md (if exists)
220
+ </files_to_read>
221
+
222
+ Diagnose the root cause of this bug.
223
+
224
+ <issue>
225
+ Title: ${issue_title}
226
+ Body: ${issue_body}
227
+ </issue>
228
+
229
+ <instructions>
230
+ Read the GSD diagnose-issues workflow for your process:
231
+ @~/.claude/get-shit-done/workflows/diagnose-issues.md
232
+
233
+ Create a debug session file at .planning/debug/${slug}.md
234
+ Investigate the codebase to find the root cause.
235
+ Return: root cause, evidence, files involved, suggested fix direction.
236
+ </instructions>
237
+ ",
238
+ subagent_type="general-purpose",
239
+ description="Diagnose bug: ${issue_title}"
240
+ )
241
+
242
+ # 4. After diagnosis, route to quick fix
243
+ # Read the debug session file for root cause
244
+ # If root cause found: spawn gsd:quick executor with the root cause as context
245
+ # If inconclusive: report to user, suggest manual investigation
246
+ ```
247
+
248
+ **Artifacts created:**
249
+ ```
250
+ .planning/debug/
251
+ {slug}.md (debug session with root cause)
252
+ ```
253
+
254
+ After diagnosis, the pipeline continues to the quick execution flow (task 3 in the
255
+ existing Quick Pipeline Pattern) with the root cause informing the plan.
256
+
257
+ ## Utility Patterns
258
+
259
+ GSD tools used by MGW for common operations.
260
+
261
+ ### Slug Generation
262
+ ```bash
263
+ SLUG=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs generate-slug "${title}" --raw)
264
+ SLUG="${SLUG:0:40}" # MGW enforces 40-char limit
265
+ ```
266
+
267
+ ### Timestamps
268
+ ```bash
269
+ TIMESTAMP=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs current-timestamp --raw)
270
+ ```
271
+
272
+ ### Progress Display
273
+ ```bash
274
+ PROGRESS=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs progress bar --raw 2>/dev/null || echo "")
275
+ PROGRESS_TABLE=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs progress table --raw 2>/dev/null || echo "")
276
+ ```
277
+
278
+ ### Summary Extraction
279
+ ```bash
280
+ # Structured extraction (returns JSON with one_liner, key_files, tech_added, patterns, decisions)
281
+ SUMMARY_DATA=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs summary-extract "${path}" 2>/dev/null || echo '{}')
282
+
283
+ # Specific fields
284
+ ONE_LINER=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs summary-extract "${path}" --fields one_liner --raw 2>/dev/null || echo "")
285
+ ```
286
+
287
+ ### GSD History Context
288
+ ```bash
289
+ # Brief digest for providing project history to agents
290
+ HISTORY=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs history-digest 2>/dev/null || echo "")
291
+ ```
292
+
293
+ ### GSD Health Check
294
+ ```bash
295
+ # Read-only health validation
296
+ HEALTH=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs validate health 2>/dev/null || echo '{"status":"unknown"}')
297
+ ```
298
+
299
+ ### Commit via GSD
300
+ ```bash
301
+ node ~/.claude/get-shit-done/bin/gsd-tools.cjs commit "${message}" --files ${file_list}
302
+ ```
303
+
304
+ ### Plan Structure Verification
305
+ ```bash
306
+ # Pre-flight check for plan quality
307
+ PLAN_CHECK=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs verify plan-structure "${PLAN_PATH}")
308
+ ```
309
+
310
+ ### Summary Verification
311
+ ```bash
312
+ VERIFY_RESULT=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs verify-summary "${SUMMARY_PATH}")
313
+ ```
314
+
315
+ ### Post-Execution Artifact Checks
316
+ ```bash
317
+ # Non-blocking — include warnings in PR if issues found
318
+ ARTIFACT_CHECK=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs verify artifacts "${PLAN_PATH}" 2>/dev/null || echo '{"passed":true}')
319
+ KEYLINK_CHECK=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs verify key-links "${PLAN_PATH}" 2>/dev/null || echo '{"passed":true}')
320
+ ```
321
+
322
+ ## Question Classification Agent Pattern
323
+
324
+ Used by `/mgw:ask` to classify questions/observations during milestone execution.
325
+ Spawns a general-purpose agent with full project context — milestone, all issues,
326
+ active state, and recent git diff — to determine if a question is in-scope,
327
+ adjacent, separate, duplicate, or out-of-scope.
328
+
329
+ ```
330
+ Task(
331
+ prompt="
332
+ <files_to_read>
333
+ - ./CLAUDE.md (Project instructions — if exists, follow all guidelines)
334
+ - .agents/skills/ (Project skills — if dir exists, list skills, read SKILL.md for each, follow relevant rules)
335
+ </files_to_read>
336
+
337
+ You are a question classification agent for the MGW pipeline.
338
+
339
+ <question>${QUESTION}</question>
340
+ <current_milestone>${MILESTONE_CONTEXT}</current_milestone>
341
+ <milestone_issues>${ALL_ISSUES_CONTEXT}</milestone_issues>
342
+ <issue_bodies>${ISSUE_BODIES}</issue_bodies>
343
+ <active_work>${ACTIVE_STATE}</active_work>
344
+ <recent_changes>${RECENT_DIFF}</recent_changes>
345
+
346
+ Classify into: in-scope | adjacent | separate | duplicate | out-of-scope
347
+ Return: classification, analysis, related issue, recommendation.
348
+ ",
349
+ subagent_type="general-purpose",
350
+ description="Classify question: ${QUESTION}"
351
+ )
352
+ ```
353
+
354
+ The agent is read-only (general-purpose, no code execution). It reads project state
355
+ and codebase to classify, then MGW presents the result and offers follow-up actions
356
+ (file new issue, post comment on related issue, etc.).
357
+
358
+ ## Anti-Patterns
359
+
360
+ - **NEVER** use Skill invocation from within a Task() agent — Skills don't resolve inside subagents
361
+ - **NEVER** spawn a Task() without the mandatory CLAUDE.md injection block
362
+ - **NEVER** hardcode model strings (e.g., `model="sonnet"`) — always resolve via gsd-tools
363
+ - **NEVER** inline code execution in the MGW orchestrator — always spawn a Task() agent
364
+ - **NEVER** let MGW read application source code directly — spawn an analysis agent
365
+ - **NEVER** omit `subagent_type` from a Task() call — always specify the agent type
366
+
367
+ ## Consumers
368
+
369
+ | Pattern | Referenced By |
370
+ |---------|-------------|
371
+ | Standard spawn template | run.md, issue.md, pr.md, ask.md, review.md |
372
+ | Comment classification | run.md (pre-flight), review.md (standalone) |
373
+ | Quick pipeline | run.md |
374
+ | Milestone pipeline | run.md, milestone.md |
375
+ | Question classification | ask.md |
376
+ | Model resolution | run.md |
377
+ | Utility patterns | run.md, pr.md, issue.md, sync.md, link.md, update.md, ask.md |