-
-
Notifications
You must be signed in to change notification settings - Fork 562
Expand file tree
/
Copy pathflow.toml
More file actions
309 lines (289 loc) · 8.9 KB
/
flow.toml
File metadata and controls
309 lines (289 loc) · 8.9 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
299
300
301
302
303
304
305
306
307
308
309
version = 1
name = "go"
[deps]
go = "go"
[[tasks]]
name = "default"
description = "List available tasks."
command = '''
cat <<'EOF'
Available tasks:
- setup Ensure Go is installed and download Flow CLI dependencies.
- flow [args...] Build a temp fgo binary and run it with forwarded args.
- dev [args...] Alias for flow.
- run [args...] Alias for flow.
- spec [args...] Build a temp spec binary and run it (copies prompt to clipboard by default).
- spec-print <file> Generate prompt to stdout without touching clipboard.
- spec-deploy Build/install spec to ~/bin/spec.
- deploy [name] Build/install to ~/bin. Default: fgo (with fe alias). Use "fm" for moonbit.
EOF
'''
[[tasks]]
name = "setup"
description = "Ensure Go is installed and download Flow CLI dependencies."
dependencies = ["go"]
command = '''
set -euo pipefail
if ! command -v go >/dev/null 2>&1; then
echo "Go toolchain 'go' not found in PATH."
echo "Install it from https://go.dev/doc/install"
exit 1
fi
go version >/dev/null
repo_root="$PWD"
pushd cli/flow >/dev/null
export GOCACHE="${GOCACHE:-$repo_root/.gocache}"
export GOMODCACHE="${GOMODCACHE:-$repo_root/.gomodcache}"
mkdir -p "$GOCACHE"
mkdir -p "$GOMODCACHE"
if ! go mod download >/dev/null; then
echo "Warning: unable to download Go modules; try again once network access is available."
fi
popd >/dev/null
pushd cli/spec >/dev/null
if ! go mod download >/dev/null; then
echo "Warning: unable to download spec CLI Go modules; try again once network access is available."
fi
popd >/dev/null
echo "✔️ you are setup"
'''
[[tasks]]
name = "flow"
description = "Run the fgo CLI (passes CLI args through)."
dependencies = ["go"]
command = '''
set -euo pipefail
repo_root="$PWD"
tmp_root="${TMPDIR:-/tmp}"
tmp_dir="$(mktemp -d "$tmp_root/fgo-task-XXXXXX")"
trap 'rm -rf "$tmp_dir"' EXIT
pushd cli/flow >/dev/null
export GOCACHE="${GOCACHE:-$repo_root/.gocache}"
export GOMODCACHE="${GOMODCACHE:-$repo_root/.gomodcache}"
mkdir -p "$GOCACHE"
mkdir -p "$GOMODCACHE"
go build -o "$tmp_dir/fgo" .
popd >/dev/null
"$tmp_dir/fgo" "$@"
'''
[[tasks]]
name = "dev"
description = "Alias for flow."
dependencies = ["go"]
command = '''
set -euo pipefail
repo_root="$PWD"
tmp_root="${TMPDIR:-/tmp}"
tmp_dir="$(mktemp -d "$tmp_root/fgo-task-XXXXXX")"
trap 'rm -rf "$tmp_dir"' EXIT
pushd cli/flow >/dev/null
export GOCACHE="${GOCACHE:-$repo_root/.gocache}"
export GOMODCACHE="${GOMODCACHE:-$repo_root/.gomodcache}"
mkdir -p "$GOCACHE"
mkdir -p "$GOMODCACHE"
go build -o "$tmp_dir/fgo" .
popd >/dev/null
"$tmp_dir/fgo" "$@"
'''
[[tasks]]
name = "run"
description = "Alias for flow."
dependencies = ["go"]
command = '''
set -euo pipefail
repo_root="$PWD"
tmp_root="${TMPDIR:-/tmp}"
tmp_dir="$(mktemp -d "$tmp_root/fgo-task-XXXXXX")"
trap 'rm -rf "$tmp_dir"' EXIT
pushd cli/flow >/dev/null
export GOCACHE="${GOCACHE:-$repo_root/.gocache}"
export GOMODCACHE="${GOMODCACHE:-$repo_root/.gomodcache}"
mkdir -p "$GOCACHE"
mkdir -p "$GOMODCACHE"
go build -o "$tmp_dir/fgo" .
popd >/dev/null
"$tmp_dir/fgo" "$@"
'''
[[tasks]]
name = "spec"
description = "Run the spec CLI (passes CLI args through)."
dependencies = ["go"]
command = '''
set -euo pipefail
repo_root="$PWD"
tmp_root="${TMPDIR:-/tmp}"
tmp_dir="$(mktemp -d "$tmp_root/spec-task-XXXXXX")"
trap 'rm -rf "$tmp_dir"' EXIT
pushd cli/spec >/dev/null
export GOCACHE="${GOCACHE:-$repo_root/.gocache}"
export GOMODCACHE="${GOMODCACHE:-$repo_root/.gomodcache}"
mkdir -p "$GOCACHE"
mkdir -p "$GOMODCACHE"
go build -o "$tmp_dir/spec" .
popd >/dev/null
"$tmp_dir/spec" "$@"
'''
[[tasks]]
name = "spec-print"
description = "Generate a prompt from a markdown spec and print to stdout."
dependencies = ["go"]
command = '''
set -euo pipefail
if [ "$#" -lt 1 ]; then
echo "Usage: f spec-print <path-to-spec.md>"
exit 1
fi
repo_root="$PWD"
tmp_root="${TMPDIR:-/tmp}"
tmp_dir="$(mktemp -d "$tmp_root/spec-task-XXXXXX")"
trap 'rm -rf "$tmp_dir"' EXIT
pushd cli/spec >/dev/null
export GOCACHE="${GOCACHE:-$repo_root/.gocache}"
export GOMODCACHE="${GOMODCACHE:-$repo_root/.gomodcache}"
mkdir -p "$GOCACHE"
mkdir -p "$GOMODCACHE"
go build -o "$tmp_dir/spec" .
popd >/dev/null
"$tmp_dir/spec" "$@" --stdout --no-clipboard
'''
[[tasks]]
name = "spec-deploy"
description = "Build the spec CLI and install it to ~/bin/spec."
dependencies = ["go"]
command = '''
set -euo pipefail
repo_root="$PWD"
install_dir="$HOME/bin"
mkdir -p "$install_dir"
pushd cli/spec >/dev/null
export GOCACHE="${GOCACHE:-$repo_root/.gocache}"
export GOMODCACHE="${GOMODCACHE:-$repo_root/.gomodcache}"
mkdir -p "$GOCACHE"
mkdir -p "$GOMODCACHE"
tmp_root="${TMPDIR:-/tmp}"
tmp_dir="$(mktemp -d "$tmp_root/spec-install-XXXXXX")"
trap 'rm -rf "$tmp_dir"' EXIT
go build -o "$tmp_dir/spec" .
popd >/dev/null
install_path="$install_dir/spec"
mv "$tmp_dir/spec" "$install_path"
chmod 755 "$install_path"
echo "Installed CLI to $install_path"
'''
[[tasks]]
name = "deploy"
description = "Build the fgo CLI binary, install it to ~/bin as fgo, and optionally add ~/bin to PATH for your shell."
dependencies = ["go"]
command = '''
set -euo pipefail
repo_root="$PWD"
install_dir="$HOME/bin"
# Default to fgo with fe alias, or use fm (no alias) if "fm" is passed
if [ "${1:-}" = "fm" ]; then
command_name="fm"
alias_name=""
else
command_name="fgo"
alias_name="fe"
fi
mkdir -p "$install_dir"
pushd cli/flow >/dev/null
export GOCACHE="${GOCACHE:-$repo_root/.gocache}"
export GOMODCACHE="${GOMODCACHE:-$repo_root/.gomodcache}"
mkdir -p "$GOCACHE"
mkdir -p "$GOMODCACHE"
tmp_root="${TMPDIR:-/tmp}"
tmp_dir="$(mktemp -d "$tmp_root/fgo-install-XXXXXX")"
trap 'rm -rf "$tmp_dir"' EXIT
go build -o "$tmp_dir/$command_name" .
popd >/dev/null
install_path="$install_dir/$command_name"
mv "$tmp_dir/$command_name" "$install_path"
chmod 755 "$install_path"
rm -rf "$tmp_dir"
echo "Installed CLI to $install_path"
if [ -n "$alias_name" ]; then
ln -sf "$install_path" "$install_dir/$alias_name"
if [ "$alias_name" = "$command_name" ]; then
echo "Ensured $install_dir/$alias_name points to $install_path"
else
echo "Created symlink $install_dir/$alias_name -> $install_path"
fi
fi
help_snapshot="$("$install_path" --help 2>&1 || true)"
notes=$(printf 'Running `%s` without any arguments opens an embedded fzf palette so you can fuzzy-search commands and read their descriptions before executing them.\n\nFor `%s commit`, export `OPENAI_API_KEY` in your shell profile (e.g. fish config) so the CLI can talk to OpenAI. This environment variable is the only requirement, so the command works in local shells and CI alike.\n\nFor `%s youtubeToSound`, the CLI automatically passes `--cookies-from-browser` using Safari cookies. Override this by setting `FLOW_YOUTUBE_COOKIES_BROWSER` (e.g. `firefox`), set it to `none` to skip cookies entirely, or pass your own `--cookies*` flags after the URL—they are forwarded directly to `yt-dlp`.\n\nIf you run `%s youtubeToSound` without arguments, the command grabs the frontmost Safari tab URL automatically.' \
"$command_name" "$command_name" "$command_name" "$command_name")
alias_note=""
if [ -n "$alias_name" ]; then
alias_note=$(printf 'A shorthand `%s` alias is installed alongside `%s`; update or remove the symlink at ~/bin/%s if you prefer a different name.' \
"$alias_name" "$command_name" "$alias_name")
notes=$(printf '%s\n\n%s' "$notes" "$alias_note")
fi
{
echo "# $command_name"
echo
printf '```\n%s --help\n' "$command_name"
printf '%s\n' "$help_snapshot"
printf '```\n\n'
echo '## Notes'
echo
printf '%s\n' "$notes"
} > "$repo_root/cli/flow/readme.md"
case ":${PATH:-}:" in
*:"$install_dir":*)
echo "$install_dir already present in PATH"
exit 0
;;
esac
shell_name="$(basename "${SHELL:-}")"
marker="# >>> ${command_name} initialize >>>"
end_marker="# <<< ${command_name} initialize <<<"
target=""
snippet=""
case "$shell_name" in
fish)
target="$HOME/.config/fish/conf.d/${command_name}.fish"
snippet='fish_add_path $HOME/bin'
;;
zsh)
target="$HOME/.zshrc"
snippet='export PATH="$HOME/bin:$PATH"'
;;
bash)
target="$HOME/.bashrc"
snippet='export PATH="$HOME/bin:$PATH"'
;;
*)
echo "$install_dir is not on PATH. Add it to your shell configuration manually."
exit 0
;;
esac
if [ -n "$target" ] && [ -f "$target" ] && grep -F "$marker" "$target" >/dev/null 2>&1; then
echo "$install_dir already configured via $target"
exit 0
fi
printf 'Add %s to PATH in %s? [y/N]: ' "$install_dir" "${target:-manual}"
read -r reply || reply=""
case "$reply" in
[yY]*)
mkdir -p "$(dirname "$target")"
if [ "$shell_name" = "fish" ]; then
{
echo "$marker"
echo "$snippet"
echo "$end_marker"
} > "$target"
else
{
printf '\n%s\n' "$marker"
printf '%s\n' "$snippet"
printf '%s\n' "$end_marker"
} >> "$target"
fi
echo "Updated $target. Restart your shell or source the file to use $command_name."
;;
*)
echo "Skipped PATH update. Add $install_dir to PATH manually if needed."
;;
esac
'''