Skip to content

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(cli): migrate legacy three-line managed blocks in both reconcilers

jkomyno6e3f5af66d94
diff --git a/install.sh b/install.sh
index cb07a8049..b976db2c4 100755
--- a/install.sh
+++ b/install.sh
@@ -458,12 +458,33 @@ write_path_block() {
return line ~ /^[[:space:]]*export PATH=".*:\$PATH"[[:space:]]*$/ ||
line ~ /^[[:space:]]*set --export PATH ".*" \$PATH[[:space:]]*$/
}
+ # The previously released installer wrote a three-line managed block:
+ # the marker, an install-dir export, then a PATH line referencing it.
+ # Recognizing that exact pair migrates the whole legacy block instead
+ # of orphaning the two export lines once the marker is consumed.
+ function is_legacy_install_dir_assignment(line) {
+ return line ~ /^[[:space:]]*export COMPOSIO_INSTALL_DIR=".*"[[:space:]]*$/ ||
+ line ~ /^[[:space:]]*set --export COMPOSIO_INSTALL_DIR ".*"[[:space:]]*$/
+ }
+ function is_legacy_pair(first, second) {
+ if (first ~ /^[[:space:]]*export COMPOSIO_INSTALL_DIR=".*"[[:space:]]*$/)
+ return second ~ /^[[:space:]]*export PATH="\$COMPOSIO_INSTALL_DIR:\$PATH"[[:space:]]*$/
+ return second ~ /^[[:space:]]*set --export PATH \$COMPOSIO_INSTALL_DIR \$PATH[[:space:]]*$/
+ }
+ holding {
+ holding = 0
+ if (is_legacy_pair(held, $0)) { held = ""; next }
+ print held
+ held = ""
+ }
pending {
pending = 0
if (is_managed_path_assignment($0)) next
+ if (is_legacy_install_dir_assignment($0)) { held = $0; holding = 1; next }
}
$0 == "# Composio CLI" { pending = 1; next }
{ print }
+ END { if (holding) print held }
' "$write_path_target" >"$write_path_tmp" 2>/dev/null; then
rm -f "$write_path_tmp"
return 1
diff --git a/test/managed-block-fixtures/legacy-migrate-bash/after b/test/managed-block-fixtures/legacy-migrate-bash/after
new file mode 100644
index 000000000..e7ac8b4cd
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-migrate-bash/after
@@ -0,0 +1,5 @@
+# bashrc prologue
+
+
+# Composio CLI
+export PATH="/opt/composio/bin:$PATH"
diff --git a/test/managed-block-fixtures/legacy-migrate-bash/before b/test/managed-block-fixtures/legacy-migrate-bash/before
new file mode 100644
index 000000000..fd4669a42
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-migrate-bash/before
@@ -0,0 +1,5 @@
+# bashrc prologue
+
+# Composio CLI
+export COMPOSIO_INSTALL_DIR="/opt/composio"
+export PATH="$COMPOSIO_INSTALL_DIR:$PATH"
diff --git a/test/managed-block-fixtures/legacy-migrate-bash/bin-dir b/test/managed-block-fixtures/legacy-migrate-bash/bin-dir
new file mode 100644
index 000000000..d1de7d329
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-migrate-bash/bin-dir
@@ -0,0 +1 @@
+/opt/composio/bin
diff --git a/test/managed-block-fixtures/legacy-migrate-bash/shell b/test/managed-block-fixtures/legacy-migrate-bash/shell
new file mode 100644
index 000000000..705963a5a
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-migrate-bash/shell
@@ -0,0 +1 @@
+bash
diff --git a/test/managed-block-fixtures/legacy-migrate-fish/after b/test/managed-block-fixtures/legacy-migrate-fish/after
new file mode 100644
index 000000000..b0c1a31a6
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-migrate-fish/after
@@ -0,0 +1,4 @@
+# fish greeting
+
+# Composio CLI
+set --export PATH "$HOME/.local/bin" $PATH
diff --git a/test/managed-block-fixtures/legacy-migrate-fish/before b/test/managed-block-fixtures/legacy-migrate-fish/before
new file mode 100644
index 000000000..c1b364554
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-migrate-fish/before
@@ -0,0 +1,4 @@
+# fish greeting
+# Composio CLI
+set --export COMPOSIO_INSTALL_DIR "/legacy/.composio"
+set --export PATH $COMPOSIO_INSTALL_DIR $PATH
diff --git a/test/managed-block-fixtures/legacy-migrate-fish/bin-dir b/test/managed-block-fixtures/legacy-migrate-fish/bin-dir
new file mode 100644
index 000000000..4b54df1d6
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-migrate-fish/bin-dir
@@ -0,0 +1 @@
+__HOME__/.local/bin
diff --git a/test/managed-block-fixtures/legacy-migrate-fish/shell b/test/managed-block-fixtures/legacy-migrate-fish/shell
new file mode 100644
index 000000000..568650a54
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-migrate-fish/shell
@@ -0,0 +1 @@
+fish
diff --git a/test/managed-block-fixtures/legacy-migrate-zsh/after b/test/managed-block-fixtures/legacy-migrate-zsh/after
new file mode 100644
index 000000000..0cdd9c1df
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-migrate-zsh/after
@@ -0,0 +1,5 @@
+# user prologue
+alias ll="ls -la"
+
+# Composio CLI
+export PATH="$HOME/.local/bin:$PATH"
diff --git a/test/managed-block-fixtures/legacy-migrate-zsh/before b/test/managed-block-fixtures/legacy-migrate-zsh/before
new file mode 100644
index 000000000..08496e12e
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-migrate-zsh/before
@@ -0,0 +1,5 @@
+# user prologue
+# Composio CLI
+export COMPOSIO_INSTALL_DIR="$HOME/.composio"
+export PATH="$COMPOSIO_INSTALL_DIR:$PATH"
+alias ll="ls -la"
diff --git a/test/managed-block-fixtures/legacy-migrate-zsh/bin-dir b/test/managed-block-fixtures/legacy-migrate-zsh/bin-dir
new file mode 100644
index 000000000..4b54df1d6
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-migrate-zsh/bin-dir
@@ -0,0 +1 @@
+__HOME__/.local/bin
diff --git a/test/managed-block-fixtures/legacy-migrate-zsh/shell b/test/managed-block-fixtures/legacy-migrate-zsh/shell
new file mode 100644
index 000000000..0abc84369
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-migrate-zsh/shell
@@ -0,0 +1 @@
+zsh
diff --git a/test/managed-block-fixtures/legacy-near-miss-zsh/after b/test/managed-block-fixtures/legacy-near-miss-zsh/after
new file mode 100644
index 000000000..d8695dad1
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-near-miss-zsh/after
@@ -0,0 +1,6 @@
+export COMPOSIO_INSTALL_DIR="/legacy/.composio"
+export PATH="/custom/bin:$PATH"
+# user epilogue
+
+# Composio CLI
+export PATH="$HOME/.local/bin:$PATH"
diff --git a/test/managed-block-fixtures/legacy-near-miss-zsh/before b/test/managed-block-fixtures/legacy-near-miss-zsh/before
new file mode 100644
index 000000000..f8f9395e4
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-near-miss-zsh/before
@@ -0,0 +1,4 @@
+# Composio CLI
+export COMPOSIO_INSTALL_DIR="/legacy/.composio"
+export PATH="/custom/bin:$PATH"
+# user epilogue
diff --git a/test/managed-block-fixtures/legacy-near-miss-zsh/bin-dir b/test/managed-block-fixtures/legacy-near-miss-zsh/bin-dir
new file mode 100644
index 000000000..4b54df1d6
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-near-miss-zsh/bin-dir
@@ -0,0 +1 @@
+__HOME__/.local/bin
diff --git a/test/managed-block-fixtures/legacy-near-miss-zsh/shell b/test/managed-block-fixtures/legacy-near-miss-zsh/shell
new file mode 100644
index 000000000..0abc84369
--- /dev/null
+++ b/test/managed-block-fixtures/legacy-near-miss-zsh/shell
@@ -0,0 +1 @@
+zsh
diff --git a/ts/packages/cli/src/commands/install.cmd.ts b/ts/packages/cli/src/commands/install.cmd.ts
index f49b8db5e..e28dda2d6 100644
--- a/ts/packages/cli/src/commands/install.cmd.ts
+++ b/ts/packages/cli/src/commands/install.cmd.ts
@@ -280,6 +280,43 @@ const isManagedPathAssignment = (line: string): boolean => {
);
};
+const LEGACY_POSIX_INSTALL_DIR_PREFIX = 'export COMPOSIO_INSTALL_DIR="';
+const LEGACY_FISH_INSTALL_DIR_PREFIX = 'set --export COMPOSIO_INSTALL_DIR "';
+
+/**
+ * The install-dir assignment the previously released installer wrote as the
+ * second line of its three-line managed block: POSIX
+ * `export COMPOSIO_INSTALL_DIR="<dir>"` or fish
+ * `set --export COMPOSIO_INSTALL_DIR "<dir>"`. Matched structurally on the
+ * prefix/quotes (any dir), like `isManagedPathAssignment`.
+ */
+const isLegacyInstallDirAssignment = (line: string): boolean => {
+ const trimmed = line.trim();
+ return (
+ (trimmed.startsWith(LEGACY_POSIX_INSTALL_DIR_PREFIX) &&
+ trimmed.endsWith('"') &&
+ trimmed.length > LEGACY_POSIX_INSTALL_DIR_PREFIX.length) ||
+ (trimmed.startsWith(LEGACY_FISH_INSTALL_DIR_PREFIX) &&
+ trimmed.endsWith('"') &&
+ trimmed.length > LEGACY_FISH_INSTALL_DIR_PREFIX.length)
+ );
+};
+
+/**
+ * True when `first` and `second` are the two export lines of the legacy
+ * three-line block, in the same shell dialect. The closing PATH line is
+ * matched byte-for-byte (modulo surrounding whitespace) against the exact
+ * text the legacy installer emitted, so anything else after an install-dir
+ * assignment is user content and stays untouched.
+ */
+const isLegacyManagedPair = (first: string, second: string): boolean => {
+ if (!isLegacyInstallDirAssignment(first)) return false;
+ const secondTrimmed = second.trim();
+ return first.trim().startsWith(LEGACY_POSIX_INSTALL_DIR_PREFIX)
+ ? secondTrimmed === 'export PATH="$COMPOSIO_INSTALL_DIR:$PATH"'
+ : secondTrimmed === 'set --export PATH $COMPOSIO_INSTALL_DIR $PATH';
+};
+
/**
* Append managed blocks after existing content, separated by one blank line
* and ending with a newline. Content lacking a final newline gains one first,
@@ -300,9 +337,12 @@ export const appendManagedBlocks = (contents: string, blocks: readonly string[])
* land in install.sh too. A file whose single byte-exact marker is directly
* followed by the expected assignment is current and left untouched.
* Otherwise every managed line — each marker, plus the next line only when it
- * is a recognizable managed PATH assignment; anything else (a user
- * annotation, a blank line, another marker) is not ours to delete — is
- * removed and one fresh block is appended after the remaining content. No
+ * is a recognizable managed PATH assignment, or the next two lines when they
+ * are the exact export pair of the legacy three-line block (marker,
+ * `export COMPOSIO_INSTALL_DIR=...`, PATH line, in POSIX or fish form);
+ * anything else (a user annotation, a blank line, another marker) is not
+ * ours to delete — is removed and one fresh block is appended after the
+ * remaining content. No
* user content is ever deleted, and because these prepend-style assignments
* make the last-sourced line win, the new bin dir takes PATH precedence over
* any orphaned stale assignment that had to be preserved.
@@ -322,13 +362,19 @@ export const reconcileManagedPathBlock = (
}
// Managed lines: each marker line, plus the next line only when it is a
- // recognizable managed PATH assignment — anything else is not ours to delete.
+ // recognizable managed PATH assignment, or the next two lines when they are
+ // the exact export pair of the legacy three-line block — anything else is
+ // not ours to delete.
const managedLineIndexes = new Set<number>(
markerIndexes.flatMap(markerIndex => {
const assignment = lines[markerIndex + 1];
- return assignment !== undefined && isManagedPathAssignment(assignment)
- ? [markerIndex, markerIndex + 1]
- : [markerIndex];
+ if (assignment === undefined) return [markerIndex];
+ if (isManagedPathAssignment(assignment)) return [markerIndex, markerIndex + 1];
+ const legacyPathLine = lines[markerIndex + 2];
+ if (legacyPathLine !== undefined && isLegacyManagedPair(assignment, legacyPathLine)) {
+ return [markerIndex, markerIndex + 1, markerIndex + 2];
+ }
+ return [markerIndex];
})
);