@devries-cameron20 / composio Mirror · read-only / commits / 294093038
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 17:15 UTC

docs(cli): make the documented uninstall safe and tested

The uninstall snippet now stages each startup-file rewrite in a 0600 mktemp file, promotes it only when the filter succeeds (preserving symlinks, inode, owner, and mode), always cleans up, removes legacy three-line blocks including the fish install-dir export, and deletes an installer-created ~/.bash_profile left empty so bash regains its default startup-file selection. A new suite extracts the snippet verbatim from the docs and exercises it under sh and dash, wired into the install script unit-test workflow.

jkomyno committed Aug 4, 2026 at 00:16 UTC 294093038199bf8120817e6ef371f0edba53bca1
4 files changed +325 -8
.github/workflows/cli.test-installation.yml
+3
@@ -36,6 +36,9 @@ jobs:
36 - name: Test atomic install replacement
37 run: bash test/install-sh-atomic-replace.test.sh
38
39 + - name: Test documented uninstall snippet
40 + run: bash test/install-sh-uninstall-snippet.test.sh
41 +
42 - name: Lint POSIX install scripts
43 run: shellcheck -s sh install.sh install/*.sh
44
INSTALL.md
+1 -1
@@ -106,7 +106,7 @@ rm -rf \
106 "$install_dir/local-tools-binaries"
107 ```
108
109 -Remove the managed `# Composio CLI` PATH block from `~/.zshrc`, `~/.bashrc`, `~/.bash_profile`, `~/.bash_login`, or `~/.config/fish/config.fish`. Blocks written by older installers contain an extra `export COMPOSIO_INSTALL_DIR=...` line after the marker; remove that line too.
109 +Remove the managed `# Composio CLI` PATH block from `~/.zshrc`, `~/.bashrc`, `~/.bash_profile`, `~/.bash_login`, or `~/.config/fish/config.fish`. Blocks written by older installers contain an extra `export COMPOSIO_INSTALL_DIR=...` (or `set --export COMPOSIO_INSTALL_DIR ...`) line after the marker; remove that line too. If removing the block leaves `~/.bash_profile` with nothing but blank lines, delete the file: the installer creates it on bash systems that had no login startup file, and even an empty `~/.bash_profile` keeps bash from reading `~/.profile`.
110
111 To purge credentials, configuration, caches, and every other CLI file, run `rm -rf "${COMPOSIO_INSTALL_DIR:-$HOME/.composio}"`. This is a complete reset and cannot be undone.
112
docs/content/docs/cli.mdx
+18 -7
@@ -167,16 +167,27 @@ for file in \
167 "$HOME/.bash_login" \
168 "$HOME/.config/fish/config.fish"; do
169 [ -f "$file" ] || continue
170 - awk '
171 - /^# Composio CLI$/ { skip = 1; next }
172 - skip && /^export COMPOSIO_INSTALL_DIR=/ { next }
173 - skip && (/^export PATH=/ || /^set --export PATH /) { skip = 0; next }
174 - { skip = 0; print }
175 - ' "$file" > "$file.tmp"
176 - cat "$file.tmp" > "$file" && rm -f "$file.tmp"
170 + tmp=$(mktemp) || continue
171 + if awk '
172 + $0 == "# Composio CLI" { in_block = 1; next }
173 + in_block && (/^export COMPOSIO_INSTALL_DIR=/ || /^set --export COMPOSIO_INSTALL_DIR /) { next }
174 + in_block && (/^export PATH=/ || /^set --export PATH /) { in_block = 0; next }
175 + { in_block = 0; print }
176 + ' "$file" > "$tmp"; then
177 + if [ "$file" = "$HOME/.bash_profile" ] && ! grep -q '[^[:space:]]' "$tmp"; then
178 + rm -f "$file"
179 + else
180 + cat "$tmp" > "$file"
181 + fi
182 + fi
183 + rm -f "$tmp"
184 done
185 ```
186
187 +The loop stages every rewrite in a `mktemp` scratch file — created with an unpredictable name and `0600` permissions, so startup-file contents never pass through a world-readable path — and writes the result back only when `awk` succeeds. A failed or missing `awk` leaves the startup file untouched, and the scratch file is always removed. Writing back with `cat` keeps a symlinked startup file intact: the symlink, its target's inode, owner, and mode all survive. The filter removes the current managed block and the three-line block written by older installers (marker plus `export COMPOSIO_INSTALL_DIR=...` or `set --export COMPOSIO_INSTALL_DIR ...`).
188 +
189 +`~/.bash_profile` gets one extra step: when removing the block leaves only blank lines, the file is deleted. The installer creates `~/.bash_profile` on bash systems that had no login startup file, and bash prefers even an empty `~/.bash_profile` over `~/.profile`, so leaving the empty file behind would silently override bash's normal startup-file selection forever. Note the edge case: a `~/.bash_profile` you created yourself but left empty is also removed.
190 +
191 <Callout type="warn">
192 **Purge all CLI state**
193
test/install-sh-uninstall-snippet.test.sh new
+303
@@ -0,0 +1,303 @@
1 +#!/usr/bin/env bash
2 +set -euo pipefail
3 +
4 +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5 +suite_tmp="$(mktemp -d)"
6 +
7 +cleanup() {
8 + rm -rf "$suite_tmp"
9 +}
10 +trap cleanup EXIT
11 +
12 +fail() {
13 + printf 'FAIL: %s\n' "$*" >&2
14 + exit 1
15 +}
16 +
17 +stat_inode() {
18 + if stat -f '%i' "$1" >/dev/null 2>&1; then
19 + stat -f '%i' "$1"
20 + else
21 + stat -c '%i' "$1"
22 + fi
23 +}
24 +
25 +stat_mode() {
26 + if stat -f '%Lp' "$1" >/dev/null 2>&1; then
27 + stat -f '%Lp' "$1"
28 + else
29 + stat -c '%a' "$1"
30 + fi
31 +}
32 +
33 +assert_no_predictable_tmp() {
34 + if find "$1" -name '*.tmp' -print -quit | grep -q .; then
35 + fail "$2 left a predictable *.tmp file behind"
36 + fi
37 +}
38 +
39 +assert_dir_empty() {
40 + if find "$1" -mindepth 1 -print -quit | grep -q .; then
41 + fail "$2 left files in the scratch TMPDIR"
42 + fi
43 +}
44 +
45 +# Extract the uninstall snippet verbatim from the docs so this suite can never
46 +# drift from what users actually run: the first ```bash fence after the
47 +# "### Uninstall" heading.
48 +docs_file="$repo_root/docs/content/docs/cli.mdx"
49 +snippet_file="$suite_tmp/uninstall-snippet.sh"
50 +awk '
51 + /^### Uninstall$/ { in_section = 1; next }
52 + in_section && $0 == "```bash" && !captured { in_block = 1; next }
53 + in_block && $0 == "```" { captured = 1; in_block = 0; next }
54 + in_block { print }
55 +' "$docs_file" >"$snippet_file"
56 +[[ -s $snippet_file ]] || fail "could not extract the uninstall snippet from $docs_file"
57 +grep -Fq 'for file in' "$snippet_file" || fail "extracted snippet is missing the startup-file loop"
58 +grep -Fq 'mktemp' "$snippet_file" || fail "extracted snippet does not stage rewrites through mktemp"
59 +! grep -Fq 'chmod' "$snippet_file" || fail "extracted snippet must not loosen mktemp permissions"
60 +
61 +real_mktemp=$(command -v mktemp)
62 +
63 +# awk stand-in that emits partial output and fails, to prove a broken filter
64 +# never reaches the startup file.
65 +fail_bin="$suite_tmp/fail-bin"
66 +mkdir -p "$fail_bin"
67 +cat >"$fail_bin/awk" <<'EOF'
68 +#!/usr/bin/env bash
69 +printf 'partial filter output\n'
70 +exit 1
71 +EOF
72 +chmod +x "$fail_bin/awk"
73 +
74 +# mktemp stand-in that records mode-at-creation and path of every scratch file
75 +# so the suite can assert 0600 under umask 022 and cleanup afterwards.
76 +log_bin="$suite_tmp/log-bin"
77 +mkdir -p "$log_bin"
78 +cat >"$log_bin/mktemp" <<EOF
79 +#!/usr/bin/env bash
80 +set -euo pipefail
81 +out=\$("$real_mktemp" "\$@")
82 +if stat -f '%Lp' "\$out" >/dev/null 2>&1; then
83 + mode=\$(stat -f '%Lp' "\$out")
84 +else
85 + mode=\$(stat -c '%a' "\$out")
86 +fi
87 +printf '%s %s\n' "\$mode" "\$out" >>"\$MKTEMP_LOG"
88 +printf '%s\n' "\$out"
89 +EOF
90 +chmod +x "$log_bin/mktemp"
91 +
92 +interpreters=("$(command -v sh)")
93 +if command -v dash >/dev/null 2>&1 && [[ $(command -v dash) != "${interpreters[0]}" ]]; then
94 + interpreters+=("$(command -v dash)")
95 +fi
96 +
97 +for interpreter in "${interpreters[@]}"; do
98 + interpreter_name=$(basename "$interpreter")
99 + case_root="$suite_tmp/$interpreter_name"
100 +
101 + run_snippet() {
102 + local case_home=$1
103 + shift
104 + env "$@" \
105 + HOME="$case_home" \
106 + COMPOSIO_INSTALL_DIR="$case_home/.composio" \
107 + COMPOSIO_BIN_DIR="$case_home/.local/bin" \
108 + "$interpreter" "$snippet_file"
109 + }
110 +
111 + # --- Removes modern POSIX, modern fish, and legacy three-line blocks while
112 + # --- keeping unrelated content; also removes release artifacts. Runs with
113 + # --- TMPDIR unset to prove mktemp still lands somewhere valid.
114 + home_main="$case_root/main-home"
115 + mkdir -p "$home_main/.config/fish" "$home_main/.composio/services" "$home_main/.local/bin"
116 + printf 'binary\n' >"$home_main/.composio/composio"
117 + printf 'service\n' >"$home_main/.composio/services/example.txt"
118 + printf 'keep me\n' >"$home_main/.composio/user-data.json"
119 + ln -s "$home_main/.composio/composio" "$home_main/.local/bin/composio"
120 + cat >"$home_main/.zshrc" <<'EOF'
121 +# user zshrc top
122 +alias ll='ls -l'
123 +
124 +# Composio CLI
125 +export PATH="$HOME/.local/bin:$PATH"
126 +
127 +# user zshrc bottom
128 +EOF
129 + cat >"$home_main/.bashrc" <<'EOF'
130 +# user bashrc
131 +
132 +# Composio CLI
133 +export COMPOSIO_INSTALL_DIR="$HOME/.composio"
134 +export PATH="$COMPOSIO_INSTALL_DIR:$PATH"
135 +
136 +alias gs='git status'
137 +EOF
138 + cat >"$home_main/.config/fish/config.fish" <<'EOF'
139 +# user fish config
140 +
141 +# Composio CLI
142 +set --export PATH "$HOME/.local/bin" $PATH
143 +
144 +# Composio CLI
145 +set --export COMPOSIO_INSTALL_DIR "$HOME/.composio"
146 +set --export PATH $COMPOSIO_INSTALL_DIR $PATH
147 +
148 +set -gx EDITOR vim
149 +EOF
150 +
151 + run_snippet "$home_main" -u TMPDIR
152 +
153 + for startup in "$home_main/.zshrc" "$home_main/.bashrc" "$home_main/.config/fish/config.fish"; do
154 + ! grep -Fxq '# Composio CLI' "$startup" || fail "$interpreter_name kept the marker in $startup"
155 + ! grep -Fq 'COMPOSIO_INSTALL_DIR' "$startup" || fail "$interpreter_name kept a legacy line in $startup"
156 + done
157 + ! grep -Fq 'export PATH=' "$home_main/.zshrc" || fail "$interpreter_name kept the modern POSIX PATH line"
158 + ! grep -Fq 'set --export PATH' "$home_main/.config/fish/config.fish" ||
159 + fail "$interpreter_name kept a fish PATH line"
160 + grep -Fq "alias ll='ls -l'" "$home_main/.zshrc" || fail "$interpreter_name lost unrelated zshrc content"
161 + grep -Fq '# user zshrc bottom' "$home_main/.zshrc" || fail "$interpreter_name lost trailing zshrc content"
162 + grep -Fq "alias gs='git status'" "$home_main/.bashrc" || fail "$interpreter_name lost unrelated bashrc content"
163 + grep -Fq 'set -gx EDITOR vim' "$home_main/.config/fish/config.fish" ||
164 + fail "$interpreter_name lost unrelated fish content"
165 + [[ ! -e "$home_main/.local/bin/composio" ]] || fail "$interpreter_name kept the bin entry point"
166 + [[ ! -e "$home_main/.composio/composio" ]] || fail "$interpreter_name kept the installed binary"
167 + [[ ! -e "$home_main/.composio/services" ]] || fail "$interpreter_name kept the services directory"
168 + [[ -f "$home_main/.composio/user-data.json" ]] || fail "$interpreter_name deleted user state"
169 + assert_no_predictable_tmp "$home_main" "$interpreter_name main case"
170 +
171 + # --- A symlinked startup file stays a symlink; the target keeps its inode
172 + # --- and gets the filtered content.
173 + home_link="$case_root/symlink-home"
174 + tmp_link="$case_root/tmp-link"
175 + mkdir -p "$home_link/dotfiles" "$tmp_link"
176 + cat >"$home_link/dotfiles/zshrc" <<'EOF'
177 +# managed by dotfiles
178 +# Composio CLI
179 +export PATH="$HOME/.local/bin:$PATH"
180 +alias dot='true'
181 +EOF
182 + ln -s "$home_link/dotfiles/zshrc" "$home_link/.zshrc"
183 + link_inode=$(stat_inode "$home_link/dotfiles/zshrc")
184 +
185 + run_snippet "$home_link" TMPDIR="$tmp_link"
186 +
187 + [[ -L "$home_link/.zshrc" ]] || fail "$interpreter_name replaced the startup symlink with a file"
188 + [[ $(readlink "$home_link/.zshrc") == "$home_link/dotfiles/zshrc" ]] ||
189 + fail "$interpreter_name repointed the startup symlink"
190 + [[ $(stat_inode "$home_link/dotfiles/zshrc") == "$link_inode" ]] ||
191 + fail "$interpreter_name replaced the symlink target inode"
192 + ! grep -Fxq '# Composio CLI' "$home_link/dotfiles/zshrc" ||
193 + fail "$interpreter_name kept the marker in the symlink target"
194 + grep -Fq "alias dot='true'" "$home_link/dotfiles/zshrc" ||
195 + fail "$interpreter_name lost content in the symlink target"
196 + assert_dir_empty "$tmp_link" "$interpreter_name symlink case"
197 +
198 + # --- A 0600 startup file keeps its mode, and under umask 022 the scratch
199 + # --- file is created 0600 (never more readable) and always removed.
200 + home_mode="$case_root/mode-home"
201 + tmp_mode="$case_root/tmp-mode"
202 + mktemp_log="$case_root/mktemp-mode.log"
203 + mkdir -p "$home_mode" "$tmp_mode"
204 + : >"$mktemp_log"
205 + cat >"$home_mode/.zshrc" <<'EOF'
206 +export SECRET_TOKEN=hunter2
207 +
208 +# Composio CLI
209 +export PATH="$HOME/.local/bin:$PATH"
210 +EOF
211 + chmod 600 "$home_mode/.zshrc"
212 +
213 + (
214 + umask 022
215 + run_snippet "$home_mode" PATH="$log_bin:$PATH" TMPDIR="$tmp_mode" MKTEMP_LOG="$mktemp_log"
216 + )
217 +
218 + [[ $(stat_mode "$home_mode/.zshrc") == 600 ]] || fail "$interpreter_name changed the 0600 startup mode"
219 + grep -Fq 'SECRET_TOKEN=hunter2' "$home_mode/.zshrc" || fail "$interpreter_name lost the secret line"
220 + ! grep -Fxq '# Composio CLI' "$home_mode/.zshrc" || fail "$interpreter_name kept the marker in the 0600 file"
221 + [[ -s $mktemp_log ]] || fail "$interpreter_name mode case never called mktemp"
222 + while read -r scratch_mode scratch_path; do
223 + [[ $scratch_mode == 600 ]] ||
224 + fail "$interpreter_name scratch file $scratch_path was created with mode $scratch_mode"
225 + [[ ! -e $scratch_path ]] || fail "$interpreter_name left scratch file $scratch_path behind"
226 + done <"$mktemp_log"
227 + assert_dir_empty "$tmp_mode" "$interpreter_name mode case"
228 +
229 + # --- A failing filter (awk overridden to emit partial output and exit 1)
230 + # --- leaves the startup file byte-identical and cleans up its scratch file.
231 + home_fail="$case_root/fail-home"
232 + tmp_fail="$case_root/tmp-fail"
233 + mkdir -p "$home_fail" "$tmp_fail"
234 + cat >"$home_fail/.zshrc" <<'EOF'
235 +# precious user config
236 +
237 +# Composio CLI
238 +export PATH="$HOME/.local/bin:$PATH"
239 +EOF
240 + cp "$home_fail/.zshrc" "$case_root/fail-before.zshrc"
241 +
242 + run_snippet "$home_fail" PATH="$fail_bin:$PATH" TMPDIR="$tmp_fail"
243 +
244 + cmp -s "$home_fail/.zshrc" "$case_root/fail-before.zshrc" ||
245 + fail "$interpreter_name modified the startup file although the filter failed"
246 + assert_dir_empty "$tmp_fail" "$interpreter_name failing-filter case"
247 + assert_no_predictable_tmp "$home_fail" "$interpreter_name failing-filter case"
248 +
249 + # --- An installer-created ~/.bash_profile that holds only the managed block
250 + # --- is deleted, restoring bash's default startup-file selection.
251 + home_bp_created="$case_root/bash-profile-created-home"
252 + mkdir -p "$home_bp_created"
253 + cat >"$home_bp_created/.bash_profile" <<'EOF'
254 +
255 +# Composio CLI
256 +export PATH="$HOME/.local/bin:$PATH"
257 +EOF
258 +
259 + run_snippet "$home_bp_created" -u TMPDIR
260 +
261 + [[ ! -e "$home_bp_created/.bash_profile" ]] ||
262 + fail "$interpreter_name kept an empty leftover .bash_profile"
263 +
264 + # --- Documented edge: a pre-existing, user-owned empty ~/.bash_profile is
265 + # --- also removed.
266 + home_bp_blank="$case_root/bash-profile-blank-home"
267 + mkdir -p "$home_bp_blank"
268 + : >"$home_bp_blank/.bash_profile"
269 +
270 + run_snippet "$home_bp_blank" -u TMPDIR
271 +
272 + [[ ! -e "$home_bp_blank/.bash_profile" ]] ||
273 + fail "$interpreter_name kept a pre-existing empty .bash_profile"
274 +
275 + # --- A ~/.bash_profile with remaining content (the installer's ~/.profile
276 + # --- seed, or any user content) survives with only the block removed.
277 + home_bp_keep="$case_root/bash-profile-keep-home"
278 + mkdir -p "$home_bp_keep"
279 + cat >"$home_bp_keep/.bash_profile" <<'EOF'
280 +# Created by the Composio CLI installer.
281 +# Bash reads this file instead of ~/.profile in login shells.
282 +if [ -f "$HOME/.profile" ]; then
283 + . "$HOME/.profile"
284 +fi
285 +
286 +# Composio CLI
287 +export PATH="$HOME/.local/bin:$PATH"
288 +EOF
289 +
290 + run_snippet "$home_bp_keep" -u TMPDIR
291 +
292 + [[ -f "$home_bp_keep/.bash_profile" ]] || fail "$interpreter_name deleted a non-empty .bash_profile"
293 + grep -Fq '. "$HOME/.profile"' "$home_bp_keep/.bash_profile" ||
294 + fail "$interpreter_name lost the ~/.profile seed content"
295 + ! grep -Fxq '# Composio CLI' "$home_bp_keep/.bash_profile" ||
296 + fail "$interpreter_name kept the marker in a seeded .bash_profile"
297 + ! grep -Fq 'export PATH=' "$home_bp_keep/.bash_profile" ||
298 + fail "$interpreter_name kept the managed PATH line in a seeded .bash_profile"
299 +
300 + printf 'docs uninstall snippet passed under %s\n' "$interpreter_name"
301 +done
302 +
303 +printf 'docs uninstall snippet tests passed\n'