chief-clancy 0.4.0 → 0.5.1

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.
@@ -1,3 +1,399 @@
1
- # Plan Workflow
1
+ # Clancy Plan Workflow
2
2
 
3
- > This workflow is a placeholder for v0.5.0. It is not yet implemented.
3
+ ## Overview
4
+
5
+ Fetch backlog tickets from the board, explore the codebase, and generate structured implementation plans. Plans are posted as comments on the ticket for human review. Does not implement anything — planning only.
6
+
7
+ ---
8
+
9
+ ## Step 1 — Preflight checks
10
+
11
+ 1. Check `.clancy/` exists and `.clancy/.env` is present. If not:
12
+ ```
13
+ .clancy/ not found. Run /clancy:init to set up Clancy first.
14
+ ```
15
+ Stop.
16
+
17
+ 2. Source `.clancy/.env` and check board credentials are present.
18
+
19
+ 3. Check `.clancy/docs/` — if the directory is empty or missing:
20
+ ```
21
+ ⚠️ No codebase documentation found in .clancy/docs/
22
+ Plans will be less accurate without codebase context.
23
+ Run /clancy:map-codebase first for better results.
24
+
25
+ Continue anyway? [y/N]
26
+ ```
27
+ If the user declines, stop. If they confirm, continue without docs context.
28
+
29
+ ---
30
+
31
+ ## Step 2 — Parse arguments
32
+
33
+ Parse the arguments passed to the command:
34
+
35
+ - **No argument:** plan 1 ticket
36
+ - **Numeric argument** (e.g. `/clancy:plan 3`): plan up to N tickets, cap at 10
37
+ - **`--force`:** re-plan tickets that already have a plan (reads feedback comments)
38
+ - Arguments can appear in any order (e.g. `/clancy:plan 3 --force` or `/clancy:plan --force 3`)
39
+
40
+ If N > 10: `Maximum batch size is 10. Planning 10 tickets.`
41
+
42
+ If N >= 5: display a confirmation:
43
+ ```
44
+ Planning {N} tickets — each requires codebase exploration. Continue? [Y/n]
45
+ ```
46
+
47
+ ---
48
+
49
+ ## Step 3 — Fetch backlog tickets
50
+
51
+ Detect board from `.clancy/.env` and fetch tickets from the **planning queue** (different from the implementation queue used by `/clancy:once`).
52
+
53
+ ### Jira
54
+
55
+ Build the JQL using planning-specific env vars:
56
+ - `CLANCY_PLAN_STATUS` defaults to `Backlog` if not set
57
+ - Sprint clause: include `AND sprint in openSprints()` if `CLANCY_JQL_SPRINT` is set
58
+ - Label clause: include `AND labels = "$CLANCY_LABEL"` if `CLANCY_LABEL` is set
59
+
60
+ Full JQL: `project=$JIRA_PROJECT_KEY [AND sprint in openSprints()] [AND labels = "$CLANCY_LABEL"] AND assignee=currentUser() AND status="$CLANCY_PLAN_STATUS" ORDER BY priority ASC`
61
+
62
+ ```bash
63
+ RESPONSE=$(curl -s \
64
+ -u "$JIRA_USER:$JIRA_API_TOKEN" \
65
+ -X POST \
66
+ -H "Content-Type: application/json" \
67
+ -H "Accept: application/json" \
68
+ "$JIRA_BASE_URL/rest/api/3/search/jql" \
69
+ -d '{"jql": "<jql as above>", "maxResults": <N>, "fields": ["summary", "description", "issuelinks", "parent", "customfield_10014", "comment"]}')
70
+ ```
71
+
72
+ Note: include the `comment` field so we can check for existing plans and read feedback.
73
+
74
+ ### GitHub Issues
75
+
76
+ ```bash
77
+ RESPONSE=$(curl -s \
78
+ -H "Authorization: Bearer $GITHUB_TOKEN" \
79
+ -H "X-GitHub-Api-Version: 2022-11-28" \
80
+ "https://api.github.com/repos/$GITHUB_REPO/issues?state=open&assignee=@me&labels=$CLANCY_PLAN_LABEL&per_page=<N>")
81
+ ```
82
+
83
+ - `CLANCY_PLAN_LABEL` defaults to `needs-refinement` if not set
84
+ - Filter out PRs (entries with `pull_request` key)
85
+ - For each issue, fetch comments: `GET /repos/$GITHUB_REPO/issues/{number}/comments`
86
+
87
+ ### Linear
88
+
89
+ Build the filter using `CLANCY_PLAN_STATE_TYPE` (defaults to `backlog` if not set):
90
+
91
+ ```graphql
92
+ query {
93
+ viewer {
94
+ assignedIssues(
95
+ filter: {
96
+ state: { type: { eq: "$CLANCY_PLAN_STATE_TYPE" } }
97
+ team: { id: { eq: "$LINEAR_TEAM_ID" } }
98
+ }
99
+ first: $N
100
+ orderBy: priority
101
+ ) {
102
+ nodes {
103
+ id identifier title description
104
+ parent { identifier title }
105
+ comments { nodes { body createdAt } }
106
+ }
107
+ }
108
+ }
109
+ }
110
+ ```
111
+
112
+ If the API call fails (non-200 response or network error):
113
+ ```
114
+ ❌ Board API error: {HTTP status or error message}
115
+
116
+ Check your credentials in .clancy/.env or run /clancy:doctor to diagnose.
117
+ ```
118
+ Stop.
119
+
120
+ If no tickets found:
121
+ ```
122
+ 🚨 Clancy — Plan
123
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
124
+
125
+ "Nothing to see here." — No backlog tickets to plan.
126
+
127
+ Check your board configuration or run /clancy:settings to verify the plan queue.
128
+ {If GitHub: "For GitHub: planning uses the \"$CLANCY_PLAN_LABEL\" label (default: needs-refinement), not \"clancy\". Apply that label to issues you want planned."}
129
+ ```
130
+ Stop.
131
+
132
+ ---
133
+
134
+ ## Step 3b — Check for existing plans (unless --force)
135
+
136
+ For each ticket, scan its comments for the marker `## Clancy Implementation Plan`:
137
+
138
+ - **No plan found:** proceed to step 4
139
+ - **Has plan, no `--force`:** skip — display `⏭️ [{KEY}] already planned. Use --force to re-plan.`
140
+ - **Has plan, with `--force`:** proceed to step 3c
141
+
142
+ ---
143
+
144
+ ## Step 3c — Read feedback comments (--force only)
145
+
146
+ When re-planning, read all comments posted AFTER the most recent `## Clancy Implementation Plan` comment. These are presumed to be PO/team feedback. No special syntax needed — they just comment normally on the ticket.
147
+
148
+ Pass this feedback to the plan generation step as additional context.
149
+
150
+ ---
151
+
152
+ ## Step 4 — For each ticket: Generate plan
153
+
154
+ Display the header:
155
+ ```
156
+ 🚨 Clancy — Plan
157
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
158
+
159
+ "Let me consult my crime files..." — Planning {N} ticket(s).
160
+ ```
161
+
162
+ For each ticket, display a progress line when starting:
163
+ ```
164
+ [{KEY}] {Title}
165
+ Exploring codebase...
166
+ ```
167
+
168
+ And when the plan is posted:
169
+ ```
170
+ ✅ Plan posted as comment.
171
+ ```
172
+
173
+ For multi-ticket runs, this provides visibility into progress. `Ctrl+C` to stop early — completed plans are already posted.
174
+
175
+ ### 4a. Quick feasibility scan
176
+
177
+ Before spending time exploring files, scan the ticket title and description for obvious non-codebase signals. Skip immediately if the ticket clearly requires work outside the codebase.
178
+
179
+ **Fail signals (skip immediately):**
180
+ - External platform references: "in Google Tag Manager", "in Salesforce", "in the AWS console", "in HubSpot", "in Jira admin"
181
+ - Human process steps: "get sign-off", "coordinate with", "schedule a meeting", "send an email to customers"
182
+ - Non-code deliverables: "write a runbook", "create a presentation", "update the wiki"
183
+ - Infrastructure ops: "rotate API keys in prod", "scale the fleet", "restart the service"
184
+
185
+ If infeasible:
186
+ ```
187
+ ⏭️ [{KEY}] {Title} — not a codebase change. Skipping.
188
+ → {reason, e.g. "Ticket describes work in Google Tag Manager, not in the codebase."}
189
+ ```
190
+
191
+ Continue to the next ticket. **Pass signals:** Anything mentioning code, components, features, bugs, UI, API, tests, refactoring, or lacking enough context to determine (benefit of the doubt).
192
+
193
+ ### 4b. Check for previous implementation (QA return detection)
194
+
195
+ Check `.clancy/progress.txt` for any previous entry matching this ticket key that ends with `| DONE` (search for `| {KEY} |` on a line ending with `| DONE`). If found, the ticket was previously implemented by Clancy and has returned (likely from QA).
196
+
197
+ If detected:
198
+ - Flag as "Previously implemented — returned from QA"
199
+ - Read QA/review comments from the board (same mechanism as feedback loop in Step 3c)
200
+ - Focus the plan on what likely went wrong and what needs fixing
201
+
202
+ If no progress entry exists: treat as fresh.
203
+
204
+ ### 4c. Read codebase context
205
+
206
+ If `.clancy/docs/` exists, read the following docs:
207
+ - `STACK.md`, `ARCHITECTURE.md`, `CONVENTIONS.md`, `TESTING.md`, `DESIGN-SYSTEM.md`, `ACCESSIBILITY.md`, `DEFINITION-OF-DONE.md`
208
+
209
+ These inform the plan's technical approach, affected files, and test plan.
210
+
211
+ ### 4d. Figma design context (if applicable)
212
+
213
+ If the ticket description contains a Figma URL and `FIGMA_API_KEY` is configured in `.clancy/.env`, fetch design context using Clancy's existing Figma MCP integration (3 MCP calls: metadata, design context, screenshot). This informs the acceptance criteria and affected components in the plan.
214
+
215
+ If Figma URL is present but `FIGMA_API_KEY` is not configured: note in the plan — "Figma URL present but API key not configured. Run /clancy:settings to add it."
216
+
217
+ ### 4e. Explore source files
218
+
219
+ Based on the ticket title AND description, explore the codebase to identify affected files.
220
+
221
+ **For S-sized tickets (simple/obvious scope):** Single-pass exploration — Glob and Read directly.
222
+
223
+ **For M/L-sized tickets (broad scope, multiple subsystems):** Spin up 2-3 parallel Explore subagents:
224
+ - **Agent 1:** Search for files matching ticket keywords, find existing implementations of similar features
225
+ - **Agent 2:** Identify related test files, check test patterns in affected areas
226
+ - **Agent 3:** (if UI ticket) Check component structure, design system usage, accessibility patterns
227
+
228
+ The size is estimated from the ticket title/description before exploration begins (rough heuristic). Subagents return their findings, which are merged into the plan.
229
+
230
+ ### 4f. Generate plan
231
+
232
+ Write the plan in this exact template:
233
+
234
+ ```markdown
235
+ ## Clancy Implementation Plan
236
+
237
+ **Ticket:** [{KEY}] {Title}
238
+ **Planned:** {YYYY-MM-DD}
239
+
240
+ ### Summary
241
+ {1-3 sentences: what this ticket asks for, why it matters, gaps filled}
242
+
243
+ ### Acceptance Criteria
244
+ - [ ] {Specific, testable criterion}
245
+ - [ ] {Specific, testable criterion}
246
+ - [ ] {Specific, testable criterion}
247
+
248
+ ### Technical Approach
249
+ {2-4 sentences: implementation strategy, patterns, key decisions}
250
+
251
+ ### Affected Files
252
+ | File | Change |
253
+ |------|--------|
254
+ | `src/path/file.ts` | {What changes and why} |
255
+ | `src/path/file.test.ts` | {What changes and why} |
256
+
257
+ ### Edge Cases
258
+ - {Specific edge case and handling}
259
+ - {Specific edge case and handling}
260
+
261
+ ### Test Plan
262
+ - [ ] {Specific test to write or verify}
263
+ - [ ] {Specific test to write or verify}
264
+
265
+ ### Dependencies
266
+ {Blockers, prerequisites, external deps. "None" if clean.}
267
+
268
+ ### Size Estimate
269
+ **{S / M / L}** — {Brief justification}
270
+
271
+ ---
272
+ *Generated by [Clancy](https://github.com/Pushedskydiver/clancy).
273
+ To request changes: comment on this ticket, then run `/clancy:plan --force` to re-plan with your feedback.
274
+ To approve: run `/clancy:approve {KEY}` to promote this plan to the ticket description.*
275
+ ```
276
+
277
+ **If re-planning with feedback**, prepend a section before Summary:
278
+ ```markdown
279
+ ### Changes From Previous Plan
280
+ {What feedback was addressed and how the plan changed}
281
+ ```
282
+
283
+ **Quality rules:**
284
+ - Acceptance criteria must be testable ("user can X", "system does Y"), never vague
285
+ - Affected files must be real files found during exploration, not guesses
286
+ - Edge cases must be specific to this ticket, not generic
287
+ - Size: S (< 1 hour, few files), M (1-4 hours, moderate), L (4+ hours, significant)
288
+ - If affected files > 15: add a note "Consider splitting this ticket"
289
+ - If UI ticket without Figma URL: note in plan
290
+ - If ticket mentions tech not in STACK.md: note in plan
291
+
292
+ **Dependency detection:**
293
+
294
+ | Type | Detection | Action |
295
+ |------|-----------|--------|
296
+ | Blocked by another ticket | Jira: issuelinks (type "Blocks"). GitHub: referenced issues. Linear: relations. | List blocking tickets. Note "Complete {KEY} first." |
297
+ | Depends on external API | Mentioned in description or inferred from affected code | If API exists with docs: include integration approach. If API doesn't exist: mark as blocked. |
298
+ | Depends on unfinished design | UI ticket with no Figma URL or design reference | Note "Design dependency — no spec provided. Visual accuracy may vary." |
299
+ | Depends on library upgrade | Ticket mentions upgrading a dependency | Include upgrade as prerequisite step. Note potential breaking changes. |
300
+ | Depends on infra in the repo | DB migrations, docker-compose, CI config | Include in affected files and plan normally. |
301
+
302
+ ---
303
+
304
+ ## Step 5 — Post plan as comment
305
+
306
+ ### Jira — POST comment
307
+
308
+ ```bash
309
+ curl -s \
310
+ -u "$JIRA_USER:$JIRA_API_TOKEN" \
311
+ -X POST \
312
+ -H "Content-Type: application/json" \
313
+ -H "Accept: application/json" \
314
+ "$JIRA_BASE_URL/rest/api/3/issue/$TICKET_KEY/comment" \
315
+ -d '<ADF JSON body>'
316
+ ```
317
+
318
+ Construct ADF (Atlassian Document Format) JSON for the comment body. Key mappings:
319
+ - `## Heading` → `heading` node (level 2)
320
+ - `### Heading` → `heading` node (level 3)
321
+ - `- bullet` → `bulletList > listItem > paragraph`
322
+ - `- [ ] checkbox` → `taskList > taskItem` (state: "TODO")
323
+ - `| table |` → `table > tableRow > tableCell`
324
+ - `**bold**` → marks: `[{ "type": "strong" }]`
325
+ - `` `code` `` → marks: `[{ "type": "code" }]`
326
+
327
+ If ADF construction is too complex for a particular element, fall back to wrapping that section in a code block (`codeBlock` node).
328
+
329
+ ### GitHub — POST comment
330
+
331
+ ```bash
332
+ curl -s \
333
+ -H "Authorization: Bearer $GITHUB_TOKEN" \
334
+ -H "X-GitHub-Api-Version: 2022-11-28" \
335
+ -X POST \
336
+ "https://api.github.com/repos/$GITHUB_REPO/issues/$ISSUE_NUMBER/comments" \
337
+ -d '{"body": "<markdown plan>"}'
338
+ ```
339
+
340
+ GitHub accepts Markdown directly — post the plan as-is.
341
+
342
+ ### Linear — commentCreate mutation
343
+
344
+ ```bash
345
+ curl -s \
346
+ -X POST \
347
+ -H "Content-Type: application/json" \
348
+ -H "Authorization: $LINEAR_API_KEY" \
349
+ "https://api.linear.app/graphql" \
350
+ -d '{"query": "mutation { commentCreate(input: { issueId: \"$ISSUE_ID\", body: \"<markdown plan>\" }) { success } }"}'
351
+ ```
352
+
353
+ Linear accepts Markdown directly.
354
+
355
+ **On failure:** Print the plan to stdout and warn — do not lose the plan. The user can manually paste it.
356
+
357
+ ```
358
+ ⚠️ Failed to post comment for [{KEY}]. Plan printed above — paste it manually.
359
+ ```
360
+
361
+ ---
362
+
363
+ ## Step 6 — Log
364
+
365
+ For each planned ticket, append to `.clancy/progress.txt`:
366
+ ```
367
+ YYYY-MM-DD HH:MM | {KEY} | PLAN | {S/M/L}
368
+ ```
369
+
370
+ ---
371
+
372
+ ## Step 7 — Summary
373
+
374
+ After all tickets are processed, display:
375
+
376
+ ```
377
+ Planned {N} ticket(s):
378
+
379
+ ✅ [{KEY1}] {Title} — M | 6 files | Comment posted
380
+ ✅ [{KEY2}] {Title} — S | 2 files | Comment posted
381
+ ⏭️ [{KEY3}] {Title} — already planned
382
+ ⏭️ [{KEY4}] {Title} — infeasible (external admin)
383
+
384
+ Plans written to your board. After review, run /clancy:approve {KEY} to promote.
385
+
386
+ "Let me dust this for prints..."
387
+ ```
388
+
389
+ ---
390
+
391
+ ## Notes
392
+
393
+ - This command does NOT implement anything — it generates plans only
394
+ - Plans are posted as comments, never overwriting the ticket description (that's `/clancy:approve`)
395
+ - Re-running without `--force` safely skips already-planned tickets
396
+ - The planning queue is separate from the implementation queue — they never compete for the same tickets
397
+ - All board API calls are best-effort — if a comment fails to post, print the plan to stdout as fallback
398
+ - When exploring the codebase, use Glob and Read for small tickets, parallel Explore subagents for larger ones
399
+ - The `## Clancy Implementation Plan` marker in comments is used by both `/clancy:plan` (to detect existing plans) and `/clancy:approve` (to find the plan to promote)
@@ -23,20 +23,25 @@ Stop.
23
23
 
24
24
  ## Step 2 — Parse progress.txt
25
25
 
26
- Each line format: `YYYY-MM-DD HH:MM | TICKET-KEY | Summary | DONE`
27
- Review lines format: `YYYY-MM-DD HH:MM | TICKET-KEY | REVIEW | {score}%`
26
+ Each line has one of these formats:
27
+ - `YYYY-MM-DD HH:MM | TICKET-KEY | Summary | DONE` — completed implementation
28
+ - `YYYY-MM-DD HH:MM | TICKET-KEY | REVIEW | {score}%` — ticket review
29
+ - `YYYY-MM-DD HH:MM | TICKET-KEY | PLAN | {S/M/L}` — plan generated
30
+ - `YYYY-MM-DD HH:MM | TICKET-KEY | APPROVE | —` — plan promoted to description
31
+ - `YYYY-MM-DD HH:MM | TICKET-KEY | SKIPPED | {reason}` — ticket skipped
28
32
 
29
33
  Parse each line:
30
34
  - Date (YYYY-MM-DD)
31
35
  - Time (HH:MM)
32
36
  - Ticket key (e.g. PROJ-42)
33
- - Summary or "REVIEW"
34
- - Status ("DONE" or score)
37
+ - Action type (DONE, REVIEW, PLAN, APPROVE, SKIPPED, or summary text)
38
+ - Detail (status, score, size, or reason)
35
39
 
36
40
  Extract:
37
41
  - Total DONE tickets
38
42
  - First and latest run dates
39
43
  - All DONE tickets from the current calendar week (Mon–Sun)
44
+ - Counts for each action type: PLAN, APPROVE, REVIEW, SKIPPED
40
45
  - Epic key from ticket key — e.g. PROJ-42 → epic likely PROJ-10 (use parent field if logged, otherwise group by project prefix)
41
46
 
42
47
  ---
@@ -65,7 +70,10 @@ By epic:
65
70
  {EPIC-KEY} {Epic name or prefix} {bar} {count} tickets
66
71
  (other) {bar} {count} tickets
67
72
 
68
- Reviews run: {N}
73
+ Plans generated: {N} (only show if > 0)
74
+ Plans approved: {N} (only show if > 0)
75
+ Reviews run: {N} (only show if > 0)
76
+ Tickets skipped: {N} (only show if > 0)
69
77
  Full log: .clancy/progress.txt
70
78
 
71
79
  "The law is powerless to help you, but here's what Clancy's done."
@@ -78,7 +86,7 @@ Full log: .clancy/progress.txt
78
86
  - Progress bars: ASCII, proportional to highest count, width 10 chars, `█` filled, `░` empty
79
87
  - Epic grouping: group by epic key in the ticket's parent field (from progress.txt if logged), or by project prefix if not available
80
88
  - Tickets without an epic: group under `(other)`
81
- - REVIEW lines: shown separately at the end as "Reviews run: N" — not included in ticket count
89
+ - REVIEW, PLAN, APPROVE, and SKIPPED lines: shown separately at the end as counts — not included in ticket count
82
90
 
83
91
  ---
84
92
 
@@ -8,7 +8,13 @@ Fetch the next ticket from the board and score how well-specified it is. Returns
8
8
 
9
9
  ## Step 1 — Preflight checks
10
10
 
11
- Same as status workflow. Check `.clancy/`, `.clancy/.env`, and board credentials.
11
+ 1. Check `.clancy/` exists and `.clancy/.env` is present. If not:
12
+ ```
13
+ .clancy/ not found. Run /clancy:init to set up Clancy first.
14
+ ```
15
+ Stop.
16
+
17
+ 2. Source `.clancy/.env` and check board credentials are present (same vars checked by `/clancy:status`).
12
18
 
13
19
  ---
14
20
 
@@ -12,6 +12,15 @@ Named after Chief Clancy Wiggum (Ralph's dad, The Simpsons). Built on the Ralph
12
12
  coined by Geoffrey Huntley (ghuntley.com/ralph/). Clancy extends that foundation with board
13
13
  integration, structured codebase docs, and a git workflow built for team development.
14
14
 
15
+ ### Planner *(optional — enable via `CLANCY_ROLES=planner` in `.clancy/.env`)*
16
+
17
+ | Command | Description |
18
+ |---|---|
19
+ | `/clancy:plan` | Refine backlog tickets into structured implementation plans |
20
+ | `/clancy:plan 3` | Plan up to 3 tickets in batch mode |
21
+ | `/clancy:plan --force` | Re-plan tickets that already have a plan (reads feedback) |
22
+ | `/clancy:approve` | Promote an approved plan to the ticket description |
23
+
15
24
  ### Implementer
16
25
 
17
26
  | Command | Description |