@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,385 @@
1
+ <purpose>
2
+ Shared GitHub CLI patterns for all MGW commands. Commands reference these patterns
3
+ instead of inventing their own gh calls. Every gh command used by MGW should be
4
+ documented here with a copy-paste-ready bash snippet.
5
+ </purpose>
6
+
7
+ ## Issue Operations
8
+
9
+ ### Fetch Single Issue
10
+ Used when triaging or loading issue context.
11
+ ```bash
12
+ # Full issue data for triage/analysis
13
+ gh issue view $ISSUE_NUMBER --json number,title,body,labels,assignees,state,comments,url,milestone
14
+ ```
15
+
16
+ ### List Issues with Filters
17
+ Used by browse commands. Default: assigned to current user, open, limit 25.
18
+ ```bash
19
+ # Default: your open issues
20
+ gh issue list --assignee @me --state open --limit 25 --json number,title,labels,createdAt,comments,assignees
21
+
22
+ # With filters (replace as needed)
23
+ gh issue list --label "$LABEL" --milestone "$MILESTONE" --assignee "$USER" --state "$STATE" --limit 25 --json number,title,labels,createdAt,comments,assignees
24
+ ```
25
+
26
+ ### Check Issue State
27
+ Used by sync and staleness detection to check if an issue is still open.
28
+ ```bash
29
+ gh issue view ${NUMBER} --json state,closed -q '{state: .state, closed: .closed}'
30
+ ```
31
+
32
+ ### Check Issue Updated Timestamp
33
+ Used by staleness detection to compare GitHub state with local state.
34
+ ```bash
35
+ gh issue view ${ISSUE_NUMBER} --json updatedAt -q .updatedAt
36
+ ```
37
+
38
+ ### Get Comment Count
39
+ Used by comment tracking to get the current number of comments on an issue.
40
+ ```bash
41
+ gh issue view ${ISSUE_NUMBER} --json comments --jq '.comments | length'
42
+ ```
43
+
44
+ ### Get Recent Comments
45
+ Used by pre-flight comment check and review command to fetch new comments since triage.
46
+ ```bash
47
+ # Fetch last N comments with author, body, and timestamp
48
+ NEW_COUNT=$((CURRENT_COMMENTS - STORED_COMMENTS))
49
+ gh issue view ${ISSUE_NUMBER} --json comments \
50
+ --jq "[.comments[-${NEW_COUNT}:]] | .[] | {author: .author.login, body: .body, createdAt: .createdAt}"
51
+ ```
52
+
53
+ ### Get Last Comment Timestamp
54
+ Used during triage to snapshot the most recent comment timestamp.
55
+ ```bash
56
+ gh issue view ${ISSUE_NUMBER} --json comments \
57
+ --jq '.comments[-1].createdAt // empty'
58
+ ```
59
+
60
+ ## Issue Mutations
61
+
62
+ ### Assign to Self
63
+ Used when claiming an issue during triage.
64
+ ```bash
65
+ GH_USER=$(gh api user -q .login)
66
+ gh issue edit $ISSUE_NUMBER --add-assignee @me
67
+ ```
68
+
69
+ ### Post Issue Comment
70
+ Used for status updates, triage results, and pipeline notifications.
71
+ ```bash
72
+ gh issue comment ${ISSUE_NUMBER} --body "$COMMENT_BODY"
73
+ ```
74
+
75
+ ### Manage Labels
76
+ Used during repo initialization to ensure standard labels exist.
77
+ ```bash
78
+ # --force updates existing labels without error
79
+ gh label create "$LABEL_NAME" --description "$DESCRIPTION" --color "$HEX_COLOR" --force
80
+ ```
81
+
82
+ ## Label Lifecycle Operations
83
+
84
+ ### MGW Pipeline Labels
85
+ Seven labels for pipeline stage tracking. Created by init.md, managed by issue.md and run.md.
86
+
87
+ | Label | Color | Description |
88
+ |-------|-------|-------------|
89
+ | `mgw:triaged` | `0e8a16` | Issue triaged and ready for pipeline |
90
+ | `mgw:needs-info` | `e4e669` | Blocked — needs more detail or clarification |
91
+ | `mgw:needs-security-review` | `d93f0b` | Blocked — requires security review |
92
+ | `mgw:discussing` | `c5def5` | Under discussion — not yet approved |
93
+ | `mgw:approved` | `0e8a16` | Discussion complete — approved for execution |
94
+ | `mgw:in-progress` | `1d76db` | Pipeline actively executing |
95
+ | `mgw:blocked` | `b60205` | Pipeline blocked by stakeholder comment |
96
+
97
+ ### Remove MGW Labels and Apply New
98
+ Used when transitioning pipeline stages. Removes all `mgw:*` pipeline labels, then applies the target label.
99
+ ```bash
100
+ # Remove all mgw: pipeline labels from issue, then apply new one
101
+ remove_mgw_labels_and_apply() {
102
+ local ISSUE_NUMBER="$1"
103
+ local NEW_LABEL="$2"
104
+
105
+ # Get current labels
106
+ CURRENT_LABELS=$(gh issue view "$ISSUE_NUMBER" --json labels --jq '.labels[].name' 2>/dev/null)
107
+
108
+ # Remove any mgw: pipeline labels
109
+ for LABEL in $CURRENT_LABELS; do
110
+ case "$LABEL" in
111
+ mgw:triaged|mgw:needs-info|mgw:needs-security-review|mgw:discussing|mgw:approved|mgw:in-progress|mgw:blocked)
112
+ gh issue edit "$ISSUE_NUMBER" --remove-label "$LABEL" 2>/dev/null
113
+ ;;
114
+ esac
115
+ done
116
+
117
+ # Apply new label
118
+ if [ -n "$NEW_LABEL" ]; then
119
+ gh issue edit "$ISSUE_NUMBER" --add-label "$NEW_LABEL" 2>/dev/null
120
+ fi
121
+ }
122
+ ```
123
+
124
+ ## Triage Comment Templates
125
+
126
+ ### Gate Blocked Comment
127
+ Posted immediately during /mgw:issue when triage gates fail.
128
+ ```bash
129
+ GATE_BLOCKED_BODY=$(cat <<COMMENTEOF
130
+ > **MGW** . \`triage-blocked\` . ${TIMESTAMP}
131
+
132
+ ### Triage: Action Required
133
+
134
+ | Gate | Result |
135
+ |------|--------|
136
+ ${GATE_TABLE_ROWS}
137
+
138
+ **What's needed:**
139
+ ${MISSING_FIELDS_LIST}
140
+
141
+ Please update the issue with the required information, then re-run \`/mgw:issue ${ISSUE_NUMBER}\`.
142
+ COMMENTEOF
143
+ )
144
+ gh issue comment ${ISSUE_NUMBER} --body "$GATE_BLOCKED_BODY" 2>/dev/null || true
145
+ ```
146
+
147
+ ### Gate Passed Comment
148
+ Posted immediately during /mgw:issue when all triage gates pass.
149
+ ```bash
150
+ GATE_PASSED_BODY=$(cat <<COMMENTEOF
151
+ > **MGW** . \`triage-complete\` . ${TIMESTAMP}
152
+
153
+ ### Triage Complete
154
+
155
+ | | |
156
+ |---|---|
157
+ | **Scope** | ${SCOPE_SIZE} -- ${FILE_COUNT} files across ${SYSTEM_LIST} |
158
+ | **Validity** | ${VALIDITY} |
159
+ | **Security** | ${SECURITY_RISK} |
160
+ | **Route** | \`${gsd_route}\` -- ${ROUTE_REASONING} |
161
+ | **Gates** | All passed |
162
+
163
+ Ready for pipeline execution.
164
+ COMMENTEOF
165
+ )
166
+ gh issue comment ${ISSUE_NUMBER} --body "$GATE_PASSED_BODY" 2>/dev/null || true
167
+ ```
168
+
169
+ ### Scope Proposal Comment
170
+ Posted when new-milestone route triggers discussion phase.
171
+ ```bash
172
+ SCOPE_PROPOSAL_BODY=$(cat <<COMMENTEOF
173
+ > **MGW** . \`scope-proposal\` . ${TIMESTAMP}
174
+
175
+ ### Scope Proposal: Discussion Requested
176
+
177
+ This issue was triaged as **${SCOPE_SIZE}** scope requiring the \`new-milestone\` route.
178
+
179
+ **Proposed breakdown:**
180
+ ${SCOPE_BREAKDOWN}
181
+
182
+ **Estimated phases:** ${PHASE_COUNT}
183
+
184
+ Please review and confirm scope, or suggest changes. Once approved, run \`/mgw:run ${ISSUE_NUMBER}\` to begin execution.
185
+ COMMENTEOF
186
+ )
187
+ gh issue comment ${ISSUE_NUMBER} --body "$SCOPE_PROPOSAL_BODY" 2>/dev/null || true
188
+ ```
189
+
190
+ ## Milestone Operations
191
+
192
+ ### Create Milestone
193
+ Used when scaffolding a project structure from a template.
194
+ ```bash
195
+ # Create milestone and capture number + ID for subsequent operations
196
+ REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)
197
+ MILESTONE_JSON=$(gh api "repos/${REPO}/milestones" --method POST \
198
+ -f title="$MILESTONE_TITLE" \
199
+ -f description="$MILESTONE_DESCRIPTION" \
200
+ -f state="open")
201
+
202
+ # milestone.number: used for issue assignment (-F milestone=N)
203
+ # milestone.id: stored in project.json for cross-referencing
204
+ MILESTONE_NUMBER=$(echo "$MILESTONE_JSON" | python3 -c "import json,sys; print(json.load(sys.stdin)['number'])")
205
+ MILESTONE_ID=$(echo "$MILESTONE_JSON" | python3 -c "import json,sys; print(json.load(sys.stdin)['id'])")
206
+ MILESTONE_URL=$(echo "$MILESTONE_JSON" | python3 -c "import json,sys; print(json.load(sys.stdin)['html_url'])")
207
+ ```
208
+
209
+ Note: There is no native `gh milestone` subcommand. Always use `gh api repos/{owner}/{repo}/milestones`.
210
+
211
+ ### Create Issue with Milestone
212
+ Used when scaffolding issues from a template. Assigns to milestone in a single API call.
213
+ ```bash
214
+ # -F (not -f) for milestone — sends as integer, not string
215
+ ISSUE_JSON=$(gh api "repos/${REPO}/issues" --method POST \
216
+ -f title="$ISSUE_TITLE" \
217
+ -f body="$ISSUE_BODY" \
218
+ -F milestone="$MILESTONE_NUMBER" \
219
+ -f "labels[]=$LABEL1" \
220
+ -f "labels[]=$LABEL2")
221
+
222
+ ISSUE_NUMBER=$(echo "$ISSUE_JSON" | python3 -c "import json,sys; print(json.load(sys.stdin)['number'])")
223
+ ```
224
+
225
+ ### Create and Apply Dependency Labels
226
+ Used after all issues are created to apply blocked-by relationships.
227
+ Two-pass required: issue numbers are only known after creation.
228
+ ```bash
229
+ # Step 1: Create label (idempotent with --force)
230
+ gh label create "blocked-by:#${BLOCKING_ISSUE}" \
231
+ --description "Blocked by issue #${BLOCKING_ISSUE}" \
232
+ --color "e4e669" \
233
+ --force
234
+
235
+ # Step 2: Apply label to dependent issue
236
+ gh issue edit "${DEPENDENT_ISSUE}" --add-label "blocked-by:#${BLOCKING_ISSUE}"
237
+ ```
238
+
239
+ Note: `#` in label names works with `gh label create` and `gh issue edit --add-label`.
240
+ For API path access (e.g., deletion), URL-encode `#` as `%23`.
241
+
242
+ ### Create Phase Labels
243
+ Used during project init to create phase tracking labels.
244
+ ```bash
245
+ gh label create "phase:${PHASE_NUMBER}-${PHASE_SLUG}" \
246
+ --description "Phase ${PHASE_NUMBER}: ${PHASE_NAME}" \
247
+ --color "0075ca" \
248
+ --force
249
+ ```
250
+
251
+ ## PR Operations
252
+
253
+ ### Create PR
254
+ Used after GSD execution to open a pull request.
255
+ ```bash
256
+ DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef -q .defaultBranchRef.name)
257
+ gh pr create --title "$PR_TITLE" --base "$DEFAULT_BRANCH" --head "$BRANCH_NAME" --body "$PR_BODY"
258
+ ```
259
+
260
+ ### Post PR Comment
261
+ Used to add testing procedures or follow-up notes to a PR.
262
+ ```bash
263
+ gh pr comment ${PR_NUMBER} --body "$COMMENT_BODY"
264
+ ```
265
+
266
+ ### Check PR State
267
+ Used by sync to determine if a linked PR was merged or closed.
268
+ ```bash
269
+ gh pr view ${PR_NUMBER} --json state,mergedAt -q '{state: .state, mergedAt: .mergedAt}'
270
+ ```
271
+
272
+ ## Repo Metadata
273
+
274
+ ### Get Repo Name
275
+ Used for display and verification that we're in a GitHub repo.
276
+ ```bash
277
+ gh repo view --json nameWithOwner -q .nameWithOwner
278
+ ```
279
+
280
+ ### Get Default Branch
281
+ Used to determine the base branch for PRs and worktree creation.
282
+ ```bash
283
+ DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef -q .defaultBranchRef.name)
284
+ ```
285
+
286
+ ## User Identity
287
+
288
+ ### Get Current User
289
+ Used to check if current user is assigned to an issue.
290
+ ```bash
291
+ GH_USER=$(gh api user -q .login)
292
+ ```
293
+
294
+ ## Remote Operations
295
+
296
+ ### Check Remote Branch Exists
297
+ Used by sync to verify if a branch still exists on the remote.
298
+ ```bash
299
+ git ls-remote --heads origin ${BRANCH_NAME} | grep -q . && echo "remote" || echo "no-remote"
300
+ ```
301
+
302
+ ### Push Branch with Upstream
303
+ Used after GSD execution to push the feature branch for PR creation.
304
+ ```bash
305
+ git push -u origin ${BRANCH_NAME}
306
+ ```
307
+
308
+ ## Batch Operations (GraphQL)
309
+
310
+ ### Batch Issue Staleness Check
311
+ Used by staleness detection to check multiple issues in a single API call.
312
+ ```bash
313
+ OWNER=$(gh repo view --json owner -q .owner.login)
314
+ REPO=$(gh repo view --json name -q .name)
315
+
316
+ gh api graphql -f query='
317
+ query($owner: String!, $repo: String!) {
318
+ repository(owner: $owner, name: $repo) {
319
+ issues(first: 50, states: OPEN) {
320
+ nodes { number updatedAt }
321
+ }
322
+ }
323
+ }
324
+ ' -f owner="$OWNER" -f repo="$REPO" --jq '.data.repository.issues.nodes'
325
+ ```
326
+
327
+ ## Rate Limit
328
+
329
+ ### Check Rate Limit
330
+ Used before batch operations (milestone execution) to estimate available API calls.
331
+ ```bash
332
+ RATE_JSON=$(gh api rate_limit --jq '.resources.core')
333
+ REMAINING=$(echo "$RATE_JSON" | python3 -c "import json,sys; print(json.load(sys.stdin)['remaining'])")
334
+ LIMIT=$(echo "$RATE_JSON" | python3 -c "import json,sys; print(json.load(sys.stdin)['limit'])")
335
+ RESET_EPOCH=$(echo "$RATE_JSON" | python3 -c "import json,sys; print(json.load(sys.stdin)['reset'])")
336
+ RESET_TIME=$(date -d "@${RESET_EPOCH}" '+%H:%M:%S' 2>/dev/null || echo "unknown")
337
+ ```
338
+
339
+ Conservative estimate: ~25 API calls per `/mgw:run` invocation (triage + comments + PR creation).
340
+ If rate limit check fails (network error), log warning and proceed — never block on non-critical checks.
341
+
342
+ ### Close Milestone
343
+ Used after all issues in a milestone are complete.
344
+ ```bash
345
+ REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)
346
+ gh api "repos/${REPO}/milestones/${MILESTONE_NUMBER}" --method PATCH \
347
+ -f state="closed"
348
+ ```
349
+
350
+ Note: Uses same API path as Create Milestone but with PATCH method.
351
+
352
+ ## Release Operations
353
+
354
+ ### Create Draft Release
355
+ Used after milestone completion to create an auto-generated release summary.
356
+ ```bash
357
+ RELEASE_TAG="milestone-${MILESTONE_NUM}-complete"
358
+ gh release create "$RELEASE_TAG" --draft \
359
+ --title "Milestone ${MILESTONE_NUM}: ${MILESTONE_NAME}" \
360
+ --notes "$RELEASE_BODY"
361
+ ```
362
+
363
+ Tag format: `milestone-{N}-complete` (e.g., `milestone-1-complete`).
364
+ Release is created as draft — user reviews and publishes manually.
365
+
366
+ ## Consumers
367
+
368
+ | Section | Referenced By |
369
+ |---------|-------------|
370
+ | Issue Operations | issue.md, run.md, issues.md, sync.md, milestone.md, next.md, ask.md |
371
+ | Comment Operations | issue.md (triage snapshot), run.md (pre-flight check), sync.md (drift), review.md |
372
+ | Issue Mutations | issue.md, update.md, run.md, init.md, milestone.md, ask.md |
373
+ | Milestone Operations | project.md, milestone.md |
374
+ | Dependency Labels | project.md |
375
+ | Phase Labels | project.md |
376
+ | PR Operations | pr.md, run.md, sync.md |
377
+ | Repo Metadata | init.md, issues.md, run.md, pr.md, milestone.md |
378
+ | User Identity | issue.md |
379
+ | Remote Operations | sync.md, run.md |
380
+ | Batch Operations | state.md (staleness detection) |
381
+ | Rate Limit | milestone.md |
382
+ | Release Operations | milestone.md |
383
+ | Label Lifecycle | issue.md, run.md, init.md |
384
+ | Triage Comment Templates | issue.md |
385
+ | Scope Proposal Template | run.md (new-milestone discussion) |