chief-clancy 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.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +426 -0
  3. package/bin/install.js +169 -0
  4. package/package.json +42 -0
  5. package/registry/boards.json +47 -0
  6. package/src/agents/arch-agent.md +72 -0
  7. package/src/agents/concerns-agent.md +89 -0
  8. package/src/agents/design-agent.md +130 -0
  9. package/src/agents/quality-agent.md +161 -0
  10. package/src/agents/tech-agent.md +92 -0
  11. package/src/commands/doctor.md +7 -0
  12. package/src/commands/help.md +50 -0
  13. package/src/commands/init.md +7 -0
  14. package/src/commands/logs.md +7 -0
  15. package/src/commands/map-codebase.md +16 -0
  16. package/src/commands/once.md +13 -0
  17. package/src/commands/review.md +9 -0
  18. package/src/commands/run.md +11 -0
  19. package/src/commands/settings.md +7 -0
  20. package/src/commands/status.md +9 -0
  21. package/src/commands/uninstall.md +5 -0
  22. package/src/commands/update-docs.md +9 -0
  23. package/src/commands/update.md +9 -0
  24. package/src/templates/.env.example.github +43 -0
  25. package/src/templates/.env.example.jira +53 -0
  26. package/src/templates/.env.example.linear +43 -0
  27. package/src/templates/CLAUDE.md +69 -0
  28. package/src/templates/scripts/clancy-afk.sh +111 -0
  29. package/src/templates/scripts/clancy-once-github.sh +225 -0
  30. package/src/templates/scripts/clancy-once-linear.sh +252 -0
  31. package/src/templates/scripts/clancy-once.sh +259 -0
  32. package/src/workflows/doctor.md +115 -0
  33. package/src/workflows/init.md +423 -0
  34. package/src/workflows/logs.md +82 -0
  35. package/src/workflows/map-codebase.md +124 -0
  36. package/src/workflows/once.md +80 -0
  37. package/src/workflows/review.md +165 -0
  38. package/src/workflows/run.md +119 -0
  39. package/src/workflows/scaffold.md +289 -0
  40. package/src/workflows/settings.md +344 -0
  41. package/src/workflows/status.md +120 -0
  42. package/src/workflows/uninstall.md +75 -0
  43. package/src/workflows/update-docs.md +89 -0
  44. package/src/workflows/update.md +67 -0
@@ -0,0 +1,252 @@
1
+ #!/usr/bin/env bash
2
+ # Strict mode: exit on error (-e), undefined variables (-u), pipe failures (-o pipefail).
3
+ # This means any command that fails will stop the script immediately rather than silently continuing.
4
+ set -euo pipefail
5
+
6
+ # ─── WHAT THIS SCRIPT DOES ─────────────────────────────────────────────────────
7
+ #
8
+ # Board: Linear
9
+ #
10
+ # 1. Preflight — checks all required tools, credentials, and API reachability
11
+ # 2. Fetch — pulls the next unstarted issue assigned to you via GraphQL
12
+ # 3. Branch — creates a feature branch from the issue's parent branch (or base branch)
13
+ # 4. Implement — passes the issue to Claude Code, which reads .clancy/docs/ and implements it
14
+ # 5. Merge — squash-merges the feature branch back into the target branch
15
+ # 6. Log — appends a completion entry to .clancy/progress.txt
16
+ #
17
+ # This script is run once per issue. The loop is handled by clancy-afk.sh.
18
+ #
19
+ # NOTE: Linear personal API keys do NOT use a "Bearer" prefix in the Authorization
20
+ # header. OAuth access tokens do. This is correct per Linear's documentation.
21
+ #
22
+ # NOTE: state.type "unstarted" is a fixed enum value — it filters by state category,
23
+ # not state name. This works regardless of what your team named their backlog column.
24
+ #
25
+ # NOTE: Failures use exit 0, not exit 1. This is intentional — clancy-afk.sh
26
+ # detects stop conditions by reading script output rather than exit codes, so a
27
+ # non-zero exit would be treated as an unexpected crash rather than a clean stop.
28
+ #
29
+ # ───────────────────────────────────────────────────────────────────────────────
30
+
31
+ # ─── PREFLIGHT ─────────────────────────────────────────────────────────────────
32
+
33
+ command -v claude >/dev/null 2>&1 || {
34
+ echo "✗ claude CLI not found."
35
+ echo " Install it: https://claude.ai/code"
36
+ exit 0
37
+ }
38
+ command -v jq >/dev/null 2>&1 || {
39
+ echo "✗ jq not found."
40
+ echo " Install: brew install jq (mac) | apt install jq (linux)"
41
+ exit 0
42
+ }
43
+ command -v curl >/dev/null 2>&1 || {
44
+ echo "✗ curl not found. Install curl for your OS."
45
+ exit 0
46
+ }
47
+
48
+ [ -f .clancy/.env ] || {
49
+ echo "✗ .clancy/.env not found."
50
+ echo " Copy .clancy/.env.example to .clancy/.env and fill in your credentials."
51
+ echo " Then run: /clancy:init"
52
+ exit 0
53
+ }
54
+ # shellcheck source=/dev/null
55
+ source .clancy/.env
56
+
57
+ git rev-parse --git-dir >/dev/null 2>&1 || {
58
+ echo "✗ Not a git repository."
59
+ echo " Clancy must be run from the root of a git project."
60
+ exit 0
61
+ }
62
+
63
+ if ! git diff --quiet || ! git diff --cached --quiet; then
64
+ echo "⚠ Working directory has uncommitted changes."
65
+ echo " Consider stashing or committing first to avoid confusion."
66
+ fi
67
+
68
+ [ -n "${LINEAR_API_KEY:-}" ] || { echo "✗ LINEAR_API_KEY is not set in .clancy/.env"; exit 0; }
69
+ [ -n "${LINEAR_TEAM_ID:-}" ] || { echo "✗ LINEAR_TEAM_ID is not set in .clancy/.env"; exit 0; }
70
+
71
+ # Linear ping — verify API key with a minimal query
72
+ # Note: personal API keys do NOT use a "Bearer" prefix — this is correct per Linear docs.
73
+ # OAuth access tokens use "Bearer". Do not change this.
74
+ PING_BODY=$(curl -s -X POST https://api.linear.app/graphql \
75
+ -H "Content-Type: application/json" \
76
+ -H "Authorization: $LINEAR_API_KEY" \
77
+ -d '{"query": "{ viewer { id } }"}')
78
+
79
+ echo "$PING_BODY" | jq -e '.data.viewer.id' >/dev/null 2>&1 || {
80
+ echo "✗ Linear authentication failed. Check LINEAR_API_KEY in .clancy/.env."; exit 0
81
+ }
82
+
83
+ if [ "${PLAYWRIGHT_ENABLED:-}" = "true" ]; then
84
+ if lsof -ti:"${PLAYWRIGHT_DEV_PORT:-5173}" >/dev/null 2>&1; then
85
+ echo "⚠ Port ${PLAYWRIGHT_DEV_PORT:-5173} is already in use."
86
+ echo " If visual checks fail, stop whatever is using the port first."
87
+ fi
88
+ fi
89
+
90
+ echo "✓ Preflight passed. Starting Clancy..."
91
+
92
+ # ─── END PREFLIGHT ─────────────────────────────────────────────────────────────
93
+
94
+ # ─── FETCH ISSUE ───────────────────────────────────────────────────────────────
95
+
96
+ # Fetch one unstarted issue assigned to the current user on the configured team.
97
+ # Note: personal API keys do NOT use "Bearer" prefix — this is intentional.
98
+ #
99
+ # GraphQL query (expanded for readability):
100
+ # viewer {
101
+ # assignedIssues(
102
+ # filter: {
103
+ # state: { type: { eq: "unstarted" } } ← fixed enum, works regardless of column name
104
+ # team: { id: { eq: "$LINEAR_TEAM_ID" } }
105
+ # labels: { name: { eq: "$CLANCY_LABEL" } } ← only if CLANCY_LABEL is set
106
+ # }
107
+ # first: 1
108
+ # orderBy: priority
109
+ # ) {
110
+ # nodes { id identifier title description parent { identifier title } }
111
+ # }
112
+ # }
113
+
114
+ # Validate user-controlled values to prevent GraphQL injection.
115
+ # Values are passed via GraphQL variables (JSON-encoded by jq) rather than string-interpolated.
116
+ if ! echo "$LINEAR_TEAM_ID" | grep -qE '^[a-zA-Z0-9_-]+$'; then
117
+ echo "✗ LINEAR_TEAM_ID contains invalid characters. Check .clancy/.env."
118
+ exit 0
119
+ fi
120
+ if [ -n "${CLANCY_LABEL:-}" ] && ! echo "$CLANCY_LABEL" | grep -qE '^[a-zA-Z0-9 _-]+$'; then
121
+ echo "✗ CLANCY_LABEL contains invalid characters. Use only letters, numbers, spaces, hyphens, and underscores."
122
+ exit 0
123
+ fi
124
+
125
+ # Build request using GraphQL variables — values are JSON-encoded by jq, never interpolated into the query string.
126
+ # The label filter clause is only added to the query when CLANCY_LABEL is set, since passing null would match nothing.
127
+ if [ -n "${CLANCY_LABEL:-}" ]; then
128
+ REQUEST_BODY=$(jq -n \
129
+ --arg teamId "$LINEAR_TEAM_ID" \
130
+ --arg label "$CLANCY_LABEL" \
131
+ '{"query": "query($teamId: String!, $label: String) { viewer { assignedIssues(filter: { state: { type: { eq: \"unstarted\" } } team: { id: { eq: $teamId } } labels: { name: { eq: $label } } } first: 1 orderBy: priority) { nodes { id identifier title description parent { identifier title } } } } }", "variables": {"teamId": $teamId, "label": $label}}')
132
+ else
133
+ REQUEST_BODY=$(jq -n \
134
+ --arg teamId "$LINEAR_TEAM_ID" \
135
+ '{"query": "query($teamId: String!) { viewer { assignedIssues(filter: { state: { type: { eq: \"unstarted\" } } team: { id: { eq: $teamId } } } first: 1 orderBy: priority) { nodes { id identifier title description parent { identifier title } } } } }", "variables": {"teamId": $teamId}}')
136
+ fi
137
+
138
+ RESPONSE=$(curl -s -X POST https://api.linear.app/graphql \
139
+ -H "Content-Type: application/json" \
140
+ -H "Authorization: $LINEAR_API_KEY" \
141
+ -d "$REQUEST_BODY")
142
+
143
+ # Check for API errors before parsing (rate limit, permission error, etc.)
144
+ if ! echo "$RESPONSE" | jq -e '.data.viewer.assignedIssues' >/dev/null 2>&1; then
145
+ ERR_MSG=$(echo "$RESPONSE" | jq -r '.errors[0].message // "Unexpected response"' 2>/dev/null || echo "Unexpected response")
146
+ echo "✗ Linear API error: $ERR_MSG. Check LINEAR_API_KEY in .clancy/.env."
147
+ exit 0
148
+ fi
149
+
150
+ NODE_COUNT=$(echo "$RESPONSE" | jq '.data.viewer.assignedIssues.nodes | length')
151
+ if [ "$NODE_COUNT" -eq 0 ]; then
152
+ echo "No issues found. All done!"
153
+ exit 0
154
+ fi
155
+
156
+ IDENTIFIER=$(echo "$RESPONSE" | jq -r '.data.viewer.assignedIssues.nodes[0].identifier')
157
+ TITLE=$(echo "$RESPONSE" | jq -r '.data.viewer.assignedIssues.nodes[0].title')
158
+ DESCRIPTION=$(echo "$RESPONSE" | jq -r '.data.viewer.assignedIssues.nodes[0].description // "No description"')
159
+ PARENT_ID=$(echo "$RESPONSE" | jq -r '.data.viewer.assignedIssues.nodes[0].parent.identifier // "none"')
160
+ PARENT_TITLE=$(echo "$RESPONSE" | jq -r '.data.viewer.assignedIssues.nodes[0].parent.title // ""')
161
+
162
+ EPIC_INFO="${PARENT_ID}"
163
+ if [ -n "$PARENT_TITLE" ] && [ "$PARENT_TITLE" != "null" ]; then
164
+ EPIC_INFO="${PARENT_ID} — ${PARENT_TITLE}"
165
+ fi
166
+
167
+ BASE_BRANCH="${CLANCY_BASE_BRANCH:-main}"
168
+ TICKET_BRANCH="feature/$(echo "$IDENTIFIER" | tr '[:upper:]' '[:lower:]')"
169
+
170
+ # Auto-detect target branch from ticket's parent.
171
+ # If the issue has a parent, branch from epic/{parent-id} (creating it from
172
+ # BASE_BRANCH if it doesn't exist yet). Otherwise branch from BASE_BRANCH directly.
173
+ if [ "$PARENT_ID" != "none" ]; then
174
+ TARGET_BRANCH="epic/$(echo "$PARENT_ID" | tr '[:upper:]' '[:lower:]')"
175
+ git show-ref --verify --quiet "refs/heads/$TARGET_BRANCH" \
176
+ || git checkout -b "$TARGET_BRANCH" "$BASE_BRANCH"
177
+ else
178
+ TARGET_BRANCH="$BASE_BRANCH"
179
+ fi
180
+
181
+ # ─── IMPLEMENT ─────────────────────────────────────────────────────────────────
182
+
183
+ echo "Picking up: [$IDENTIFIER] $TITLE"
184
+ echo "Epic: $EPIC_INFO | Target branch: $TARGET_BRANCH"
185
+
186
+ git checkout "$TARGET_BRANCH"
187
+ # -B creates the branch if it doesn't exist, or resets it to HEAD if it does.
188
+ # This handles retries cleanly without failing on an already-existing branch.
189
+ git checkout -B "$TICKET_BRANCH"
190
+
191
+ PROMPT="You are implementing Linear issue $IDENTIFIER.
192
+
193
+ Title: $TITLE
194
+ Epic: $EPIC_INFO
195
+
196
+ Description:
197
+ $DESCRIPTION
198
+
199
+ Step 0 — Executability check (do this before any git or file operation):
200
+ Read the issue title and description above. Can this issue be implemented entirely
201
+ as a code change committed to this repo? Consult the 'Executability check' section of
202
+ CLAUDE.md for the full list of skip conditions.
203
+
204
+ If you must SKIP this issue:
205
+ 1. Output: ⚠ Skipping [$IDENTIFIER]: {one-line reason}
206
+ 2. Output: Ticket skipped — update it to be codebase-only work, then re-run.
207
+ 3. Append to .clancy/progress.txt: YYYY-MM-DD HH:MM | $IDENTIFIER | SKIPPED | {reason}
208
+ 4. Stop — no branches, no file changes, no git operations.
209
+
210
+ If the issue IS implementable, continue:
211
+ 1. Read ALL docs in .clancy/docs/ — especially GIT.md for branching and commit conventions
212
+ 2. Follow the conventions in GIT.md exactly
213
+ 3. Implement the issue fully
214
+ 4. Commit your work following the conventions in GIT.md
215
+ 5. When done, confirm you are finished."
216
+
217
+ CLAUDE_ARGS=(--dangerously-skip-permissions)
218
+ [ -n "${CLANCY_MODEL:-}" ] && CLAUDE_ARGS+=(--model "$CLANCY_MODEL")
219
+ echo "$PROMPT" | claude "${CLAUDE_ARGS[@]}"
220
+
221
+ # ─── MERGE & LOG ───────────────────────────────────────────────────────────────
222
+
223
+ # Squash all commits from the feature branch into a single commit on the target branch.
224
+ git checkout "$TARGET_BRANCH"
225
+ git merge --squash "$TICKET_BRANCH"
226
+ if git diff --cached --quiet; then
227
+ echo "⚠ No changes staged after squash merge. Claude may not have committed any work."
228
+ else
229
+ git commit -m "feat($IDENTIFIER): $TITLE"
230
+ fi
231
+
232
+ # Delete ticket branch locally
233
+ git branch -d "$TICKET_BRANCH"
234
+
235
+ # Log progress
236
+ echo "$(date '+%Y-%m-%d %H:%M') | $IDENTIFIER | $TITLE | DONE" >> .clancy/progress.txt
237
+
238
+ echo "✓ $IDENTIFIER complete."
239
+
240
+ # Send completion notification if webhook is configured
241
+ if [ -n "${CLANCY_NOTIFY_WEBHOOK:-}" ]; then
242
+ NOTIFY_MSG="✓ Clancy completed [$IDENTIFIER] $TITLE"
243
+ if echo "$CLANCY_NOTIFY_WEBHOOK" | grep -q "hooks.slack.com"; then
244
+ curl -s -X POST "$CLANCY_NOTIFY_WEBHOOK" \
245
+ -H "Content-Type: application/json" \
246
+ -d "$(jq -n --arg text "$NOTIFY_MSG" '{"text": $text}')" >/dev/null 2>&1 || true
247
+ else
248
+ curl -s -X POST "$CLANCY_NOTIFY_WEBHOOK" \
249
+ -H "Content-Type: application/json" \
250
+ -d "$(jq -n --arg text "$NOTIFY_MSG" '{"type":"message","attachments":[{"contentType":"application/vnd.microsoft.card.adaptive","content":{"type":"AdaptiveCard","body":[{"type":"TextBlock","text":$text}]}}]}')" >/dev/null 2>&1 || true
251
+ fi
252
+ fi
@@ -0,0 +1,259 @@
1
+ #!/usr/bin/env bash
2
+ # Strict mode: exit on error (-e), undefined variables (-u), pipe failures (-o pipefail).
3
+ # This means any command that fails will stop the script immediately rather than silently continuing.
4
+ set -euo pipefail
5
+
6
+ # ─── WHAT THIS SCRIPT DOES ─────────────────────────────────────────────────────
7
+ #
8
+ # Board: Jira
9
+ #
10
+ # 1. Preflight — checks all required tools, credentials, and board reachability
11
+ # 2. Fetch — pulls the next assigned "To Do" ticket from Jira (maxResults: 1)
12
+ # 3. Branch — creates a feature branch from the ticket's epic branch (or base branch)
13
+ # 4. Implement — passes the ticket to Claude Code, which reads .clancy/docs/ and implements it
14
+ # 5. Merge — squash-merges the feature branch back into the target branch
15
+ # 6. Log — appends a completion entry to .clancy/progress.txt
16
+ #
17
+ # This script is run once per ticket. The loop is handled by clancy-afk.sh.
18
+ #
19
+ # NOTE: This file has no -jira suffix by design. /clancy:init copies the correct
20
+ # board variant into the user's .clancy/ directory as clancy-once.sh regardless
21
+ # of board. The board is determined by which template was copied, not the filename.
22
+ #
23
+ # NOTE: Failures use exit 0, not exit 1. This is intentional — clancy-afk.sh
24
+ # detects stop conditions by reading script output rather than exit codes, so a
25
+ # non-zero exit would be treated as an unexpected crash rather than a clean stop.
26
+ #
27
+ # ───────────────────────────────────────────────────────────────────────────────
28
+
29
+ # ─── PREFLIGHT ─────────────────────────────────────────────────────────────────
30
+
31
+ command -v claude >/dev/null 2>&1 || {
32
+ echo "✗ claude CLI not found."
33
+ echo " Install it: https://claude.ai/code"
34
+ exit 0
35
+ }
36
+ command -v jq >/dev/null 2>&1 || {
37
+ echo "✗ jq not found."
38
+ echo " Install: brew install jq (mac) | apt install jq (linux)"
39
+ exit 0
40
+ }
41
+ command -v curl >/dev/null 2>&1 || {
42
+ echo "✗ curl not found. Install curl for your OS."
43
+ exit 0
44
+ }
45
+
46
+ [ -f .clancy/.env ] || {
47
+ echo "✗ .clancy/.env not found."
48
+ echo " Copy .clancy/.env.example to .clancy/.env and fill in your credentials."
49
+ echo " Then run: /clancy:init"
50
+ exit 0
51
+ }
52
+ # shellcheck source=/dev/null
53
+ source .clancy/.env
54
+
55
+ git rev-parse --git-dir >/dev/null 2>&1 || {
56
+ echo "✗ Not a git repository."
57
+ echo " Clancy must be run from the root of a git project."
58
+ exit 0
59
+ }
60
+
61
+ if ! git diff --quiet || ! git diff --cached --quiet; then
62
+ echo "⚠ Working directory has uncommitted changes."
63
+ echo " Consider stashing or committing first to avoid confusion."
64
+ fi
65
+
66
+ [ -n "${JIRA_BASE_URL:-}" ] || { echo "✗ JIRA_BASE_URL is not set in .clancy/.env"; exit 0; }
67
+ [ -n "${JIRA_USER:-}" ] || { echo "✗ JIRA_USER is not set in .clancy/.env"; exit 0; }
68
+ [ -n "${JIRA_API_TOKEN:-}" ] || { echo "✗ JIRA_API_TOKEN is not set in .clancy/.env"; exit 0; }
69
+ [ -n "${JIRA_PROJECT_KEY:-}" ] || { echo "✗ JIRA_PROJECT_KEY is not set in .clancy/.env"; exit 0; }
70
+ if ! echo "$JIRA_PROJECT_KEY" | grep -qE '^[A-Z][A-Z0-9]+$'; then
71
+ echo "✗ JIRA_PROJECT_KEY format is invalid. Expected uppercase letters and numbers only (e.g. PROJ, ENG2). Check JIRA_PROJECT_KEY in .clancy/.env."
72
+ exit 0
73
+ fi
74
+
75
+ PING=$(curl -s -o /dev/null -w "%{http_code}" \
76
+ -u "$JIRA_USER:$JIRA_API_TOKEN" \
77
+ "$JIRA_BASE_URL/rest/api/3/project/$JIRA_PROJECT_KEY")
78
+
79
+ case "$PING" in
80
+ 200) ;;
81
+ 401) echo "✗ Jira authentication failed. Check JIRA_USER and JIRA_API_TOKEN in .clancy/.env."; exit 0 ;;
82
+ 403) echo "✗ Jira access denied. Your token may lack Browse Projects permission."; exit 0 ;;
83
+ 404) echo "✗ Jira project '$JIRA_PROJECT_KEY' not found. Check JIRA_PROJECT_KEY in .clancy/.env."; exit 0 ;;
84
+ 000) echo "✗ Could not reach Jira at $JIRA_BASE_URL. Check JIRA_BASE_URL and your network."; exit 0 ;;
85
+ *) echo "✗ Jira returned unexpected status $PING. Check your config."; exit 0 ;;
86
+ esac
87
+
88
+ if [ "${PLAYWRIGHT_ENABLED:-}" = "true" ]; then
89
+ if lsof -ti:"${PLAYWRIGHT_DEV_PORT:-5173}" >/dev/null 2>&1; then
90
+ echo "⚠ Port ${PLAYWRIGHT_DEV_PORT:-5173} is already in use."
91
+ echo " Clancy will attempt to start the dev server on this port."
92
+ echo " If visual checks fail, stop whatever is using the port first."
93
+ fi
94
+ fi
95
+
96
+ echo "✓ Preflight passed. Starting Clancy..."
97
+
98
+ # ─── END PREFLIGHT ─────────────────────────────────────────────────────────────
99
+
100
+ # ─── FETCH TICKET ──────────────────────────────────────────────────────────────
101
+
102
+ # Validate user-controlled values to prevent JQL injection.
103
+ # JQL does not support parameterised queries, so we restrict to safe characters.
104
+ if [ -n "${CLANCY_LABEL:-}" ] && ! echo "$CLANCY_LABEL" | grep -qE '^[a-zA-Z0-9 _-]+$'; then
105
+ echo "✗ CLANCY_LABEL contains invalid characters. Use only letters, numbers, spaces, hyphens, and underscores."
106
+ exit 0
107
+ fi
108
+ if ! echo "${CLANCY_JQL_STATUS:-To Do}" | grep -qE '^[a-zA-Z0-9 _-]+$'; then
109
+ echo "✗ CLANCY_JQL_STATUS contains invalid characters. Use only letters, numbers, spaces, hyphens, and underscores."
110
+ exit 0
111
+ fi
112
+
113
+ # Build JQL — sprint filter is optional (requires Jira Software license).
114
+ # Uses the /rest/api/3/search/jql POST endpoint — the old GET /search was removed Aug 2025.
115
+ # maxResults:1 is intentional — pick one ticket per run, never paginate.
116
+ if [ -n "${CLANCY_JQL_SPRINT:-}" ]; then
117
+ SPRINT_CLAUSE="AND sprint in openSprints()"
118
+ else
119
+ SPRINT_CLAUSE=""
120
+ fi
121
+
122
+ # Optional label filter — set CLANCY_LABEL in .env to only pick up tickets with that label.
123
+ # Useful for mixed backlogs where not every ticket is suitable for autonomous implementation.
124
+ if [ -n "${CLANCY_LABEL:-}" ]; then
125
+ LABEL_CLAUSE="AND labels = \"$CLANCY_LABEL\""
126
+ else
127
+ LABEL_CLAUSE=""
128
+ fi
129
+
130
+ RESPONSE=$(curl -s \
131
+ -u "$JIRA_USER:$JIRA_API_TOKEN" \
132
+ -X POST \
133
+ -H "Content-Type: application/json" \
134
+ -H "Accept: application/json" \
135
+ "$JIRA_BASE_URL/rest/api/3/search/jql" \
136
+ -d "{
137
+ \"jql\": \"project=$JIRA_PROJECT_KEY $SPRINT_CLAUSE $LABEL_CLAUSE AND assignee=currentUser() AND status=\\\"${CLANCY_JQL_STATUS:-To Do}\\\" ORDER BY priority ASC\",
138
+ \"maxResults\": 1,
139
+ \"fields\": [\"summary\", \"description\", \"issuelinks\", \"parent\", \"customfield_10014\"]
140
+ }")
141
+
142
+ # New endpoint returns { "issues": [...], "isLast": bool } — no .total field
143
+ ISSUE_COUNT=$(echo "$RESPONSE" | jq '.issues | length')
144
+ if [ "$ISSUE_COUNT" -eq 0 ]; then
145
+ echo "No tickets found. All done!"
146
+ exit 0
147
+ fi
148
+
149
+ TICKET_KEY=$(echo "$RESPONSE" | jq -r '.issues[0].key')
150
+ SUMMARY=$(echo "$RESPONSE" | jq -r '.issues[0].fields.summary')
151
+
152
+ # Extract description via recursive ADF walk
153
+ DESCRIPTION=$(echo "$RESPONSE" | jq -r '
154
+ .issues[0].fields.description
155
+ | .. | strings
156
+ | select(length > 0)
157
+ | . + "\n"
158
+ ' 2>/dev/null || echo "No description")
159
+
160
+ # Extract epic — try parent first (next-gen), fall back to customfield_10014 (classic)
161
+ EPIC_INFO=$(echo "$RESPONSE" | jq -r '
162
+ .issues[0].fields.parent.key // .issues[0].fields.customfield_10014 // "none"
163
+ ')
164
+
165
+ # Extract blocking issue links
166
+ BLOCKERS=$(echo "$RESPONSE" | jq -r '
167
+ [.issues[0].fields.issuelinks[]?
168
+ | select(.type.name == "Blocks" and .inwardIssue?)
169
+ | .inwardIssue.key]
170
+ | if length > 0 then "Blocked by: " + join(", ") else "None" end
171
+ ' 2>/dev/null || echo "None")
172
+
173
+ BASE_BRANCH="${CLANCY_BASE_BRANCH:-main}"
174
+ TICKET_BRANCH="feature/$(echo "$TICKET_KEY" | tr '[:upper:]' '[:lower:]')"
175
+
176
+ # Auto-detect target branch from ticket's parent epic.
177
+ # If the ticket has a parent epic, branch from epic/{epic-key} (creating it from
178
+ # BASE_BRANCH if it doesn't exist yet). Otherwise branch from BASE_BRANCH directly.
179
+ if [ "$EPIC_INFO" != "none" ]; then
180
+ TARGET_BRANCH="epic/$(echo "$EPIC_INFO" | tr '[:upper:]' '[:lower:]')"
181
+ git show-ref --verify --quiet "refs/heads/$TARGET_BRANCH" \
182
+ || git checkout -b "$TARGET_BRANCH" "$BASE_BRANCH"
183
+ else
184
+ TARGET_BRANCH="$BASE_BRANCH"
185
+ fi
186
+
187
+ # ─── IMPLEMENT ─────────────────────────────────────────────────────────────────
188
+
189
+ echo "Picking up: [$TICKET_KEY] $SUMMARY"
190
+ echo "Epic: $EPIC_INFO | Target branch: $TARGET_BRANCH | Blockers: $BLOCKERS"
191
+
192
+ git checkout "$TARGET_BRANCH"
193
+ # -B creates the branch if it doesn't exist, or resets it to HEAD if it does.
194
+ # This handles retries cleanly without failing on an already-existing branch.
195
+ git checkout -B "$TICKET_BRANCH"
196
+
197
+ PROMPT="You are implementing Jira ticket $TICKET_KEY.
198
+
199
+ Summary: $SUMMARY
200
+ Epic: $EPIC_INFO
201
+ Blockers: $BLOCKERS
202
+
203
+ Description:
204
+ $DESCRIPTION
205
+
206
+ Step 0 — Executability check (do this before any git or file operation):
207
+ Read the ticket summary and description above. Can this ticket be implemented entirely
208
+ as a code change committed to this repo? Consult the 'Executability check' section of
209
+ CLAUDE.md for the full list of skip conditions.
210
+
211
+ If you must SKIP this ticket:
212
+ 1. Output: ⚠ Skipping [$TICKET_KEY]: {one-line reason}
213
+ 2. Output: Ticket skipped — update it to be codebase-only work, then re-run.
214
+ 3. Append to .clancy/progress.txt: YYYY-MM-DD HH:MM | $TICKET_KEY | SKIPPED | {reason}
215
+ 4. Stop — no branches, no file changes, no git operations.
216
+
217
+ If the ticket IS implementable, continue:
218
+ 1. Read ALL docs in .clancy/docs/ — especially GIT.md for branching and commit conventions
219
+ 2. Follow the conventions in GIT.md exactly
220
+ 3. Implement the ticket fully
221
+ 4. Commit your work following the conventions in GIT.md
222
+ 5. When done, confirm you are finished."
223
+
224
+ CLAUDE_ARGS=(--dangerously-skip-permissions)
225
+ [ -n "${CLANCY_MODEL:-}" ] && CLAUDE_ARGS+=(--model "$CLANCY_MODEL")
226
+ echo "$PROMPT" | claude "${CLAUDE_ARGS[@]}"
227
+
228
+ # ─── MERGE & LOG ───────────────────────────────────────────────────────────────
229
+
230
+ # Squash all commits from the feature branch into a single commit on the target branch.
231
+ git checkout "$TARGET_BRANCH"
232
+ git merge --squash "$TICKET_BRANCH"
233
+ if git diff --cached --quiet; then
234
+ echo "⚠ No changes staged after squash merge. Claude may not have committed any work."
235
+ else
236
+ git commit -m "feat($TICKET_KEY): $SUMMARY"
237
+ fi
238
+
239
+ # Delete ticket branch locally (never push deletes)
240
+ git branch -d "$TICKET_BRANCH"
241
+
242
+ # Log progress
243
+ echo "$(date '+%Y-%m-%d %H:%M') | $TICKET_KEY | $SUMMARY | DONE" >> .clancy/progress.txt
244
+
245
+ echo "✓ $TICKET_KEY complete."
246
+
247
+ # Send completion notification if webhook is configured
248
+ if [ -n "${CLANCY_NOTIFY_WEBHOOK:-}" ]; then
249
+ NOTIFY_MSG="✓ Clancy completed [$TICKET_KEY] $SUMMARY"
250
+ if echo "$CLANCY_NOTIFY_WEBHOOK" | grep -q "hooks.slack.com"; then
251
+ curl -s -X POST "$CLANCY_NOTIFY_WEBHOOK" \
252
+ -H "Content-Type: application/json" \
253
+ -d "$(jq -n --arg text "$NOTIFY_MSG" '{"text": $text}')" >/dev/null 2>&1 || true
254
+ else
255
+ curl -s -X POST "$CLANCY_NOTIFY_WEBHOOK" \
256
+ -H "Content-Type: application/json" \
257
+ -d "$(jq -n --arg text "$NOTIFY_MSG" '{"type":"message","attachments":[{"contentType":"application/vnd.microsoft.card.adaptive","content":{"type":"AdaptiveCard","body":[{"type":"TextBlock","text":$text}]}}]}')" >/dev/null 2>&1 || true
258
+ fi
259
+ fi
@@ -0,0 +1,115 @@
1
+ ## Update check
2
+
3
+ Before doing anything else, check for updates:
4
+
5
+ 1. Run: `npm show chief-clancy version`
6
+ 2. Read the installed version from the Clancy `package.json`
7
+ 3. If a newer version exists, print: `ℹ Clancy v{current} → v{latest} available. Run /clancy:update to upgrade.` then continue normally.
8
+ 4. If already on latest, continue silently.
9
+ 5. If the npm check fails for any reason (offline, network error), continue silently. Never block on this.
10
+
11
+ ---
12
+
13
+ # Clancy Doctor Workflow
14
+
15
+ ## Overview
16
+
17
+ Diagnose your Clancy setup — test every configured integration and report what's working, what's broken, and how to fix it. Never modifies any files or state.
18
+
19
+ ---
20
+
21
+ ## Step 1 — Check install
22
+
23
+ - Verify Clancy commands are installed (`.claude/commands/clancy/` or `~/.claude/commands/clancy/`)
24
+ - Read installed version from `package.json` in the commands directory
25
+ - Print: `✓ Clancy v{version} installed ({location})`
26
+
27
+ ---
28
+
29
+ ## Step 2 — Check prerequisites
30
+
31
+ Test each required binary:
32
+
33
+ | Binary | Check | Fix hint |
34
+ |---|---|---|
35
+ | `jq` | `command -v jq` | `brew install jq` / `apt install jq` |
36
+ | `curl` | `command -v curl` | Install curl for your OS |
37
+ | `git` | `command -v git` | Install git for your OS |
38
+
39
+ Print `✓` or `✗` for each.
40
+
41
+ ---
42
+
43
+ ## Step 3 — Check project setup
44
+
45
+ - `.clancy/` exists → `✓ .clancy/ found`
46
+ - `.clancy/clancy-once.sh` exists and is executable → `✓ clancy-once.sh`
47
+ - `.clancy/clancy-afk.sh` exists and is executable → `✓ clancy-afk.sh`
48
+ - `.clancy/.env` exists → `✓ .clancy/.env found`
49
+ - `.clancy/docs/` has non-empty files → `✓ codebase docs present ({N} files)`
50
+
51
+ If `.clancy/` is missing: `✗ .clancy/ not found — run /clancy:init`
52
+ If `.clancy/.env` is missing: `✗ .clancy/.env not found — run /clancy:init`
53
+
54
+ ---
55
+
56
+ ## Step 4 — Check board credentials
57
+
58
+ Source `.clancy/.env` and detect which board is configured:
59
+
60
+ **Jira** — if `JIRA_BASE_URL` is set:
61
+ 1. Check all required vars are non-empty: `JIRA_BASE_URL`, `JIRA_USER`, `JIRA_API_TOKEN`, `JIRA_PROJECT_KEY`
62
+ 2. Ping: `GET {JIRA_BASE_URL}/rest/api/3/project/{JIRA_PROJECT_KEY}` with basic auth
63
+ 3. Report HTTP status with specific guidance for each failure code
64
+
65
+ **GitHub Issues** — if `GITHUB_TOKEN` is set:
66
+ 1. Check: `GITHUB_TOKEN`, `GITHUB_REPO`
67
+ 2. Ping: `GET https://api.github.com/repos/{GITHUB_REPO}` with bearer token
68
+ 3. Report status
69
+
70
+ **Linear** — if `LINEAR_API_KEY` is set:
71
+ 1. Check: `LINEAR_API_KEY`, `LINEAR_TEAM_ID`
72
+ 2. Ping: `POST https://api.linear.app/graphql` with `{ viewer { id } }` — no Bearer prefix
73
+ 3. Report status
74
+
75
+ ---
76
+
77
+ ## Step 5 — Check optional integrations
78
+
79
+ **Figma** — if `FIGMA_API_KEY` is set:
80
+ - Call `GET https://api.figma.com/v1/me` with `X-Figma-Token: $FIGMA_API_KEY`
81
+ - On success: print `✓ Figma connected — {email}`
82
+ - On 403: print `✗ Figma authentication failed. Check FIGMA_API_KEY in .clancy/.env.`
83
+ - Note: Figma's API does not expose plan information — check your plan at figma.com/settings
84
+
85
+ **Playwright** — if `PLAYWRIGHT_ENABLED=true`:
86
+ - Check `.clancy/docs/PLAYWRIGHT.md` exists
87
+ - Verify `PLAYWRIGHT_DEV_COMMAND` and `PLAYWRIGHT_DEV_PORT` are set
88
+ - Check port is not currently in use (just a status, not a blocker)
89
+
90
+ **Notifications** — if `CLANCY_NOTIFY_WEBHOOK` is set:
91
+ - Detect platform from URL (Slack/Teams)
92
+ - Send a test ping: `"Clancy doctor — webhook test from {project dir}"`
93
+ - Report success or failure
94
+
95
+ ---
96
+
97
+ ## Step 6 — Summary
98
+
99
+ ```
100
+ Clancy doctor — {N} checks passed, {N} warnings, {N} failures
101
+
102
+ ✓ Clancy v0.1.0 installed (global)
103
+ ✓ jq, curl, git — all present
104
+ ✓ .clancy/ set up — 10 docs present
105
+ ✓ Jira connected — PROJ reachable
106
+ ✓ Figma connected — alex@example.com (check plan at figma.com/settings)
107
+ ✗ PLAYWRIGHT_STORYBOOK_PORT — not set in .clancy/.env
108
+
109
+ Fix the ✗ items, then run /clancy:once to verify end-to-end.
110
+ ```
111
+
112
+ If all checks pass:
113
+ ```
114
+ All good. Run /clancy:once to pick up your first ticket.
115
+ ```