bendit 0.3.0__py3-none-any.whl

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.
bendit/__init__.py ADDED
File without changes
bendit/__main__.py ADDED
@@ -0,0 +1,16 @@
1
+ """Run the bundled install.sh, passing every argument through."""
2
+ import os
3
+ import sys
4
+
5
+
6
+ def main():
7
+ path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "install.sh")
8
+ try:
9
+ os.execvp("bash", ["bash", path] + sys.argv[1:])
10
+ except FileNotFoundError:
11
+ print("bendit needs bash, and it was not found on PATH.", file=sys.stderr)
12
+ sys.exit(2)
13
+
14
+
15
+ if __name__ == "__main__":
16
+ main()
bendit/install.sh ADDED
@@ -0,0 +1,566 @@
1
+ #!/usr/bin/env bash
2
+ # bendit installer. Meant to be piped from curl, so a dropped connection can hand
3
+ # bash HALF this file: every statement below lives in a function, and the only
4
+ # top-level call is the last line, `main "$@"`. A truncated copy defines some
5
+ # functions and runs nothing.
6
+ #
7
+ # Exit codes: 0 ready (or --check found nothing missing); 1 something required
8
+ # is missing or failed; 2 usage error, refused location, unsupported OS.
9
+ set -u
10
+ ASK_OPEN="" # never inherited: a caller must not choose which fd ask() reads
11
+ ASKED="
12
+ " # install commands already offered, one per line
13
+ CLT_MISSING=0
14
+
15
+ BENDIT_VERSION="0.3.0"
16
+ # The major of Playwright's own engines.node floor (plugins/bendit/lib/drive/
17
+ # package.json): the browser driver cannot run on less. drive.test.sh checks it.
18
+ NODE_MIN=20
19
+
20
+ say() { printf '%s\n' "$*"; }
21
+
22
+ # die <code> <text>
23
+ die() {
24
+ local code="$1"; shift
25
+ printf '%s\n' "$*" >&2
26
+ exit "$code"
27
+ }
28
+
29
+ usage() {
30
+ say "bendit installer $BENDIT_VERSION"
31
+ say ""
32
+ say "Usage: install.sh [--check | --version | --help]"
33
+ say ""
34
+ say " --check report what is missing; install nothing"
35
+ say " --version print the installer version"
36
+ say " --help print this help"
37
+ }
38
+
39
+ check_os() {
40
+ local os
41
+ os="$(uname -s)"
42
+ case "$os" in
43
+ Darwin|Linux) ;;
44
+ MINGW*|MSYS*|CYGWIN*) die 2 "Windows is not supported yet." ;;
45
+ *) die 2 "Unsupported system: $os. bendit installs on macOS and Linux." ;;
46
+ esac
47
+ }
48
+
49
+ # Running from $HOME or / would make the whole machine "the project".
50
+ check_location() {
51
+ local here home
52
+ here="$(pwd -P)"
53
+ home="$(cd "$HOME" 2>/dev/null && pwd -P)" || home=""
54
+ if [ "$here" = "/" ] || { [ -n "$home" ] && [ "$here" = "$home" ]; }; then
55
+ die 2 "Run this from inside a project folder, not from $here."
56
+ fi
57
+ }
58
+
59
+ # ver_ge <found> <min> -- 0 when found >= min, compared numerically field by field.
60
+ ver_ge() {
61
+ local a="${1#v}" b="${2#v}" x y
62
+ while [ -n "$a" ] || [ -n "$b" ]; do
63
+ x="${a%%.*}"; y="${b%%.*}"
64
+ case "$a" in *.*) a="${a#*.}" ;; *) a="" ;; esac
65
+ case "$b" in *.*) b="${b#*.}" ;; *) b="" ;; esac
66
+ x="${x//[!0-9]/}"; y="${y//[!0-9]/}"
67
+ x="${x:-0}"; y="${y:-0}"
68
+ [ "$((10#$x))" -gt "$((10#$y))" ] && return 0
69
+ [ "$((10#$x))" -lt "$((10#$y))" ] && return 1
70
+ done
71
+ return 0
72
+ }
73
+
74
+ # Google Chrome, on PATH or as an app bundle. BENDIT_APP_DIRS (space
75
+ # separated) overrides the app folders searched. Chromium does NOT count: the
76
+ # browser driver launches Playwright channels (chrome, msedge, ...), none of
77
+ # which is a system Chromium, so a Chromium-only machine cannot be driven.
78
+ find_chrome() {
79
+ local c d
80
+ for c in google-chrome google-chrome-stable; do
81
+ command -v "$c" >/dev/null 2>&1 && return 0
82
+ done
83
+ if [ -n "${BENDIT_APP_DIRS:-}" ]; then
84
+ for d in $BENDIT_APP_DIRS; do
85
+ [ -e "$d/Google Chrome.app" ] && return 0
86
+ done
87
+ else
88
+ for d in /Applications "$HOME/Applications"; do
89
+ [ -e "$d/Google Chrome.app" ] && return 0
90
+ done
91
+ fi
92
+ return 1
93
+ }
94
+
95
+ # 0 when ./package.json names a web framework as a dependency key, or ./index.html
96
+ # exists. Read-only. With python3 >= 3.9 the JSON is parsed properly; without it
97
+ # the check is a grep for "<name>": anywhere in the file, which is approximate (a
98
+ # nested key of the same name would count).
99
+ is_web_project() {
100
+ local names="next react vue svelte @sveltejs/kit nuxt astro vite @angular/core solid-js @remix-run/react"
101
+ local n pv hit=""
102
+ [ -e ./index.html ] && return 0
103
+ [ -f ./package.json ] || return 1
104
+ pv="$(python_version)"
105
+ if [ -n "$pv" ] && ver_ge "$pv" 3.9; then
106
+ if hit="$(python3 -I -c '
107
+ import json, sys
108
+ names = sys.argv[1:]
109
+ d = json.load(open("package.json"))
110
+ keys = set()
111
+ for k in ("dependencies", "devDependencies"):
112
+ v = d.get(k)
113
+ if isinstance(v, dict):
114
+ keys.update(v)
115
+ for n in names:
116
+ if n in keys:
117
+ print(n)
118
+ break
119
+ ' $names 2>/dev/null)"; then
120
+ # Only a name from the list counts; anything else printed is not an answer.
121
+ case " $names " in *" $hit "*) [ -n "$hit" ] && return 0 ;; esac
122
+ return 1
123
+ fi
124
+ fi
125
+ for n in $names; do
126
+ grep -q "\"$n\"[[:space:]]*:" ./package.json 2>/dev/null && return 0
127
+ done
128
+ return 1
129
+ }
130
+
131
+ python_version() {
132
+ command -v python3 >/dev/null 2>&1 || return 0
133
+ apple_stub python3 && return 0
134
+ python3 -I -c 'import sys;print("%d.%d.%d"%sys.version_info[:3])' 2>/dev/null | head -n 1
135
+ }
136
+
137
+ # apple_stub <tool> -- 0 when <tool> is macOS's stub in /usr/bin and the Command
138
+ # Line Tools are missing, so running it would open Apple's install dialog.
139
+ # BENDIT_APPLE_SHIMS (a test hook) names the folder the stubs live in.
140
+ apple_stub() {
141
+ [ "${CLT_MISSING:-0}" = 1 ] || return 1
142
+ [ "$(command -v "$1")" = "${BENDIT_APPLE_SHIMS:-/usr/bin}/$1" ]
143
+ }
144
+
145
+ # row <item> <found-or-empty> <needed> <ok 0|1> <why>
146
+ row() {
147
+ local mark="✓" found="$2"
148
+ printf -v "FOUND_$1" '%s' "$2"
149
+ printf -v "NEED_$1" '%s' "$3"
150
+ [ "$4" = 0 ] || mark="✗"
151
+ [ -n "$found" ] || found="missing"
152
+ printf '%s %-8s %-9s %-7s %s\n' "$mark" "$1" "$found" "$3" "$5"
153
+ }
154
+
155
+ # Sets MISSING_REQUIRED and MISSING_WEB (space-separated item names) and prints
156
+ # the table.
157
+ check_machine() {
158
+ local v ok web=0
159
+ MISSING_REQUIRED=""; MISSING_WEB=""
160
+ # Before anything runs git or python3: on a Mac without the Command Line Tools
161
+ # both are stubs that open Apple's install dialog each time they run.
162
+ CLT_MISSING=0
163
+ if [ "$(uname -s)" = Darwin ] && command -v xcode-select >/dev/null 2>&1 \
164
+ && ! xcode-select -p >/dev/null 2>&1; then
165
+ CLT_MISSING=1
166
+ fi
167
+ is_web_project && web=1
168
+ say " item found needed why"
169
+
170
+ v=""; ok=1
171
+ if command -v claude >/dev/null 2>&1; then
172
+ v="$(claude --version 2>/dev/null | head -n 1 | cut -d' ' -f1)"; ok=0; [ -n "$v" ] || v="found"
173
+ fi
174
+ row claude "$v" any "$ok" "runs the agent bendit plugs into"
175
+ [ "$ok" = 0 ] || MISSING_REQUIRED="$MISSING_REQUIRED claude"
176
+
177
+ v=""; ok=1
178
+ if command -v git >/dev/null 2>&1; then
179
+ if apple_stub git; then
180
+ v="stub only"
181
+ elif git --version >/dev/null 2>&1; then
182
+ ok=0; v="found"
183
+ else
184
+ v="found but did not run"
185
+ fi
186
+ fi
187
+ row git "$v" any "$ok" "reads and records your changes"
188
+ [ "$ok" = 0 ] || MISSING_REQUIRED="$MISSING_REQUIRED git"
189
+
190
+ v="$(python_version)"; ok=1
191
+ [ -n "$v" ] && ver_ge "$v" 3.9 && ok=0
192
+ if [ -z "$v" ] && command -v python3 >/dev/null 2>&1; then
193
+ if apple_stub python3; then v="stub only"; else v="found but did not run"; fi
194
+ fi
195
+ row python3 "$v" "3.9+" "$ok" "runs bendit's guards"
196
+ [ "$ok" = 0 ] || MISSING_REQUIRED="$MISSING_REQUIRED python3"
197
+
198
+ if [ "$web" = 1 ]; then
199
+ v=""; ok=1
200
+ if command -v node >/dev/null 2>&1; then
201
+ v="$(node --version 2>/dev/null | head -n 1)"; v="${v#v}"
202
+ [ -n "$v" ] && ver_ge "$v" "$NODE_MIN" && ok=0
203
+ fi
204
+ row node "$v" "$NODE_MIN+" "$ok" "drives the browser for a web app"
205
+ [ "$ok" = 0 ] || MISSING_WEB="$MISSING_WEB node"
206
+
207
+ ok=1; v=""
208
+ if find_chrome; then ok=0; v="found"; fi
209
+ row chrome "$v" any "$ok" "the browser bendit looks at your app with"
210
+ [ "$ok" = 0 ] || MISSING_WEB="$MISSING_WEB chrome"
211
+ fi
212
+ MISSING_REQUIRED="${MISSING_REQUIRED# }"; MISSING_WEB="${MISSING_WEB# }"
213
+ return 0
214
+ }
215
+
216
+ # ask <question> -- 0 only for y/yes, read from the terminal (BENDIT_TTY is a
217
+ # test hook), never from stdin: stdin may be the script itself, piped from curl.
218
+ # 1 for anything else; 3 when there is no terminal to ask on.
219
+ ask() {
220
+ local a=""
221
+ have_tty || return 3
222
+ [ -n "${ASK_OPEN:-}" ] || { exec 3< "${BENDIT_TTY:-/dev/tty}"; ASK_OPEN=1; }
223
+ printf '%s' "$1"
224
+ IFS= read -r a <&3 || a=""
225
+ case "$a" in [Yy]|[Yy][Ee][Ss]) return 0 ;; esac
226
+ return 1
227
+ }
228
+
229
+ # 0 when the terminal can be opened for reading.
230
+ have_tty() { ( : < "${BENDIT_TTY:-/dev/tty}" ) 2>/dev/null; }
231
+
232
+ # install_cmd <item> -- the command for this machine, or nothing.
233
+ install_cmd() {
234
+ local item="$1" pm="" s
235
+ if [ "$item" = claude ]; then
236
+ command -v curl >/dev/null 2>&1 && say 'curl -fsSL https://claude.ai/install.sh | bash'
237
+ return 0
238
+ fi
239
+ case "$(uname -s)" in
240
+ Darwin)
241
+ # brew itself needs the Command Line Tools, and they bring git and python3.
242
+ if [ "${CLT_MISSING:-0}" = 1 ]; then
243
+ case "$item" in git|python3) say 'xcode-select --install'; return 0 ;; esac
244
+ fi
245
+ command -v brew >/dev/null 2>&1 || return 0
246
+ case "$item" in
247
+ python3) say 'brew install python@3.13' ;;
248
+ git) say 'brew install git' ;;
249
+ node) say 'brew install node' ;;
250
+ chrome) say 'brew install --cask google-chrome' ;;
251
+ esac ;;
252
+ Linux)
253
+ for pm in apt-get dnf pacman; do command -v "$pm" >/dev/null 2>&1 && break; pm=""; done
254
+ [ -n "$pm" ] || return 0
255
+ # root needs no sudo; anyone else without sudo (a container) gets no route.
256
+ if command -v id >/dev/null 2>&1 && [ "$(id -u)" = 0 ]; then
257
+ s=""
258
+ elif command -v sudo >/dev/null 2>&1; then
259
+ s="sudo "
260
+ else
261
+ return 0
262
+ fi
263
+ # apt's own nodejs is older than NODE_MIN (18 on Ubuntu 24.04 and Debian
264
+ # 12, 12 on 22.04), and dnf's can be too (RHEL, Rocky and Alma streams),
265
+ # so neither is a route for node. A fresh image has no package lists
266
+ # until apt-get update. pacman -Sy without -u is a partial upgrade, which
267
+ # Arch does not support, so pacman installs from the database as it is.
268
+ case "$pm:$item" in
269
+ apt-get:python3) say "${s}apt-get update && ${s}apt-get install -y python3" ;;
270
+ apt-get:git) say "${s}apt-get update && ${s}apt-get install -y git" ;;
271
+ dnf:python3) say "${s}dnf install -y python3" ;;
272
+ dnf:git) say "${s}dnf install -y git" ;;
273
+ pacman:python3) say "${s}pacman -S --needed --noconfirm python" ;;
274
+ pacman:git) say "${s}pacman -S --needed --noconfirm git" ;;
275
+ pacman:node) say "${s}pacman -S --needed --noconfirm nodejs" ;;
276
+ esac ;;
277
+ esac
278
+ return 0
279
+ }
280
+
281
+ manual_pointer() {
282
+ case "$1" in
283
+ python3) say "Get Python 3.9 or newer from https://www.python.org/downloads/" ;;
284
+ git) say "Get git from https://git-scm.com/downloads" ;;
285
+ node)
286
+ say "Get Node.js $NODE_MIN or newer from https://nodejs.org/ (or with nvm)."
287
+ if [ "$(uname -s)" = Linux ]; then
288
+ if command -v apt-get >/dev/null 2>&1; then
289
+ say " apt's own nodejs is older than $NODE_MIN; NodeSource's packages are new enough."
290
+ elif command -v dnf >/dev/null 2>&1; then
291
+ say " dnf's own nodejs can be older than $NODE_MIN; NodeSource's packages are new enough."
292
+ fi
293
+ fi ;;
294
+ chrome) say "Get Chrome from https://www.google.com/chrome/" ;;
295
+ claude) say "See https://code.claude.com/docs/en/setup" ;;
296
+ esac
297
+ }
298
+
299
+ # pacman_hint <cmd> [failed] -- a pacman install can fail on a stale database;
300
+ # bendit never upgrades the system for you, so it says how.
301
+ pacman_hint() {
302
+ case "$1" in *pacman\ *) ;; *) return 0 ;; esac
303
+ local s="" # the prefix the install command itself used (empty for root)
304
+ case "$1" in "sudo "*) s="sudo " ;; esac
305
+ if [ -n "${2:-}" ]; then
306
+ say " Run \`${s}pacman -Syu\` yourself first (a stale package database), then run this again."
307
+ else
308
+ say " (if this fails, run \`${s}pacman -Syu\` yourself first)"
309
+ fi
310
+ }
311
+
312
+ why_missing() {
313
+ local var="FOUND_$1"
314
+ if [ "${!var:-}" = "stub only" ]; then
315
+ say "$1 is only Apple's stub until the Command Line Tools are installed."
316
+ return 0
317
+ fi
318
+ case "$1" in
319
+ python3) say "python3 is missing or older than 3.9 (it runs bendit's guards)." ;;
320
+ node) say "node is missing or older than $NODE_MIN (it drives the browser for a web app)." ;;
321
+ chrome) say "Chrome is missing (the browser bendit looks at your app with)." ;;
322
+ git) say "git is missing or does not run (it reads and records your changes)." ;;
323
+ claude) say "claude is missing (the agent bendit plugs into)." ;;
324
+ esac
325
+ }
326
+
327
+ # is_missing <item> -- re-runs the machine check quietly.
328
+ is_missing() {
329
+ check_machine >/dev/null
330
+ case " $MISSING_REQUIRED $MISSING_WEB " in *" $1 "*) return 0 ;; esac
331
+ return 1
332
+ }
333
+
334
+ # offer <item> -- 0 installed and verified, 1 declined or no automatic route,
335
+ # 2 the install ran but the item is still missing, 3 no terminal.
336
+ offer() {
337
+ local item="$1" cmd rc tool now need added=0 var
338
+ cmd="$(install_cmd "$item")"
339
+ why_missing "$item"
340
+ # One command can serve two items (xcode-select --install brings git and
341
+ # python3): ask once.
342
+ case "$ASKED" in *"
343
+ $cmd
344
+ "*)
345
+ [ -n "$cmd" ] && { say " That is the same install as above."; return 1; } ;;
346
+ esac
347
+ ASKED="$ASKED$cmd
348
+ "
349
+ if [ -z "$cmd" ]; then
350
+ say " bendit cannot install it automatically here. $(manual_pointer "$item")"
351
+ return 1
352
+ fi
353
+ say " To install it, bendit would run:"
354
+ say " $cmd"
355
+ ask " Run that now? [y/N] "; rc=$?
356
+ [ "$rc" = 3 ] && return 3
357
+ say ""
358
+ [ "$rc" = 0 ] || return 1
359
+ # pipefail: a failed download in `curl ... | bash` is a failure, not bash's
360
+ # 0. fd 3 is the terminal ask() reads; the command does not get it.
361
+ ( set -o pipefail; eval "$cmd" ) < /dev/null 3<&-; rc=$?
362
+ # claude installs to ~/.local/bin, which a fresh machine may not have on PATH yet.
363
+ if [ "$item" = claude ]; then
364
+ case ":$PATH:" in *":$HOME/.local/bin:"*) ;; *) PATH="$HOME/.local/bin:$PATH"; added=1 ;; esac
365
+ fi
366
+ hash -r 2>/dev/null
367
+ if ! is_missing "$item"; then
368
+ say " $item is ready."
369
+ if [ "$added" = 1 ] && [ "$(command -v claude)" = "$HOME/.local/bin/claude" ]; then
370
+ say " claude is in ~/.local/bin, which this shell's PATH lacks: open a new terminal"
371
+ say " (or add ~/.local/bin to PATH) before you run claude yourself."
372
+ fi
373
+ return 0
374
+ fi
375
+ if [ "$cmd" = "xcode-select --install" ]; then
376
+ say " Apple's installer has opened in its own window."
377
+ say " When Apple's installer finishes, run this again."
378
+ return 2
379
+ fi
380
+ tool="${cmd#sudo }"; tool="${tool%% *}"
381
+ var="FOUND_$item"; now="${!var:-}"; var="NEED_$item"; need="${!var:-}"
382
+ if [ "$rc" != 0 ]; then
383
+ say " The install command failed (exit $rc), and $item is still not ready."
384
+ pacman_hint "$cmd" failed
385
+ elif [ -z "$now" ]; then
386
+ say " $tool said it worked, but $item is still not found."
387
+ elif [ "$now" = "found but did not run" ] || [ "$now" = "stub only" ]; then
388
+ say " $tool said it worked, but $item still does not run."
389
+ else
390
+ say " $tool said it worked, but $item is still $now; bendit needs $need."
391
+ fi
392
+ return 2
393
+ }
394
+
395
+ # Nothing can be asked: list what is missing and the commands, install nothing.
396
+ no_terminal() {
397
+ local item cmd all="$MISSING_REQUIRED $MISSING_WEB"
398
+ all="${all# }"; all="${all% }"
399
+ say ""
400
+ say "Missing: $all"
401
+ for item in $all; do
402
+ cmd="$(install_cmd "$item")"
403
+ if [ -n "$cmd" ]; then say " $item: $cmd"; pacman_hint "$cmd"; else say " $item: $(manual_pointer "$item")"; fi
404
+ done
405
+ say "There is no terminal to ask on, so nothing was installed. Run the commands"
406
+ say "above yourself, or run this installer from a terminal."
407
+ exit 1
408
+ }
409
+
410
+ # Asks about every missing item; installs only after a yes; re-checks each.
411
+ install_missing() {
412
+ local item rc blocked="" web_off=""
413
+ have_tty || no_terminal
414
+ for item in $MISSING_REQUIRED; do
415
+ say ""
416
+ offer "$item"; rc=$?
417
+ [ "$rc" = 3 ] && no_terminal
418
+ [ "$rc" = 0 ] || blocked="$blocked $item"
419
+ done
420
+ if [ -n "$blocked" ]; then
421
+ say ""
422
+ for item in $blocked; do say "$item is required, so bendit cannot go on without it."; done
423
+ say "Install it, then run this again."
424
+ exit 1
425
+ fi
426
+ for item in $MISSING_WEB; do
427
+ say ""
428
+ offer "$item"; rc=$?
429
+ [ "$rc" = 3 ] && no_terminal
430
+ [ "$rc" = 0 ] || web_off="$web_off $item"
431
+ done
432
+ if [ -n "$web_off" ]; then
433
+ say ""
434
+ say "Skipping${web_off}: the browser driver will be off, so bendit cannot look at"
435
+ say "your web app until that is installed. Everything else will work."
436
+ fi
437
+ return 0
438
+ }
439
+
440
+ # fetch_kit -- prints the plugin directory, cloning bendit into the cache first
441
+ # unless a good clone of this version is already there. The clone lands in a temp
442
+ # folder inside the cache and is moved into place, so a failed or interrupted
443
+ # fetch never leaves a half-made v<version> folder.
444
+ fetch_kit() {
445
+ local cache dir src ref tmp out
446
+ cache="${BENDIT_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/bendit}"
447
+ dir="$cache/v$BENDIT_VERSION"
448
+ src="${BENDIT_SOURCE:-https://github.com/VedangP57/bendit.git}"
449
+ ref="${BENDIT_REF:-v$BENDIT_VERSION}"
450
+ # git -C walks up into a parent repository, so .git must be in dir itself, and
451
+ # the plugin must really be there.
452
+ if [ -d "$dir/.git" ] && [ -f "$dir/plugins/bendit/.claude-plugin/plugin.json" ] \
453
+ && git -C "$dir" rev-parse --verify HEAD >/dev/null 2>&1; then
454
+ say "$dir/plugins/bendit"
455
+ return 0
456
+ fi
457
+ rm -rf "$dir"
458
+ mkdir -p "$cache" || { printf '%s\n' "could not create $cache" >&2; return 1; }
459
+ tmp="$(mktemp -d "$cache/.fetch.XXXXXX")" || { printf '%s\n' "could not create a temporary folder in $cache" >&2; return 1; }
460
+ # git's own chatter (detached HEAD advice, local-clone depth warning) is noise
461
+ # unless the clone fails, and then it is the reason.
462
+ if ! out="$(git -c advice.detachedHead=false clone --quiet --depth 1 --branch "$ref" "$src" "$tmp/kit" </dev/null 2>&1)"; then
463
+ rm -rf "$tmp"
464
+ [ -z "$out" ] || printf '%s\n' "$out" >&2
465
+ printf '%s\n' "could not fetch bendit from $src ($ref)." >&2
466
+ return 1
467
+ fi
468
+ if ! mv "$tmp/kit" "$dir"; then
469
+ rm -rf "$tmp"
470
+ printf '%s\n' "could not move bendit into $cache." >&2
471
+ return 1
472
+ fi
473
+ rm -rf "$tmp"
474
+ say "$dir/plugins/bendit"
475
+ }
476
+
477
+ # handover_stdin -- sets HANDOVER_STDIN to where claude should read its input:
478
+ # empty means "leave stdin alone" (it already is the terminal); otherwise a path.
479
+ # Under `curl | bash` stdin is the script pipe, so claude needs the terminal
480
+ # explicitly -- and the real device (/dev/ttys003), not the /dev/tty alias:
481
+ # macOS kqueue cannot watch /dev/tty, and a Bun claude dies with EINVAL on it.
482
+ # Sets a variable instead of printing: a command substitution would hide the
483
+ # terminal on stdout.
484
+ handover_stdin() {
485
+ local dev=""
486
+ HANDOVER_STDIN=""
487
+ if [ -n "${BENDIT_TTY:-}" ]; then HANDOVER_STDIN="$BENDIT_TTY"; return 0; fi
488
+ [ -t 0 ] && return 0
489
+ if [ -t 2 ]; then dev="$(tty 0<&2 2>/dev/null)"
490
+ elif [ -t 1 ]; then dev="$(tty 0<&1 2>/dev/null)"; fi
491
+ if [ -n "$dev" ] && [ "$dev" != "not a tty" ] && [ -c "$dev" ]; then
492
+ HANDOVER_STDIN="$dev"
493
+ else
494
+ HANDOVER_STDIN=/dev/tty
495
+ fi
496
+ return 0
497
+ }
498
+
499
+ # hand_over <plugin-dir> -- with a terminal, becomes claude running /bendit:adopt (its
500
+ # input is the terminal, not the script a curl pipe may be feeding stdin);
501
+ # without one, prints the command to run.
502
+ hand_over() {
503
+ local plugin="$1" q
504
+ if have_tty; then
505
+ handover_stdin
506
+ if [ -n "$HANDOVER_STDIN" ]; then
507
+ exec claude --plugin-dir "$plugin" "/bendit:adopt" < "$HANDOVER_STDIN"
508
+ fi
509
+ exec claude --plugin-dir "$plugin" "/bendit:adopt"
510
+ fi
511
+ printf -v q '%q' "$plugin"
512
+ say ""
513
+ say "There is no terminal to open Claude on. To finish, run this in your project:"
514
+ say " claude --plugin-dir $q \"/bendit:adopt\""
515
+ exit 0
516
+ }
517
+
518
+ # repo_note -- one line when the project folder is not a git repository.
519
+ repo_note() {
520
+ local out
521
+ out="$(LC_ALL=C git rev-parse --is-inside-work-tree 2>&1)" && return 0
522
+ case "$out" in
523
+ *"not a git repository"*) say "This folder is not a git repository; /bendit:adopt will offer git init." ;;
524
+ *) say "git could not tell whether this folder is a repository: $(printf '%s\n' "$out" | head -n 1)" ;;
525
+ esac
526
+ }
527
+
528
+ ready() {
529
+ local plugin
530
+ say ""
531
+ repo_note
532
+ say "This machine is ready. Fetching bendit..."
533
+ plugin="$(fetch_kit)" || exit 1
534
+ hand_over "$plugin"
535
+ }
536
+
537
+ main() {
538
+ local check=0 arg
539
+ for arg in "$@"; do
540
+ case "$arg" in
541
+ --version) say "bendit installer $BENDIT_VERSION"; exit 0 ;;
542
+ --help|-h) usage; exit 0 ;;
543
+ --check) check=1 ;;
544
+ *) die 2 "Unknown option: $arg (try --help)" ;;
545
+ esac
546
+ done
547
+ check_os
548
+ [ -n "${HOME:-}" ] || die 2 "HOME is not set, so bendit cannot tell where your home folder is. Set HOME and run again."
549
+ check_location
550
+ check_machine
551
+ if [ "$check" = 1 ]; then
552
+ local all="$MISSING_REQUIRED $MISSING_WEB"
553
+ all="${all# }"; all="${all% }"
554
+ [ -z "$all" ] && { say "Nothing is missing."; exit 0; }
555
+ say "Missing: $all"
556
+ exit 1
557
+ fi
558
+ if [ -n "$MISSING_REQUIRED$MISSING_WEB" ]; then
559
+ install_missing
560
+ check_machine >/dev/null
561
+ fi
562
+ ready
563
+ return 0
564
+ }
565
+
566
+ main "$@"
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: bendit
3
+ Version: 0.3.0
4
+ Summary: Enforced rules for coding agents: fail-closed guard hooks, a verification gate, practice skills, and /adopt for any project.
5
+ License: MIT
6
+ Project-URL: Repository, https://github.com/VedangP57/bendit
7
+ Requires-Python: >=3.9
@@ -0,0 +1,8 @@
1
+ bendit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ bendit/__main__.py,sha256=HRmn0-T-nuNJYkmZWqwpOGsPxc7CAGVOHpOPHEnwAyI,422
3
+ bendit/install.sh,sha256=OWEwhZnqR06xIk5M_NX2vPWyXDW1BjMw13-QcrWBOP0,20404
4
+ bendit-0.3.0.dist-info/METADATA,sha256=uI76Djs9yQsW4TyaK8mflDnwxOQl_jzvNJzLue1dobc,281
5
+ bendit-0.3.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
6
+ bendit-0.3.0.dist-info/entry_points.txt,sha256=RyVGZjPS7fffIFLmgATuB7S2IuC5hqYxSoWPAiHluik,48
7
+ bendit-0.3.0.dist-info/top_level.txt,sha256=bCQV0QxtJgrzD98HkuZ63NhdtIWoc5J05GkSwf7eWrQ,7
8
+ bendit-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ bendit = bendit.__main__:main
@@ -0,0 +1 @@
1
+ bendit