Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
fix(review): harden inline rewrite, delegation trust, and reconciliation
Apply verified code-review findings: write through symlinked startup files with preserved mode and a per-process tmp name; verify delegated CLI setup actually reconciled the managed block before trusting exit 0; make managed-block reconciliation assignment-aware so annotated blocks never lose user content or PATH precedence; clean up the CLI's tmp file when an atomic write fails; assert the auto contract in the install health-check canary; recommend composio install --shell in generated release docs; record the new default in the CLI changelog.
jkomyno committed
Aug 3, 2026 at 17:48 UTC
d5b425bd56c2cd00b537eb9877dfe68ea5d16333
7 files changed
+329
-34
.github/workflows/build-cli-binaries.yml
+3
-3
@@ -357,9 +357,9 @@ jobs:
357
export PATH="$COMPOSIO_BIN_DIR:$PATH"
358
```
359
360
- After a manual installation, run `composio install` to add the CLI to your
361
- shell's `PATH` permanently (or `composio install --shell zsh|bash|fish` to
362
- target a specific shell).
360
+ After a manual installation, run `composio install --shell zsh|bash|fish`
361
+ (with your shell in place of `zsh|bash|fish`) to add the CLI to your
362
+ shell's `PATH` permanently.
363
364
## Usage
365
.github/workflows/cli.install-health-check.yml
+32
-1
@@ -60,6 +60,18 @@ jobs:
60
# automatic shell setup (the default infers the shell from $SHELL; the idempotent rc
61
# edit on this ephemeral runner is harmless). Asset-aware and self-healing, so it is a
62
# coverage net rather than the primary signal.
63
+ #
64
+ # This leg is also the canary for the auto shell-setup default itself: shell-setup
65
+ # failure is non-fatal in install.sh (exit 0 + warning), so without asserting the
66
+ # actual contract below, a broken default would install a working binary and still
67
+ # report green. SHELL=/bin/bash pins deterministic auto-resolution on this runner, and
68
+ # the assertions mirror cli.test-installation.yml's checks — the managed PATH block in
69
+ # ~/.bashrc, plus that a login shell can actually resolve the binary.
70
+ #
71
+ # Deployment coupling: like the production legs in cli.install-e2e.yml, this installs
72
+ # from the PRODUCTION installer (composio.dev/install), so the shell-setup assertions
73
+ # only pass once the auto-default ships there. This workflow is schedule/workflow_dispatch
74
+ # only (no pull_request trigger), so it never runs against a pre-deploy PR or branch.
75
- name: Install via default no-arg flow
76
run: |
77
set -euo pipefail
@@ -76,11 +88,30 @@ jobs:
88
"$HOME/.composio/services" \
89
"$HOME/.composio/acp-adapters" \
90
"$HOME/.composio/local-tools-binaries"
79
- curl -fsSL https://composio.dev/install | sh
91
+ curl -fsSL https://composio.dev/install | SHELL=/bin/bash sh
92
test -x "$HOME/.composio/composio"
93
test -L "$HOME/.local/bin/composio"
94
"$HOME/.local/bin/composio" --version
95
96
+ # Assert the auto shell-setup contract: the managed PATH block landed in ~/.bashrc.
97
+ if grep -Fqx '# Composio CLI' "$HOME/.bashrc" \
98
+ && grep -Fqx 'export PATH="$HOME/.local/bin:$PATH"' "$HOME/.bashrc"; then
99
+ echo "✅ ~/.bashrc gained the managed Composio PATH block via automatic shell setup"
100
+ else
101
+ echo "❌ ~/.bashrc missing the managed Composio PATH block after the no-argument install"
102
+ echo "=== ~/.bashrc contents ==="
103
+ cat "$HOME/.bashrc" || true
104
+ exit 1
105
+ fi
106
+
107
+ # Assert a login shell actually resolves the binary through that PATH block.
108
+ if bash -ilc 'command -v composio' && bash -ilc 'composio --version'; then
109
+ echo "✅ composio resolves via a login bash shell"
110
+ else
111
+ echo "❌ composio did not resolve via a login bash shell"
112
+ exit 1
113
+ fi
114
+
115
- name: Send Slack Notification (Failure)
116
if: failure()
117
uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0
install.sh
+42
-5
@@ -369,16 +369,25 @@ write_path_block() {
369
if [ ! -f "$write_path_file" ]; then
370
touch "$write_path_file" 2>/dev/null || return 1
371
fi
372
- if path_block_current "$write_path_file" "$write_path_line"; then
372
+ # Dotfile managers keep startup files as symlinks; rewrite the physical
373
+ # target so the tmp+rename replace below cannot detach the symlink.
374
+ write_path_target=$(resolve_physical_path "$write_path_file")
375
+ if path_block_current "$write_path_target" "$write_path_line"; then
376
info "$(tildify "$write_path_file") is already up to date."
377
return 0
378
fi
376
- write_path_tmp=$write_path_file.composio.tmp
379
+ write_path_tmp=$write_path_target.composio.tmp.$$
380
+ # cp -p seeds the tmp with the original permission bits; the awk rewrite
381
+ # below truncates its content while the copied mode survives the rename.
382
+ if ! cp -p "$write_path_target" "$write_path_tmp" 2>/dev/null; then
383
+ rm -f "$write_path_tmp"
384
+ return 1
385
+ fi
386
if ! awk '
387
pending { pending = 0; next }
388
$0 == "# Composio CLI" { pending = 1; next }
389
{ print }
381
- ' "$write_path_file" >"$write_path_tmp" 2>/dev/null; then
390
+ ' "$write_path_target" >"$write_path_tmp" 2>/dev/null; then
391
rm -f "$write_path_tmp"
392
return 1
393
fi
@@ -386,7 +395,7 @@ write_path_block() {
395
rm -f "$write_path_tmp"
396
return 1
397
fi
389
- if ! mv "$write_path_tmp" "$write_path_file" 2>/dev/null; then
398
+ if ! mv "$write_path_tmp" "$write_path_target" 2>/dev/null; then
399
rm -f "$write_path_tmp"
400
return 1
401
fi
@@ -419,6 +428,33 @@ inline_shell_setup() {
428
return 0
429
}
430
431
+# Succeeds when one startup file already holds the current managed block.
432
+delegated_file_current() {
433
+ [ -f "$1" ] && path_block_current "$1" "$2"
434
+}
435
+
436
+# Stable CLI --shell implementations skip any startup file that already
437
+# carries the managed marker, so a delegated exit 0 can leave a stale block
438
+# naming an old bin dir. Confirm every target startup file of the requested
439
+# shell names the current bin dir before trusting the delegation.
440
+delegated_setup_verified() {
441
+ delegated_rendered=$(render_bin_dir "$resolved_bin_dir")
442
+ case $requested_shell in
443
+ zsh) delegated_file_current "$HOME/.zshrc" "$(path_block_line zsh "$delegated_rendered")" ;;
444
+ fish) delegated_file_current "$HOME/.config/fish/config.fish" "$(path_block_line fish "$delegated_rendered")" ;;
445
+ bash)
446
+ delegated_line=$(path_block_line bash "$delegated_rendered")
447
+ delegated_file_current "$HOME/.bashrc" "$delegated_line" || return 1
448
+ if [ -f "$HOME/.bash_profile" ]; then
449
+ delegated_file_current "$HOME/.bash_profile" "$delegated_line"
450
+ elif [ -f "$HOME/.bash_login" ]; then
451
+ delegated_file_current "$HOME/.bash_login" "$delegated_line"
452
+ fi
453
+ ;;
454
+ *) return 1 ;;
455
+ esac
456
+}
457
+
458
setup_requested_shell() {
459
if is_unsafe_path "$resolved_bin_dir"; then
460
warn "Skipping automatic shell setup: the executable directory \"$resolved_bin_dir\" contains unsupported characters."
@@ -426,7 +462,8 @@ setup_requested_shell() {
462
fi
463
if "$exe" install --help 2>&1 | grep -q -- '--shell'; then
464
debug "delegating shell setup to $exe install --shell $requested_shell"
429
- if COMPOSIO_CLI_INVOCATION_ORIGIN=installer COMPOSIO_BIN_DIR="$resolved_bin_dir" "$exe" install --shell "$requested_shell"; then
465
+ if COMPOSIO_CLI_INVOCATION_ORIGIN=installer COMPOSIO_BIN_DIR="$resolved_bin_dir" "$exe" install --shell "$requested_shell" &&
466
+ delegated_setup_verified; then
467
shell_configured=cli
468
info "Configured $requested_shell shell setup ($shell_configured)."
469
return 0
test/install-sh-release-resolution.test.sh
+107
-8
@@ -62,6 +62,11 @@ for script in "$repo_root/install.sh" "$repo_root"/install/*.sh; do
62
fi
63
done
64
65
+# Concurrent installer runs must not share one rc rewrite tmp file, so the
66
+# tmp suffix embeds the process id.
67
+grep -Fq '.composio.tmp.$$' "$repo_root/install.sh" ||
68
+ fail 'install.sh rc rewrites must use a per-process tmp suffix'
69
+
70
# The shell variants are served as standalone scripts, so their shared logic
71
# (including the URL-validation security checks) is intentionally copied.
72
# Enforce that they stay byte-identical except for the shell each hardcodes in
@@ -295,6 +300,32 @@ install)
300
if [ "${TEST_INSTALL_HINT:-0}" = 1 ]; then
301
printf '%s\n' '│ Restart your shell so composio is on PATH │'
302
fi
303
+ # Mirror the reconciling CLI: write the managed block to the same startup
304
+ # files the installer verifies. TEST_INSTALL_RECONCILE=0 models stable
305
+ # CLIs that exit 0 without reconciling (they skip marker-bearing files).
306
+ if [ "${TEST_INSTALL_EXIT:-0}" = 0 ] && [ "${TEST_INSTALL_RECONCILE:-1}" = 1 ]; then
307
+ write_block() {
308
+ if [ -f "$1" ] && grep -Fq "$2" "$1"; then
309
+ return 0
310
+ fi
311
+ printf '\n# Composio CLI\n%s\n' "$2" >>"$1"
312
+ }
313
+ case ${3:-} in
314
+ zsh) write_block "$HOME/.zshrc" "export PATH=\"$COMPOSIO_BIN_DIR:\$PATH\"" ;;
315
+ fish)
316
+ mkdir -p "$HOME/.config/fish"
317
+ write_block "$HOME/.config/fish/config.fish" "set --export PATH \"$COMPOSIO_BIN_DIR\" \$PATH"
318
+ ;;
319
+ bash)
320
+ write_block "$HOME/.bashrc" "export PATH=\"$COMPOSIO_BIN_DIR:\$PATH\""
321
+ if [ -f "$HOME/.bash_profile" ]; then
322
+ write_block "$HOME/.bash_profile" "export PATH=\"$COMPOSIO_BIN_DIR:\$PATH\""
323
+ elif [ -f "$HOME/.bash_login" ]; then
324
+ write_block "$HOME/.bash_login" "export PATH=\"$COMPOSIO_BIN_DIR:\$PATH\""
325
+ fi
326
+ ;;
327
+ esac
328
+ fi
329
exit "${TEST_INSTALL_EXIT:-0}"
330
fi
331
exit 98
@@ -323,7 +354,7 @@ EOF
354
unset CASE_GITHUB_URL CASE_API_BASE CASE_INSTALL_VERSION CASE_INSTALL_SHELL CASE_PLUGINS CASE_QUIET CASE_DEBUG CASE_HELP
355
unset CASE_ALLOW_HTTP_HOST CASE_CHECKSUM_MODE CASE_API_ASSET_URL CASE_BASE_MODE CASE_REDIRECT_DOWNGRADE
356
unset CASE_SHELL_CAPABILITY CASE_INSTALL_EXIT CASE_SETUP_EXIT CASE_VERSION_EXIT CASE_PATH_PREFIX CASE_UNSET_SHELL
326
- unset CASE_CURL_DELAY_URL CASE_CURL_DELAY_SECONDS CASE_SHELL_VALUE CASE_INSTALL_HINT
357
+ unset CASE_CURL_DELAY_URL CASE_CURL_DELAY_SECONDS CASE_SHELL_VALUE CASE_INSTALL_HINT CASE_INSTALL_RECONCILE
358
rm -f "$case_root/curl-parent.pid"
359
: >"$curl_log"
360
: >"$composio_log"
@@ -362,6 +393,7 @@ EOF
393
TEST_SHELL_CAPABILITY="${CASE_SHELL_CAPABILITY:-supported}" \
394
TEST_INSTALL_EXIT="${CASE_INSTALL_EXIT:-0}" \
395
TEST_INSTALL_HINT="${CASE_INSTALL_HINT:-0}" \
396
+ TEST_INSTALL_RECONCILE="${CASE_INSTALL_RECONCILE:-1}" \
397
TEST_SETUP_EXIT="${CASE_SETUP_EXIT:-0}" \
398
TEST_VERSION_EXIT="${CASE_VERSION_EXIT:-0}" \
399
TEST_CURL_DELAY_URL="${CASE_CURL_DELAY_URL:-}" \
@@ -393,6 +425,7 @@ EOF
425
TEST_CHECKSUM_MODE=missing \
426
TEST_SHELL_CAPABILITY="${CASE_SHELL_CAPABILITY:-supported}" \
427
TEST_INSTALL_EXIT="${CASE_INSTALL_EXIT:-0}" \
428
+ TEST_INSTALL_RECONCILE="${CASE_INSTALL_RECONCILE:-1}" \
429
TEST_CURL_DELAY_URL="${CASE_CURL_DELAY_URL:-}" \
430
TEST_CURL_DELAY_SECONDS="${CASE_CURL_DELAY_SECONDS:-1}" \
431
TEST_CURL_PARENT_PID_FILE="$case_root/curl-parent.pid" \
@@ -416,7 +449,8 @@ EOF
449
# for delegated CLI calls, but the ending must reflect only the PATH the
450
# invoking terminal inherited, which does not contain the bin dir here.
451
assert_tail "$output" "$case_b_tail" "$interpreter_name default auto Case B tail"
419
- [[ ! -e "$home/.bashrc" ]] || fail "$interpreter_name delegated default flow must not write rc files"
452
+ grep -Fq "export PATH=\"$bin_dir:\$PATH\"" "$home/.bashrc" || fail "$interpreter_name delegated default flow rc written by the CLI"
453
+ assert_not_contains "$output" 'Updated ~/.bashrc' "$interpreter_name delegated default flow must not rewrite rc files inline"
454
[[ $(wc -l <"$composio_log") -eq 3 ]] || fail "$interpreter_name default flow invoked extra CLI commands"
455
grep -Fq '|--version' "$composio_log" || fail "$interpreter_name version probe"
456
[[ ! -s "$case_root/git.log" ]] || fail "$interpreter_name must not use git"
@@ -607,7 +641,8 @@ EOF
641
assert_contains "$direct_output" 'Configured zsh shell setup (cli).' "$interpreter_name COMPOSIO_INSTALL_SHELL confirmation"
642
assert_not_contains "$direct_output" 'Required next step' "$interpreter_name COMPOSIO_INSTALL_SHELL must not print setup guidance"
643
assert_tail "$direct_output" "$case_b_tail" "$interpreter_name COMPOSIO_INSTALL_SHELL Case B tail"
610
- [[ ! -e "$direct_home/.zshrc" ]] || fail "$interpreter_name COMPOSIO_INSTALL_SHELL CLI path must not write rc files"
644
+ grep -Fq "export PATH=\"$direct_bin:\$PATH\"" "$direct_home/.zshrc" || fail "$interpreter_name COMPOSIO_INSTALL_SHELL CLI-written block"
645
+ assert_not_contains "$direct_output" 'Updated ~/.zshrc' "$interpreter_name COMPOSIO_INSTALL_SHELL CLI path must not rewrite rc files inline"
646
647
reset_case
648
CASE_INSTALL_SHELL=zsh
@@ -780,12 +815,14 @@ EOF
815
assert_contains "$shadow_output" "$shadow_dir/composio" "$interpreter_name shadow ending names the shadowing command"
816
assert_tail "$shadow_output" $'To use the newly installed CLI, run:\n\n '"$shadow_install/composio login" "$interpreter_name shadow tail avoids the shadowed bare command"
817
783
- # Pinned old CLI: supports --shell but ignores the invocation-origin hint and
784
- # prints its own boxed restart hint. A relative COMPOSIO_BIN_DIR must never
785
- # reach setup raw; startup files stay untouched; the installer's plain final
818
+ # Pinned old CLI: supports --shell but ignores the invocation-origin hint,
819
+ # prints its own boxed restart hint, and exits 0 without reconciling. A
820
+ # relative COMPOSIO_BIN_DIR must never reach setup raw; the installer must
821
+ # detect the unreconciled startup file and repair it inline; its plain final
822
# block prints after the old hint and supersedes it.
823
reset_case
824
CASE_INSTALL_HINT=1
825
+ CASE_INSTALL_RECONCILE=0
826
oldcli_home="$case_root/oldcli-home"
827
oldcli_work="$case_root/oldcli-work"
828
oldcli_install="$case_root/oldcli-install"
@@ -793,8 +830,9 @@ EOF
830
oldcli_output=$(cd "$oldcli_work" && run_installer "$oldcli_home" "$oldcli_install" "rel-bin" "$stable_tag" 2>&1)
831
grep -Fq "|installer|$oldcli_work/rel-bin|install --shell bash" "$composio_log" ||
832
fail "$interpreter_name old-CLI setup must receive the resolved absolute bin dir"
796
- [[ ! -e "$oldcli_home/.bashrc" && ! -e "$oldcli_home/.bash_profile" ]] ||
797
- fail "$interpreter_name old-CLI delegation must leave startup files unchanged"
833
+ grep -Fq "export PATH=\"$oldcli_work/rel-bin:\$PATH\"" "$oldcli_home/.bashrc" ||
834
+ fail "$interpreter_name old-CLI delegation must be reconciled inline with the absolute bin dir"
835
+ assert_contains "$oldcli_output" 'Configured bash shell setup (fallback).' "$interpreter_name old-CLI reconciliation disclosure"
836
assert_contains "$oldcli_output" '│ Restart your shell so composio is on PATH │' "$interpreter_name old-CLI restart hint passes through"
837
assert_tail "$oldcli_output" "$case_b_tail" "$interpreter_name old-CLI hint superseded by the installer tail"
838
@@ -853,6 +891,67 @@ EOF
891
grep -Fq 'alias reconcile-before=1' "$reconcile_home/.zshrc" || fail "$interpreter_name unmanaged content preserved (before block)"
892
grep -Fq 'alias reconcile-after=1' "$reconcile_home/.zshrc" || fail "$interpreter_name unmanaged content preserved (after block)"
893
894
+ # --- Symlinked startup files and mode preservation (managed dotfiles) ---
895
+
896
+ # Inline setup must write through a symlinked rc file: the symlink survives
897
+ # and its target receives the managed block (mirrors the CLI unit test
898
+ # 'preserves a symlinked .zshrc').
899
+ reset_case
900
+ CASE_SHELL_CAPABILITY=unsupported
901
+ CASE_SHELL_VALUE=/bin/zsh
902
+ symlink_home="$case_root/symlink-home"
903
+ symlink_store="$case_root/symlink-store"
904
+ symlink_bin="$case_root/symlink-bin"
905
+ mkdir -p "$symlink_home" "$symlink_store"
906
+ printf '%s\n' 'alias dotfiles-managed=1' >"$symlink_store/zshrc"
907
+ ln -s "$symlink_store/zshrc" "$symlink_home/.zshrc"
908
+ symlink_output=$(run_installer "$symlink_home" "$case_root/symlink-install" "$symlink_bin" "$stable_tag" 2>&1)
909
+ assert_contains "$symlink_output" 'Updated ~/.zshrc' "$interpreter_name symlinked rc update disclosure"
910
+ [[ -L "$symlink_home/.zshrc" ]] || fail "$interpreter_name symlinked rc must stay a symlink"
911
+ [[ $(readlink "$symlink_home/.zshrc") == "$symlink_store/zshrc" ]] || fail "$interpreter_name symlinked rc target must not change"
912
+ [[ $(grep -Fc '# Composio CLI' "$symlink_store/zshrc") -eq 1 ]] || fail "$interpreter_name symlink target must hold one managed block"
913
+ grep -Fq "export PATH=\"$symlink_bin:\$PATH\"" "$symlink_store/zshrc" || fail "$interpreter_name symlink target managed line"
914
+ grep -Fq 'alias dotfiles-managed=1' "$symlink_store/zshrc" || fail "$interpreter_name symlink target unmanaged content preserved"
915
+
916
+ # The inline rewrite must preserve the startup file's permission bits.
917
+ reset_case
918
+ CASE_SHELL_CAPABILITY=unsupported
919
+ CASE_SHELL_VALUE=/bin/zsh
920
+ mode_home="$case_root/mode-home"
921
+ mkdir -p "$mode_home"
922
+ printf '%s\n' 'alias mode-check=1' >"$mode_home/.zshrc"
923
+ chmod 600 "$mode_home/.zshrc"
924
+ run_installer "$mode_home" "$case_root/mode-install" "$case_root/mode-bin" "$stable_tag" >/dev/null 2>&1
925
+ grep -Fq '# Composio CLI' "$mode_home/.zshrc" || fail "$interpreter_name mode-preservation run must write the block"
926
+ case $(uname) in
927
+ Darwin) mode_actual=$(stat -f '%Lp' "$mode_home/.zshrc") ;;
928
+ *) mode_actual=$(stat -c '%a' "$mode_home/.zshrc") ;;
929
+ esac
930
+ [[ $mode_actual == 600 ]] || fail "$interpreter_name inline rewrite must preserve the file mode (got $mode_actual)"
931
+
932
+ # --- Delegated setup verification (stale managed blocks) ---
933
+
934
+ # A delegated CLI that exits 0 without reconciling a pre-seeded stale block
935
+ # must not be trusted: the installer verifies the startup file, reconciles
936
+ # inline, and reports the fallback disclosure with the Case B ending.
937
+ reset_case
938
+ CASE_INSTALL_SHELL=zsh
939
+ CASE_INSTALL_RECONCILE=0
940
+ stale_home="$case_root/stale-delegated-home"
941
+ stale_bin="$case_root/stale-delegated-bin"
942
+ mkdir -p "$stale_home"
943
+ printf '%s\n' 'alias stale-guard=1' '' '# Composio CLI' 'export PATH="/stale/old-bin:$PATH"' >"$stale_home/.zshrc"
944
+ stale_output=$(run_installer "$stale_home" "$case_root/stale-delegated-install" "$stale_bin" "$stable_tag" 2>&1)
945
+ grep -Fq "|installer|$stale_bin|install --shell zsh" "$composio_log" || fail "$interpreter_name stale delegation still delegates first"
946
+ assert_contains "$stale_output" 'Configured zsh shell setup (fallback).' "$interpreter_name stale delegation reconciles inline"
947
+ [[ $(grep -Fc '# Composio CLI' "$stale_home/.zshrc") -eq 1 ]] || fail "$interpreter_name stale reconcile keeps one marker block"
948
+ grep -Fq "export PATH=\"$stale_bin:\$PATH\"" "$stale_home/.zshrc" || fail "$interpreter_name stale reconcile names the current bin dir"
949
+ if grep -Fq '/stale/old-bin' "$stale_home/.zshrc"; then
950
+ fail "$interpreter_name stale managed path must be replaced after delegation"
951
+ fi
952
+ grep -Fq 'alias stale-guard=1' "$stale_home/.zshrc" || fail "$interpreter_name stale reconcile preserves unmanaged content"
953
+ assert_tail "$stale_output" "$case_b_tail" "$interpreter_name stale delegation Case B tail"
954
+
955
# --- Unsafe resolved bin dirs under the default flow (KD3) ---
956
957
unsafe_auto_index=0
ts/packages/cli/CHANGELOG.md
+1
@@ -4,6 +4,7 @@
4
5
### Minor Changes
6
7
+- The installer (`curl -fsSL https://composio.dev/install | sh`) now configures your shell automatically: `COMPOSIO_INSTALL_SHELL` defaults to `auto`, which infers the login shell from `$SHELL` (zsh, bash, or fish) and always runs idempotent PATH setup for it; `COMPOSIO_INSTALL_SHELL=none` keeps the old install-only behavior for CI, Docker, and dotfile managers. Startup-file setup failures no longer fail the install — the installer keeps the binary, warns, and prints a runnable absolute-path command. `composio install` now reconciles an existing managed PATH block whose bin directory changed (one block per physical file, symlink-aware) and suppresses its boxed restart hint when invoked by the installer, which owns the final message.
8
- `composio install` gains a `--shell <zsh|bash|fish>` flag that overrides `$SHELL` detection, in preparation for the mise-style installer rewrite. The bin-dir PATH target now resolves through `COMPOSIO_BIN_DIR`, an existing `~/.local/bin/composio`, or the real binary's own directory, in that order, instead of hardcoding `~/.composio`; rc blocks write only a PATH line (the `export COMPOSIO_INSTALL_DIR=...` line is gone, since that variable identifies the install bundle, not the PATH entry point). Bash now also writes the PATH line to `~/.bash_profile` or `~/.bash_login` when either already exists, so `bash -ilc` picks it up. The restart hint bug is fixed: bash now prints `source ~/.bashrc` instead of the literal string `exec $SHELL`.
9
10
### Patch Changes
ts/packages/cli/src/commands/install.cmd.ts
+54
-17
@@ -195,17 +195,35 @@ type ManagedPathBlockState =
195
| { readonly state: 'current' }
196
| { readonly state: 'stale'; readonly reconciled: string };
197
198
-const isAnyMarkerLine = (line: string): boolean => {
198
+/**
199
+ * A line this installer could have written as the managed PATH assignment:
200
+ * POSIX `export PATH="<dir>:$PATH"` or fish `set --export PATH "<dir>" $PATH`.
201
+ * Matched structurally on the prefix/suffix (any bin dir) so stale blocks
202
+ * recording another directory are still recognized as ours.
203
+ */
204
+const isManagedPathAssignment = (line: string): boolean => {
205
const trimmed = line.trim();
200
- return trimmed === MARKER || trimmed === COMPLETIONS_MARKER;
206
+ return (
207
+ (trimmed.startsWith('export PATH="') && trimmed.endsWith(':$PATH"')) ||
208
+ (trimmed.startsWith('set --export PATH "') && trimmed.endsWith('" $PATH'))
209
+ );
210
};
211
212
/**
213
* Reconcile the managed PATH block — the `MARKER` line plus the PATH
214
* assignment right below it — with the currently resolved bin directory.
206
- * A block recording a stale bin dir is replaced in place, duplicate managed
207
- * PATH blocks collapse into a single current block, and unmanaged content
208
- * (including the completions block) is left byte-for-byte untouched.
215
+ * A well-formed block recording a stale bin dir is replaced in place,
216
+ * duplicate managed PATH blocks collapse into a single current block, and
217
+ * unmanaged content (including the completions block) is left byte-for-byte
218
+ * untouched.
219
+ *
220
+ * A marker whose next line is not a recognizable managed assignment (a user
221
+ * annotation, a blank line, another marker) is malformed: only the marker
222
+ * line itself is removed, and the fresh block is appended after all remaining
223
+ * content instead of replacing in place. That guarantees no user content is
224
+ * ever deleted, and — because these prepend-style assignments make the
225
+ * last-sourced line win — the new bin dir still takes PATH precedence over
226
+ * any orphaned stale assignment left behind.
227
*/
228
const reconcileManagedPathBlock = (contents: string, pathBlock: string): ManagedPathBlockState => {
229
const lines = contents.split('\n');
@@ -213,7 +231,8 @@ const reconcileManagedPathBlock = (contents: string, pathBlock: string): Managed
231
const firstMarkerIndex = markerIndexes[0];
232
if (firstMarkerIndex === undefined) return { state: 'absent' };
233
216
- const expectedAssignment = (pathBlock.split('\n')[1] ?? '').trim();
234
+ const blockLines = pathBlock.split('\n');
235
+ const expectedAssignment = (blockLines[1] ?? '').trim();
236
if (
237
markerIndexes.length === 1 &&
238
(lines[firstMarkerIndex + 1] ?? '').trim() === expectedAssignment
@@ -221,21 +240,33 @@ const reconcileManagedPathBlock = (contents: string, pathBlock: string): Managed
240
return { state: 'current' };
241
}
242
224
- // Managed lines: each marker line and its assignment line, unless that next
225
- // line is itself a marker (never consume the completions block).
243
+ // Managed lines: each marker line, plus the next line only when it is a
244
+ // recognizable managed PATH assignment — anything else is not ours to delete.
245
const managedLineIndexes = new Set<number>(
246
markerIndexes.flatMap(markerIndex => {
247
const assignment = lines[markerIndex + 1];
229
- return assignment !== undefined && !isAnyMarkerLine(assignment)
248
+ return assignment !== undefined && isManagedPathAssignment(assignment)
249
? [markerIndex, markerIndex + 1]
250
: [markerIndex];
251
})
252
);
253
+ const hasMalformedBlock = markerIndexes.some(
254
+ markerIndex => !isManagedPathAssignment(lines[markerIndex + 1] ?? '')
255
+ );
256
235
- const reconciledLines = lines.flatMap((line, index) => {
236
- if (index === firstMarkerIndex) return pathBlock.split('\n');
237
- return managedLineIndexes.has(index) ? [] : [line];
238
- });
257
+ if (!hasMalformedBlock) {
258
+ const reconciledLines = lines.flatMap((line, index) => {
259
+ if (index === firstMarkerIndex) return blockLines;
260
+ return managedLineIndexes.has(index) ? [] : [line];
261
+ });
262
+ return { state: 'stale', reconciled: reconciledLines.join('\n') };
263
+ }
264
+
265
+ const keptLines = lines.flatMap((line, index) => (managedLineIndexes.has(index) ? [] : [line]));
266
+ const endsWithNewline = keptLines[keptLines.length - 1] === '';
267
+ const reconciledLines = endsWithNewline
268
+ ? [...keptLines.slice(0, -1), ...blockLines, '']
269
+ : [...keptLines, ...blockLines];
270
return { state: 'stale', reconciled: reconciledLines.join('\n') };
271
};
272
@@ -308,10 +339,16 @@ const atomicWriteWithMode = (
339
const tmpPath = `${writeTarget}.composio-tmp`;
340
341
yield* fs.writeFileString(tmpPath, contents);
311
- if (Option.isSome(existingTargetInfo)) {
312
- yield* fs.chmod(tmpPath, existingTargetInfo.value.mode & 0o7777);
313
- }
314
- yield* fs.rename(tmpPath, writeTarget);
342
+ // Mirror install.sh's write_path_block: when the chmod or rename step
343
+ // fails, remove the temp file before propagating the error so no
344
+ // `.composio-tmp` litter is left next to the target.
345
+ const promoteTmp = Effect.gen(function* () {
346
+ if (Option.isSome(existingTargetInfo)) {
347
+ yield* fs.chmod(tmpPath, existingTargetInfo.value.mode & 0o7777);
348
+ }
349
+ yield* fs.rename(tmpPath, writeTarget);
350
+ });
351
+ yield* promoteTmp.pipe(Effect.onError(() => fs.remove(tmpPath).pipe(Effect.ignore)));
352
});
353
354
/** Atomically rewrite each reconciled physical target, preserving its file mode. */
ts/packages/cli/test/src/commands/install.cmd.test.ts
+90
@@ -593,6 +593,73 @@ describe('CLI: composio install', () => {
593
});
594
});
595
596
+ describe('[When] a user comment sits between the managed marker and the stale export', () => {
597
+ layer(InstallTestLive())(it => {
598
+ it.scoped('[Then] the comment survives and the fresh assignment wins PATH precedence', () =>
599
+ Effect.gen(function* () {
600
+ const os = yield* NodeOs;
601
+ const fs = yield* FileSystem.FileSystem;
602
+ vi.stubEnv('SHELL', '/bin/zsh');
603
+ const expectedBinDir = expectedRuntimeBinDir();
604
+
605
+ const rcPath = path.join(os.homedir, '.zshrc');
606
+ yield* fs.writeFileString(
607
+ rcPath,
608
+ '# Composio CLI\n# added by my dotfiles\nexport PATH="/stale/bin:$PATH"\n# user epilogue\n'
609
+ );
610
+
611
+ yield* install();
612
+
613
+ const contents = yield* fs.readFileString(rcPath);
614
+ // No user content may ever be deleted.
615
+ expect(contents).toContain('# added by my dotfiles');
616
+ expect(contents).toContain('# user epilogue');
617
+ // Exactly one marker, directly followed by the current assignment.
618
+ expect(contents.match(/^# Composio CLI$/gm)?.length ?? 0).toBe(1);
619
+ const newAssignment = `export PATH="${expectedBinDir}:$PATH"`;
620
+ const lines = contents.split('\n');
621
+ const markerIndex = lines.findIndex(line => line.trim() === '# Composio CLI');
622
+ expect(lines[markerIndex + 1]).toBe(newAssignment);
623
+ // Prepend-style exports make the last-sourced assignment win, so the
624
+ // fresh assignment must be removed-or-after any surviving stale one.
625
+ const staleIndex = contents.indexOf('export PATH="/stale/bin:$PATH"');
626
+ expect(contents.indexOf(newAssignment)).toBeGreaterThan(staleIndex);
627
+ })
628
+ );
629
+ });
630
+ });
631
+
632
+ describe('[When] a blank line sits between the managed marker and the stale export', () => {
633
+ layer(InstallTestLive())(it => {
634
+ it.scoped('[Then] nothing but the marker is removed and the fresh assignment wins', () =>
635
+ Effect.gen(function* () {
636
+ const os = yield* NodeOs;
637
+ const fs = yield* FileSystem.FileSystem;
638
+ vi.stubEnv('SHELL', '/bin/zsh');
639
+ const expectedBinDir = expectedRuntimeBinDir();
640
+
641
+ const rcPath = path.join(os.homedir, '.zshrc');
642
+ yield* fs.writeFileString(
643
+ rcPath,
644
+ '# user prologue\n# Composio CLI\n\nexport PATH="/stale/bin:$PATH"\n'
645
+ );
646
+
647
+ yield* install();
648
+
649
+ const contents = yield* fs.readFileString(rcPath);
650
+ expect(contents).toContain('# user prologue');
651
+ expect(contents.match(/^# Composio CLI$/gm)?.length ?? 0).toBe(1);
652
+ const newAssignment = `export PATH="${expectedBinDir}:$PATH"`;
653
+ const lines = contents.split('\n');
654
+ const markerIndex = lines.findIndex(line => line.trim() === '# Composio CLI');
655
+ expect(lines[markerIndex + 1]).toBe(newAssignment);
656
+ const staleIndex = contents.indexOf('export PATH="/stale/bin:$PATH"');
657
+ expect(contents.indexOf(newAssignment)).toBeGreaterThan(staleIndex);
658
+ })
659
+ );
660
+ });
661
+ });
662
+
663
describe('[When] .bashrc and .bash_profile alias one physical file with a stale managed block', () => {
664
layer(InstallTestLive())(it => {
665
it.scoped('[Then] the physical file ends with exactly one current block', () =>
@@ -630,6 +697,29 @@ describe('CLI: composio install', () => {
697
});
698
});
699
700
+ describe('[When] the atomic write cannot replace the target file', () => {
701
+ layer(InstallTestLive())(it => {
702
+ it.scoped('[Then] the error propagates and no .composio-tmp file is left behind', () =>
703
+ Effect.gen(function* () {
704
+ const os = yield* NodeOs;
705
+ const fs = yield* FileSystem.FileSystem;
706
+ vi.stubEnv('SHELL', '/bin/zsh');
707
+
708
+ // A directory at the rc path makes the final rename(file, dir) fail
709
+ // after the temp file was already written.
710
+ const rcPath = path.join(os.homedir, '.zshrc');
711
+ yield* fs.remove(rcPath, { force: true, recursive: true });
712
+ yield* fs.makeDirectory(rcPath);
713
+
714
+ const exit = yield* install().pipe(Effect.exit);
715
+
716
+ expect(Exit.isFailure(exit)).toBe(true);
717
+ expect(yield* fs.exists(`${rcPath}.composio-tmp`)).toBe(false);
718
+ })
719
+ );
720
+ });
721
+ });
722
+
723
describe('[When] COMPOSIO_CLI_INVOCATION_ORIGIN=installer delegates shell setup', () => {
724
layer(InstallTestLive())(it => {
725
it.scoped('[Then] keeps the Updated status line but suppresses the restart hint', () =>