-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevflow
More file actions
executable file
·298 lines (262 loc) · 12.6 KB
/
Copy pathdevflow
File metadata and controls
executable file
·298 lines (262 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/usr/bin/env bash
set -euo pipefail
# ── Resolve devflow root ─────────────────────────────────────────────────────
# Follow symlinks to find the real install directory
_resolve_source() {
local src="${BASH_SOURCE[0]}"
while [[ -L "$src" ]]; do
local dir="$(cd "$(dirname "$src")" && pwd)"
src="$(readlink "$src")"
[[ "$src" != /* ]] && src="$dir/$src"
done
echo "$src"
}
DEVFLOW_BIN="$(cd "$(dirname "$(_resolve_source)")" && pwd)"
DEVFLOW_ROOT="$(dirname "$DEVFLOW_BIN")"
# ── Source libraries ──────────────────────────────────────────────────────────
source "${DEVFLOW_ROOT}/lib/utils.sh"
source "${DEVFLOW_ROOT}/lib/init.sh"
source "${DEVFLOW_ROOT}/lib/services.sh"
source "${DEVFLOW_ROOT}/lib/check.sh"
source "${DEVFLOW_ROOT}/lib/skills.sh"
source "${DEVFLOW_ROOT}/lib/seed.sh"
source "${DEVFLOW_ROOT}/lib/worktree.sh"
source "${DEVFLOW_ROOT}/lib/visualizations.sh"
source "${DEVFLOW_ROOT}/lib/done.sh"
source "${DEVFLOW_ROOT}/lib/watch.sh"
source "${DEVFLOW_ROOT}/lib/release.sh"
source "${DEVFLOW_ROOT}/lib/deps.sh"
source "${DEVFLOW_ROOT}/lib/render-deps.sh"
# Override devflow_root to use our resolved path
devflow_root() { echo "$DEVFLOW_ROOT"; }
# ── Help ──────────────────────────────────────────────────────────────────────
usage() {
cat <<EOF
${BOLD}devflow${RESET} v${DEVFLOW_VERSION} — AI dev environment orchestrator
${BOLD}USAGE${RESET}
devflow <command> [options]
${BOLD}COMMANDS${RESET}
${CYAN}init${RESET} [project-dir] Initialize a project with all 6 layers
${CYAN}up${RESET} Start Docker services (Hindsight + Langfuse)
${CYAN}down${RESET} Stop Docker services
${CYAN}restart${RESET} Restart Docker services (down + up)
${CYAN}status${RESET} Show status of all layers
${CYAN}check${RESET} Run code review checks on current diff
${CYAN}deps${RESET} check <skill> Check a skill's required/optional dependencies
${CYAN}skills${RESET} list List available skills
${CYAN}skills${RESET} install <name> Install a skill to the current project
${CYAN}skills${RESET} remove <name> Remove a skill from the project
${CYAN}skills${RESET} convert [opts] Convert skills to a Claude Code plugin
${CYAN}seed${RESET} [project-dir] Seed Hindsight memory from project files
${CYAN}done${RESET} <branch-name> Clean up a completed work session
${CYAN}clean${RESET} [--dry-run] [--all] Remove merged worktrees (--all for everything)
${CYAN}worktree${RESET} <name> Create a worktree
${CYAN}review${RESET} [<pr-url>] Review local diff or a PR/MR by URL
${CYAN}watch${RESET} [setup|remove] Sensitive file watchdog (background watcher)
${CYAN}check-version${RESET} Check version consistency across all files
${CYAN}version-bump${RESET} <version> Bump version in all files
${CYAN}release${RESET} Preview next release (dry-run)
${CYAN}visualizations${RESET} [action] Manage visualizations (config, list, open, update, render)
${CYAN}root${RESET} Print devflow installation path
${CYAN}version${RESET} Print version
${CYAN}help${RESET} Show this help
${BOLD}LAYERS${RESET}
1. Hindsight — Memory MCP (Docker)
2. Worktrunk — Git worktrees (brew)
3. Code Review — AI-powered (claude/opencode)
4. CLAUDE.md — Process discipline (skills)
5. Langfuse — Observability (Docker)
${BOLD}EXAMPLES${RESET}
devflow init ~/projects/myapp
devflow up
devflow seed
devflow worktree MES-1234
devflow skills install code-review
devflow check
devflow review
devflow review https://github.com/org/repo/pull/42
EOF
}
# ── Review ────────────────────────────────────────────────────────────────────
# _review_fetch_pr_info <url> — fetch PR/MR metadata (title + description)
# Outputs the metadata as formatted text to stdout.
_review_fetch_pr_info() {
local url="$1"
case "$url" in
*github.com/*/pull/*)
gh pr view "$url" --json title,body \
--template '## PR: {{.title}}{{"\n\n"}}{{.body}}' 2>/dev/null || true
;;
*gitlab.com/*/merge_requests/*|*gitlab.*/*/merge_requests/*)
local mr_number project_path
mr_number="${url##*/merge_requests/}"
mr_number="${mr_number%%[?#]*}"
project_path="$(echo "$url" | sed -E 's|https?://[^/]+/||; s|/-/merge_requests/.*||')"
glab mr view "$mr_number" --repo "$project_path" 2>/dev/null \
| head -50 || true
;;
esac
}
# _review_fetch_pr_discussions <url> — fetch ALL discussion threads on a PR/MR.
#
# GOTCHA — pagination: the GitLab `glab api` and GitHub `gh api` endpoints default
# to a small page size (per_page=20 on GitLab, 30 on GitHub). A busy MR/PR easily
# spills onto page 2+ and Claude only sees the first page if you don't pass
# --paginate. This silently truncates the review's view of what's already been
# discussed, leading to re-flagging issues that were already raised + fixed.
#
# This helper always uses --paginate and per_page=100 to minimize round-trips.
# Output is JSON for downstream parsing (jq).
_review_fetch_pr_discussions() {
local url="$1"
case "$url" in
*github.com/*/pull/*)
need_cmd gh
local owner_repo pr_number
pr_number="${url##*/pull/}"
pr_number="${pr_number%%[?#]*}"
owner_repo="$(echo "$url" | sed -E 's|https?://github.com/||; s|/pull/.*||')"
# GitHub: two endpoints — inline review comments + PR-level reviews
gh api --paginate "repos/${owner_repo}/pulls/${pr_number}/comments?per_page=100" \
|| die "Failed to fetch PR inline comments. Check gh auth."
gh api --paginate "repos/${owner_repo}/pulls/${pr_number}/reviews?per_page=100" \
|| die "Failed to fetch PR reviews. Check gh auth."
;;
*gitlab.com/*/merge_requests/*|*gitlab.*/*/merge_requests/*)
need_cmd glab
local mr_number project_path enc_path
mr_number="${url##*/merge_requests/}"
mr_number="${mr_number%%[?#]*}"
project_path="$(echo "$url" | sed -E 's|https?://[^/]+/||; s|/-/merge_requests/.*||')"
enc_path="$(echo "$project_path" | sed 's|/|%2F|g')"
# GitLab's discussions endpoint returns threads with resolved status + position
# data. Prefer over /notes (flat, no resolution status).
glab api --paginate "projects/${enc_path}/merge_requests/${mr_number}/discussions?per_page=100" \
|| die "Failed to fetch MR discussions. Check glab auth."
;;
*)
die "Unsupported URL: $url (expected a GitHub PR or GitLab MR URL)"
;;
esac
}
# _review_diff_from_url <url> — fetch the diff for a PR/MR URL
# Supports GitHub (gh) and GitLab (glab) URLs.
_review_diff_from_url() {
local url="$1"
case "$url" in
*github.com/*/pull/*)
need_cmd gh
gh pr diff "$url" --color=never \
|| die "Failed to fetch PR diff. Check the URL and your gh auth."
;;
*gitlab.com/*/merge_requests/*|*gitlab.*/*/merge_requests/*)
need_cmd glab
local mr_number project_path
mr_number="${url##*/merge_requests/}"
mr_number="${mr_number%%[?#]*}"
project_path="$(echo "$url" | sed -E 's|https?://[^/]+/||; s|/-/merge_requests/.*||')"
glab mr diff "$mr_number" --repo "$project_path" --color=never \
|| die "Failed to fetch MR diff. Check the URL and your glab auth."
;;
*)
die "Unsupported URL: $url (expected a GitHub PR or GitLab MR URL)"
;;
esac
}
# _review_diff_local <project_dir> — get the local working-tree diff
_review_diff_local() {
local proj="$1"
local diff
diff=$(git -C "$proj" diff HEAD 2>/dev/null || git -C "$proj" diff 2>/dev/null || echo "")
if [[ -z "$diff" ]]; then
warn "No uncommitted changes to review."
info "Reviewing staged changes instead..."
diff=$(git -C "$proj" diff --cached 2>/dev/null || echo "")
fi
if [[ -z "$diff" ]]; then
die "No changes to review (no uncommitted or staged changes)."
fi
echo "$diff"
}
devflow_review() {
local url="${1:-}"
if ! has_cmd claude; then
die "Claude Code is not installed. Install from https://claude.ai/download"
fi
local diff source_label system_prompt
local output_format
output_format="Format your response as structured markdown:"
output_format+=" Start with a one-line summary verdict (PASS/FAIL/NEEDS WORK)."
output_format+=" Then list findings grouped by category (## Correctness, ## Naming, ## Architecture, ## Error Handling, ## Security, ## Tests)."
output_format+=" Skip categories with no findings. For each finding, include the file path, line number, severity (critical/warning/nit), and a concrete suggestion."
output_format+=" End with a ## Summary section with overall assessment."
if [[ -n "$url" ]]; then
# ── Remote PR/MR review ────────────────────────────────────────────────
section "Reviewing PR/MR"
log "Fetching PR/MR metadata..."
local pr_info
pr_info="$(_review_fetch_pr_info "$url")"
log "Fetching diff from: $url"
diff="$(_review_diff_from_url "$url")"
source_label="$url"
system_prompt="You are a code reviewer. You will receive a PR/MR diff and the author's PR description."
system_prompt+=" Use the PR description to understand the author's intent, then evaluate whether the diff actually achieves it."
system_prompt+=" Check for: correctness, naming conventions, architecture violations, missing error handling, test coverage gaps, security issues."
system_prompt+=" Be specific and actionable. Reference file names and line numbers from the diff."
system_prompt+=" ${output_format}"
if [[ -n "$pr_info" ]]; then
system_prompt+=" --- PR/MR DESCRIPTION --- ${pr_info}"
fi
else
# ── Local self-review ──────────────────────────────────────────────────
section "Running self-review"
local proj
proj="$(project_root)"
if [[ ! -f "${proj}/CLAUDE.md" ]]; then
die "No CLAUDE.md found in project root. Run 'devflow init' first."
fi
diff="$(_review_diff_local "$proj")"
source_label="local changes"
system_prompt="You are a code reviewer. Review the git diff provided against the project CLAUDE.md conventions."
system_prompt+=" Check for: naming conventions, architecture violations, missing error handling, test coverage gaps."
system_prompt+=" Be specific and actionable. Reference file names and line numbers from the diff."
system_prompt+=" ${output_format}"
fi
log "Invoking Claude Code for review ($source_label)..."
echo "$diff" | claude --print \
--system-prompt "$system_prompt" \
--permission-mode plan \
--allowedTools "Read,Glob,Grep" \
"Review this diff." \
|| die "Claude Code review failed. Make sure Claude Code is installed and authenticated."
}
# ── Dispatch ──────────────────────────────────────────────────────────────────
main() {
local cmd="${1:-help}"
shift || true
case "$cmd" in
init) devflow_init "$@" ;;
up) devflow_up "$@" ;;
down) devflow_down "$@" ;;
restart) devflow_restart "$@" ;;
status) devflow_status "$@" ;;
check) devflow_check "$@" ;;
deps) devflow_deps "$@" ;;
skills) devflow_skills "$@" ;;
seed) devflow_seed "$@" ;;
done) devflow_done "$@" ;;
clean) devflow_clean "$@" ;;
worktree) devflow_worktree "$@" ;;
review) devflow_review "$@" ;;
watch) devflow_watch "$@" ;;
check-version) check_version_consistency "$(project_root)" ;;
version-bump) devflow_version_bump "$@" ;;
release) devflow_release_preview "$@" ;;
visualizations|viz) devflow_visualizations "$@" ;;
root) devflow_root "$@" ;;
version) echo "devflow v${DEVFLOW_VERSION}" ;;
help|-h|--help) usage ;;
*) err "Unknown command: $cmd"; usage; exit 1 ;;
esac
}
main "$@"