@devries-cameron20 / composio-1 / commits / 6e3f5af66
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.

fix(cli): migrate legacy three-line managed blocks in both reconcilers

The previous installer wrote marker + export COMPOSIO_INSTALL_DIR + PATH export. Both the shell and TypeScript reconcilers now consume that triple as one managed block instead of orphaning the export lines, with shared legacy-migrate and near-miss fixtures keeping the two implementations byte-identical.

jkomyno committed Aug 4, 2026 at 00:15 UTC 6e3f5af66d94b78658b1793d55530cb8f160219b
18 files changed +120 -7
install.sh
+21
@@ -458,12 +458,33 @@ write_path_block() {
458 return line ~ /^[[:space:]]*export PATH=".*:\$PATH"[[:space:]]*$/ ||
459 line ~ /^[[:space:]]*set --export PATH ".*" \$PATH[[:space:]]*$/
460 }
461 + # The previously released installer wrote a three-line managed block:
462 + # the marker, an install-dir export, then a PATH line referencing it.
463 + # Recognizing that exact pair migrates the whole legacy block instead
464 + # of orphaning the two export lines once the marker is consumed.
465 + function is_legacy_install_dir_assignment(line) {
466 + return line ~ /^[[:space:]]*export COMPOSIO_INSTALL_DIR=".*"[[:space:]]*$/ ||
467 + line ~ /^[[:space:]]*set --export COMPOSIO_INSTALL_DIR ".*"[[:space:]]*$/
468 + }
469 + function is_legacy_pair(first, second) {
470 + if (first ~ /^[[:space:]]*export COMPOSIO_INSTALL_DIR=".*"[[:space:]]*$/)
471 + return second ~ /^[[:space:]]*export PATH="\$COMPOSIO_INSTALL_DIR:\$PATH"[[:space:]]*$/
472 + return second ~ /^[[:space:]]*set --export PATH \$COMPOSIO_INSTALL_DIR \$PATH[[:space:]]*$/
473 + }
474 + holding {
475 + holding = 0
476 + if (is_legacy_pair(held, $0)) { held = ""; next }
477 + print held
478 + held = ""
479 + }
480 pending {
481 pending = 0
482 if (is_managed_path_assignment($0)) next
483 + if (is_legacy_install_dir_assignment($0)) { held = $0; holding = 1; next }
484 }
485 $0 == "# Composio CLI" { pending = 1; next }
486 { print }
487 + END { if (holding) print held }
488 ' "$write_path_target" >"$write_path_tmp" 2>/dev/null; then
489 rm -f "$write_path_tmp"
490 return 1
test/managed-block-fixtures/legacy-migrate-bash/after new
+5
@@ -0,0 +1,5 @@
1 +# bashrc prologue
2 +
3 +
4 +# Composio CLI
5 +export PATH="/opt/composio/bin:$PATH"
test/managed-block-fixtures/legacy-migrate-bash/before new
+5
@@ -0,0 +1,5 @@
1 +# bashrc prologue
2 +
3 +# Composio CLI
4 +export COMPOSIO_INSTALL_DIR="/opt/composio"
5 +export PATH="$COMPOSIO_INSTALL_DIR:$PATH"
test/managed-block-fixtures/legacy-migrate-bash/bin-dir new
+1
@@ -0,0 +1 @@
1 +/opt/composio/bin
test/managed-block-fixtures/legacy-migrate-bash/shell new
+1
@@ -0,0 +1 @@
1 +bash
test/managed-block-fixtures/legacy-migrate-fish/after new
+4
@@ -0,0 +1,4 @@
1 +# fish greeting
2 +
3 +# Composio CLI
4 +set --export PATH "$HOME/.local/bin" $PATH
test/managed-block-fixtures/legacy-migrate-fish/before new
+4
@@ -0,0 +1,4 @@
1 +# fish greeting
2 +# Composio CLI
3 +set --export COMPOSIO_INSTALL_DIR "/legacy/.composio"
4 +set --export PATH $COMPOSIO_INSTALL_DIR $PATH
test/managed-block-fixtures/legacy-migrate-fish/bin-dir new
+1
@@ -0,0 +1 @@
1 +__HOME__/.local/bin
test/managed-block-fixtures/legacy-migrate-fish/shell new
+1
@@ -0,0 +1 @@
1 +fish
test/managed-block-fixtures/legacy-migrate-zsh/after new
+5
@@ -0,0 +1,5 @@
1 +# user prologue
2 +alias ll="ls -la"
3 +
4 +# Composio CLI
5 +export PATH="$HOME/.local/bin:$PATH"
test/managed-block-fixtures/legacy-migrate-zsh/before new
+5
@@ -0,0 +1,5 @@
1 +# user prologue
2 +# Composio CLI
3 +export COMPOSIO_INSTALL_DIR="$HOME/.composio"
4 +export PATH="$COMPOSIO_INSTALL_DIR:$PATH"
5 +alias ll="ls -la"
test/managed-block-fixtures/legacy-migrate-zsh/bin-dir new
+1
@@ -0,0 +1 @@
1 +__HOME__/.local/bin
test/managed-block-fixtures/legacy-migrate-zsh/shell new
+1
@@ -0,0 +1 @@
1 +zsh
test/managed-block-fixtures/legacy-near-miss-zsh/after new
+6
@@ -0,0 +1,6 @@
1 +export COMPOSIO_INSTALL_DIR="/legacy/.composio"
2 +export PATH="/custom/bin:$PATH"
3 +# user epilogue
4 +
5 +# Composio CLI
6 +export PATH="$HOME/.local/bin:$PATH"
test/managed-block-fixtures/legacy-near-miss-zsh/before new
+4
@@ -0,0 +1,4 @@
1 +# Composio CLI
2 +export COMPOSIO_INSTALL_DIR="/legacy/.composio"
3 +export PATH="/custom/bin:$PATH"
4 +# user epilogue
test/managed-block-fixtures/legacy-near-miss-zsh/bin-dir new
+1
@@ -0,0 +1 @@
1 +__HOME__/.local/bin
test/managed-block-fixtures/legacy-near-miss-zsh/shell new
+1
@@ -0,0 +1 @@
1 +zsh
ts/packages/cli/src/commands/install.cmd.ts
+53 -7
@@ -280,6 +280,43 @@ const isManagedPathAssignment = (line: string): boolean => {
280 );
281 };
282
283 +const LEGACY_POSIX_INSTALL_DIR_PREFIX = 'export COMPOSIO_INSTALL_DIR="';
284 +const LEGACY_FISH_INSTALL_DIR_PREFIX = 'set --export COMPOSIO_INSTALL_DIR "';
285 +
286 +/**
287 + * The install-dir assignment the previously released installer wrote as the
288 + * second line of its three-line managed block: POSIX
289 + * `export COMPOSIO_INSTALL_DIR="<dir>"` or fish
290 + * `set --export COMPOSIO_INSTALL_DIR "<dir>"`. Matched structurally on the
291 + * prefix/quotes (any dir), like `isManagedPathAssignment`.
292 + */
293 +const isLegacyInstallDirAssignment = (line: string): boolean => {
294 + const trimmed = line.trim();
295 + return (
296 + (trimmed.startsWith(LEGACY_POSIX_INSTALL_DIR_PREFIX) &&
297 + trimmed.endsWith('"') &&
298 + trimmed.length > LEGACY_POSIX_INSTALL_DIR_PREFIX.length) ||
299 + (trimmed.startsWith(LEGACY_FISH_INSTALL_DIR_PREFIX) &&
300 + trimmed.endsWith('"') &&
301 + trimmed.length > LEGACY_FISH_INSTALL_DIR_PREFIX.length)
302 + );
303 +};
304 +
305 +/**
306 + * True when `first` and `second` are the two export lines of the legacy
307 + * three-line block, in the same shell dialect. The closing PATH line is
308 + * matched byte-for-byte (modulo surrounding whitespace) against the exact
309 + * text the legacy installer emitted, so anything else after an install-dir
310 + * assignment is user content and stays untouched.
311 + */
312 +const isLegacyManagedPair = (first: string, second: string): boolean => {
313 + if (!isLegacyInstallDirAssignment(first)) return false;
314 + const secondTrimmed = second.trim();
315 + return first.trim().startsWith(LEGACY_POSIX_INSTALL_DIR_PREFIX)
316 + ? secondTrimmed === 'export PATH="$COMPOSIO_INSTALL_DIR:$PATH"'
317 + : secondTrimmed === 'set --export PATH $COMPOSIO_INSTALL_DIR $PATH';
318 +};
319 +
320 /**
321 * Append managed blocks after existing content, separated by one blank line
322 * 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[])
337 * land in install.sh too. A file whose single byte-exact marker is directly
338 * followed by the expected assignment is current and left untouched.
339 * Otherwise every managed line — each marker, plus the next line only when it
303 - * is a recognizable managed PATH assignment; anything else (a user
304 - * annotation, a blank line, another marker) is not ours to delete — is
305 - * removed and one fresh block is appended after the remaining content. No
340 + * is a recognizable managed PATH assignment, or the next two lines when they
341 + * are the exact export pair of the legacy three-line block (marker,
342 + * `export COMPOSIO_INSTALL_DIR=...`, PATH line, in POSIX or fish form);
343 + * anything else (a user annotation, a blank line, another marker) is not
344 + * ours to delete — is removed and one fresh block is appended after the
345 + * remaining content. No
346 * user content is ever deleted, and because these prepend-style assignments
347 * make the last-sourced line win, the new bin dir takes PATH precedence over
348 * any orphaned stale assignment that had to be preserved.
@@ -322,13 +362,19 @@ export const reconcileManagedPathBlock = (
362 }
363
364 // Managed lines: each marker line, plus the next line only when it is a
325 - // recognizable managed PATH assignment — anything else is not ours to delete.
365 + // recognizable managed PATH assignment, or the next two lines when they are
366 + // the exact export pair of the legacy three-line block — anything else is
367 + // not ours to delete.
368 const managedLineIndexes = new Set<number>(
369 markerIndexes.flatMap(markerIndex => {
370 const assignment = lines[markerIndex + 1];
329 - return assignment !== undefined && isManagedPathAssignment(assignment)
330 - ? [markerIndex, markerIndex + 1]
331 - : [markerIndex];
371 + if (assignment === undefined) return [markerIndex];
372 + if (isManagedPathAssignment(assignment)) return [markerIndex, markerIndex + 1];
373 + const legacyPathLine = lines[markerIndex + 2];
374 + if (legacyPathLine !== undefined && isLegacyManagedPair(assignment, legacyPathLine)) {
375 + return [markerIndex, markerIndex + 1, markerIndex + 2];
376 + }
377 + return [markerIndex];
378 })
379 );
380