@devries-cameron20 / composio Mirror · read-only / commits / b7c17458a
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

feat(cli): reconcile managed PATH blocks and defer final messaging to installer

jkomyno committed Aug 3, 2026 at 16:56 UTC b7c17458abbb3b6c0fd18452d4b55dc82f007b31
2 files changed +444 -70
ts/packages/cli/src/commands/install.cmd.ts
+274 -60
@@ -189,6 +189,217 @@ const buildShellConfig = (
189 const fileContains = (contents: string, marker: string): boolean =>
190 contents.split('\n').some(line => line.trim() === marker.trim());
191
192 +/** Outcome of reconciling a startup file's managed PATH block against the resolved bin dir. */
193 +type ManagedPathBlockState =
194 + | { readonly state: 'absent' }
195 + | { readonly state: 'current' }
196 + | { readonly state: 'stale'; readonly reconciled: string };
197 +
198 +const isAnyMarkerLine = (line: string): boolean => {
199 + const trimmed = line.trim();
200 + return trimmed === MARKER || trimmed === COMPLETIONS_MARKER;
201 +};
202 +
203 +/**
204 + * Reconcile the managed PATH block — the `MARKER` line plus the PATH
205 + * 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.
209 + */
210 +const reconcileManagedPathBlock = (contents: string, pathBlock: string): ManagedPathBlockState => {
211 + const lines = contents.split('\n');
212 + const markerIndexes = lines.flatMap((line, index) => (line.trim() === MARKER ? [index] : []));
213 + const firstMarkerIndex = markerIndexes[0];
214 + if (firstMarkerIndex === undefined) return { state: 'absent' };
215 +
216 + const expectedAssignment = (pathBlock.split('\n')[1] ?? '').trim();
217 + if (
218 + markerIndexes.length === 1 &&
219 + (lines[firstMarkerIndex + 1] ?? '').trim() === expectedAssignment
220 + ) {
221 + return { state: 'current' };
222 + }
223 +
224 + // Managed lines: each marker line and its assignment line, unless that next
225 + // line is itself a marker (never consume the completions block).
226 + const managedLineIndexes = new Set<number>(
227 + markerIndexes.flatMap(markerIndex => {
228 + const assignment = lines[markerIndex + 1];
229 + return assignment !== undefined && !isAnyMarkerLine(assignment)
230 + ? [markerIndex, markerIndex + 1]
231 + : [markerIndex];
232 + })
233 + );
234 +
235 + const reconciledLines = lines.flatMap((line, index) => {
236 + if (index === firstMarkerIndex) return pathBlock.split('\n');
237 + return managedLineIndexes.has(index) ? [] : [line];
238 + });
239 + return { state: 'stale', reconciled: reconciledLines.join('\n') };
240 +};
241 +
242 +interface ManagedBlockReplacement {
243 + readonly contents: string;
244 + readonly displayPath: string;
245 +}
246 +
247 +interface PathBlockWritePlan {
248 + readonly appendPathFiles: readonly string[];
249 + readonly replacementsByTarget: ReadonlyMap<string, ManagedBlockReplacement>;
250 + readonly loginOverrideWritten: boolean;
251 +}
252 +
253 +/**
254 + * Decide, per configured PATH file, whether the managed block must be appended
255 + * (absent), replaced in place (stale bin dir), or left alone (already
256 + * current). Both appends and replacements are deduplicated by physical write
257 + * target so two logical paths aliasing the same file (a dotfiles symlink
258 + * setup) keep exactly one managed block.
259 + */
260 +const planPathBlockWrites = (params: {
261 + readonly pathFiles: readonly string[];
262 + readonly existingByFile: ReadonlyMap<string, string>;
263 + readonly pathFileTargets: ReadonlyMap<string, string>;
264 + readonly pathBlock: string;
265 + readonly bashLoginOverride: string | undefined;
266 + readonly skipPathWriteForReachability: boolean;
267 +}): PathBlockWritePlan => {
268 + const appendPathFiles: string[] = [];
269 + const replacementsByTarget = new Map<string, ManagedBlockReplacement>();
270 + const queuedPathTargets = new Set<string>();
271 + let loginOverrideWritten = false;
272 + for (const filePath of params.pathFiles) {
273 + const existing = params.existingByFile.get(filePath) ?? '';
274 + const target = params.pathFileTargets.get(filePath)!;
275 + const reconciliation = reconcileManagedPathBlock(existing, params.pathBlock);
276 + if (reconciliation.state === 'stale') {
277 + if (!replacementsByTarget.has(target)) {
278 + replacementsByTarget.set(target, {
279 + contents: reconciliation.reconciled,
280 + displayPath: filePath,
281 + });
282 + if (filePath === params.bashLoginOverride) loginOverrideWritten = true;
283 + }
284 + continue;
285 + }
286 + if (
287 + reconciliation.state === 'current' ||
288 + params.skipPathWriteForReachability ||
289 + queuedPathTargets.has(target)
290 + ) {
291 + continue;
292 + }
293 + appendPathFiles.push(filePath);
294 + queuedPathTargets.add(target);
295 + if (filePath === params.bashLoginOverride) loginOverrideWritten = true;
296 + }
297 + return { appendPathFiles, replacementsByTarget, loginOverrideWritten };
298 +};
299 +
300 +/** Atomically rewrite each reconciled physical target, preserving its file mode. */
301 +const writeReconciledTargets = (params: {
302 + readonly replacementsByTarget: ReadonlyMap<string, ManagedBlockReplacement>;
303 + readonly fs: FileSystem.FileSystem;
304 + readonly homedir: string;
305 + readonly report: (message: string) => Effect.Effect<void>;
306 +}): Effect.Effect<void, PlatformError> =>
307 + Effect.gen(function* () {
308 + for (const [writeTarget, replacement] of params.replacementsByTarget.entries()) {
309 + const existingTargetInfo = yield* params.fs.stat(writeTarget).pipe(Effect.option);
310 + const tmpPath = `${writeTarget}.composio-tmp`;
311 +
312 + yield* params.fs.writeFileString(tmpPath, replacement.contents);
313 + if (Option.isSome(existingTargetInfo)) {
314 + yield* params.fs.chmod(tmpPath, existingTargetInfo.value.mode & 0o7777);
315 + }
316 + yield* params.fs.rename(tmpPath, writeTarget);
317 +
318 + yield* params.report(`Updated ${tildify(replacement.displayPath, params.homedir)}`);
319 + }
320 + });
321 +
322 +/** Completion status line, plus whether the completion block still needs appending. */
323 +const planCompletionWrite = (params: {
324 + readonly shell: Shell;
325 + readonly completionsRequested: boolean;
326 + readonly completionBlock: string | undefined;
327 + readonly completionFile: string;
328 + readonly existingCompletionFile: string;
329 + readonly homedir: string;
330 +}): { readonly statusLine: string; readonly append: boolean } => {
331 + if (params.shell === 'zsh') {
332 + return { statusLine: 'Completions: skipped for zsh', append: false };
333 + }
334 + if (!params.completionsRequested) {
335 + return {
336 + statusLine: 'Completions: skipped by default (pass --completions to enable)',
337 + append: false,
338 + };
339 + }
340 + if (!params.completionBlock) {
341 + return { statusLine: 'Completions: not available for this shell', append: false };
342 + }
343 + if (fileContains(params.existingCompletionFile, COMPLETIONS_MARKER)) {
344 + return { statusLine: 'Completions: already configured', append: false };
345 + }
346 + return {
347 + statusLine:
348 + params.shell === 'fish'
349 + ? `Completions: will install fish completions to ${tildify(params.completionFile, params.homedir)}`
350 + : 'Completions: will install shell completions',
351 + append: true,
352 + };
353 +};
354 +
355 +/** Status lines summarizing the planned PATH work, in print order. */
356 +const pathStatusLines = (params: {
357 + readonly pathWritten: boolean;
358 + readonly pathReplaced: boolean;
359 + readonly skipPathWriteForReachability: boolean;
360 + readonly renderedBinDir: string;
361 +}): readonly string[] => {
362 + const lines: string[] = [];
363 + if (params.pathWritten) lines.push(`PATH: will add ${params.renderedBinDir} to $PATH`);
364 + if (params.pathReplaced) {
365 + lines.push(`PATH: will update the managed block to ${params.renderedBinDir}`);
366 + }
367 + if (lines.length === 0) {
368 + lines.push(
369 + params.skipPathWriteForReachability
370 + ? 'PATH: already on $PATH — nothing to do.'
371 + : 'PATH: already configured'
372 + );
373 + }
374 + return lines;
375 +};
376 +
377 +/** Shell-specific body of the restart hint printed after a change. */
378 +const restartHintBody = (params: {
379 + readonly shell: Shell;
380 + readonly zshPathFile: string;
381 + readonly bashrc: string;
382 + readonly bashLoginOverride: string | undefined;
383 + readonly loginOverrideWritten: boolean;
384 + readonly homedir: string;
385 +}): string => {
386 + switch (params.shell) {
387 + case 'fish':
388 + return 'exec fish';
389 + case 'zsh':
390 + return `source ${tildify(params.zshPathFile, params.homedir)}`;
391 + case 'bash': {
392 + const hintLines = [`source ${tildify(params.bashrc, params.homedir)}`];
393 + if (params.loginOverrideWritten && params.bashLoginOverride) {
394 + hintLines.push(
395 + `${tildify(params.bashLoginOverride, params.homedir)} was also updated — that entry applies to new login shells too.`
396 + );
397 + }
398 + return hintLines.join('\n');
399 + }
400 + }
401 +};
402 +
403 const tildify = (p: string, homedir: string): string =>
404 p.startsWith(homedir + '/') ? `~/${p.slice(homedir.length + 1)}` : p;
405
@@ -276,6 +487,13 @@ export const installShellIntegration = (params: {
487 return;
488 }
489
490 + // KD7 (final-block contract): when install.sh delegates to this command it
491 + // passes COMPOSIO_CLI_INVOCATION_ORIGIN=installer and owns the final action
492 + // block itself. Keep the concise per-file status lines but suppress the
493 + // boxed restart hint so the CLI never prints a competing instruction.
494 + const invocationOrigin = yield* readOptionalEnv('COMPOSIO_CLI_INVOCATION_ORIGIN');
495 + const installerOwnsFinalMessaging = invocationOrigin === 'installer';
496 +
497 const isExplicitShell = params.shell !== undefined;
498 const shellEnv = yield* readEnvWithDefault('SHELL', '');
499 const shell = params.shell ?? detectShellFromEnv(path, shellEnv);
@@ -358,52 +576,51 @@ export const installShellIntegration = (params: {
576 );
577 const skipPathWriteForReachability =
578 !isExplicitShell && binDirOnPath && !anyPathFileAlreadyMarked;
361 - let pathWritten = false;
362 - let loginOverrideWritten = false;
363 - const queuedPathTargets = new Set<string>();
364 - for (const filePath of config.pathFiles) {
365 - const existing = existingByFile.get(filePath) ?? '';
366 - const target = pathFileTargets.get(filePath)!;
367 - if (
368 - fileContains(existing, MARKER) ||
369 - skipPathWriteForReachability ||
370 - queuedPathTargets.has(target)
371 - ) {
372 - continue;
373 - }
579 + const writePlan = planPathBlockWrites({
580 + pathFiles: config.pathFiles,
581 + existingByFile,
582 + pathFileTargets,
583 + pathBlock: config.pathBlock,
584 + bashLoginOverride,
585 + skipPathWriteForReachability,
586 + });
587 + const { replacementsByTarget, loginOverrideWritten } = writePlan;
588 + for (const filePath of writePlan.appendPathFiles) {
589 pushBlock(filePath, config.pathBlock);
375 - queuedPathTargets.add(target);
376 - pathWritten = true;
377 - if (filePath === bashLoginOverride) loginOverrideWritten = true;
590 }
591 + const pathWritten = writePlan.appendPathFiles.length > 0;
592 +
593 + yield* Effect.forEach(
594 + pathStatusLines({
595 + pathWritten,
596 + pathReplaced: replacementsByTarget.size > 0,
597 + skipPathWriteForReachability,
598 + renderedBinDir: tildify(binDir, os.homedir),
599 + }),
600 + step
601 + );
602
380 - if (pathWritten) {
381 - yield* step(`PATH: will add ${tildify(binDir, os.homedir)} to $PATH`);
382 - } else if (skipPathWriteForReachability) {
383 - yield* step('PATH: already on $PATH — nothing to do.');
384 - } else {
385 - yield* step('PATH: already configured');
603 + const completionWrite = planCompletionWrite({
604 + shell,
605 + completionsRequested: params.completions,
606 + completionBlock: config.completionBlock,
607 + completionFile: config.completionFile,
608 + existingCompletionFile: existingByFile.get(config.completionFile) ?? '',
609 + homedir: os.homedir,
610 + });
611 + if (completionWrite.append && config.completionBlock) {
612 + pushBlock(config.completionFile, config.completionBlock);
613 }
614 + yield* step(completionWrite.statusLine);
615
388 - if (shell === 'zsh') {
389 - yield* step('Completions: skipped for zsh');
390 - } else if (!params.completions) {
391 - yield* step('Completions: skipped by default (pass --completions to enable)');
392 - } else if (!config.completionBlock) {
393 - yield* step('Completions: not available for this shell');
394 - } else {
395 - const existingCompletionFile = existingByFile.get(config.completionFile) ?? '';
396 - if (!fileContains(existingCompletionFile, COMPLETIONS_MARKER)) {
397 - pushBlock(config.completionFile, config.completionBlock);
398 - yield* step(
399 - config.shell === 'fish'
400 - ? `Completions: will install fish completions to ${tildify(config.completionFile, os.homedir)}`
401 - : 'Completions: will install shell completions'
402 - );
403 - } else {
404 - yield* step('Completions: already configured');
405 - }
406 - }
616 + // Reconcile stale managed blocks first so any completion append below
617 + // (which re-reads from disk) lands on top of the replaced contents.
618 + yield* writeReconciledTargets({
619 + replacementsByTarget,
620 + fs,
621 + homedir: os.homedir,
622 + report: success,
623 + });
624
625 if (blocksByFile.size > 0) {
626 for (const [filePath, blocks] of blocksByFile.entries()) {
@@ -435,28 +652,25 @@ export const installShellIntegration = (params: {
652
653 yield* success(`Updated ${tildify(filePath, os.homedir)}`);
654 }
438 - } else {
655 + }
656 +
657 + const changesWritten = blocksByFile.size > 0 || replacementsByTarget.size > 0;
658 + if (!changesWritten) {
659 yield* success('Shell integration already configured — nothing to do.');
660 }
661
442 - if (blocksByFile.size > 0) {
443 - if (shell === 'fish') {
444 - yield* note('exec fish', 'Restart your shell to apply changes');
445 - } else if (shell === 'zsh') {
446 - yield* note(
447 - `source ${tildify(config.pathFiles[0]!, os.homedir)}`,
448 - 'Restart your shell to apply changes'
449 - );
450 - } else {
451 - const bashrc = path.join(os.homedir, '.bashrc');
452 - const hintLines = [`source ${tildify(bashrc, os.homedir)}`];
453 - if (loginOverrideWritten && bashLoginOverride) {
454 - hintLines.push(
455 - `${tildify(bashLoginOverride, os.homedir)} was also updated — that entry applies to new login shells too.`
456 - );
457 - }
458 - yield* note(hintLines.join('\n'), 'Restart your shell to apply changes');
459 - }
662 + if (changesWritten && !installerOwnsFinalMessaging) {
663 + yield* note(
664 + restartHintBody({
665 + shell,
666 + zshPathFile: config.pathFiles[0]!,
667 + bashrc: path.join(os.homedir, '.bashrc'),
668 + bashLoginOverride,
669 + loginOverrideWritten,
670 + homedir: os.homedir,
671 + }),
672 + 'Restart your shell to apply changes'
673 + );
674 }
675
676 yield* ui.outro('Done');
ts/packages/cli/test/src/commands/install.cmd.test.ts
+170 -10
@@ -74,6 +74,8 @@ describe('CLI: composio install', () => {
74 Effect.gen(function* () {
75 const os = yield* NodeOs;
76 vi.stubEnv('SHELL', '/bin/zsh');
77 + // A direct invocation (no installer origin) keeps the restart hint.
78 + vi.stubEnv('COMPOSIO_CLI_INVOCATION_ORIGIN', '');
79 const expectedBinDir = expectedRuntimeBinDir();
80
81 yield* install();
@@ -93,6 +95,7 @@ describe('CLI: composio install', () => {
95 expect(output).toContain('PATH: will add');
96 expect(output).toContain('Completions: skipped for zsh');
97 expect(output).toContain('Updated');
98 + expect(output).toContain('Restart your shell to apply changes');
99 expect(output).toContain('source ~/.zshrc');
100 })
101 );
@@ -500,20 +503,19 @@ describe('CLI: composio install', () => {
503 });
504 });
505
503 - describe('[When] .zshrc already has the marker', () => {
506 + describe('[When] .zshrc already has a managed block recording the current bin dir', () => {
507 layer(InstallTestLive())(it => {
505 - it.scoped('[Then] reports already configured', () =>
508 + it.scoped('[Then] reports already configured and leaves the file byte-identical', () =>
509 Effect.gen(function* () {
510 const os = yield* NodeOs;
511 const fs = yield* FileSystem.FileSystem;
512 vi.stubEnv('SHELL', '/bin/zsh');
513 + const expectedBinDir = expectedRuntimeBinDir();
514
511 - // Pre-populate .zshrc with existing config
515 + // Pre-populate .zshrc with a managed block that is already current.
516 const rcPath = path.join(os.homedir, '.zshrc');
513 - yield* fs.writeFileString(
514 - rcPath,
515 - '# existing config\n# Composio CLI\nexport PATH="$HOME/.local/bin:$PATH"\n# Composio CLI completions\n_composio() {}\n'
516 - );
517 + const original = `# existing config\n# Composio CLI\nexport PATH="${expectedBinDir}:$PATH"\n# Composio CLI completions\n_composio() {}\n`;
518 + yield* fs.writeFileString(rcPath, original);
519
520 yield* install({ completions: true });
521
@@ -522,11 +524,169 @@ describe('CLI: composio install', () => {
524 expect(output).toContain('PATH: already configured');
525 expect(output).toContain('Completions: skipped for zsh');
526 expect(output).toContain('Shell integration already configured');
527 + expect(output).not.toContain('Updated');
528 +
529 + // File must not be rewritten at all.
530 + const contents = yield* fs.readFileString(rcPath);
531 + expect(contents).toBe(original);
532 + })
533 + );
534 + });
535 + });
536 +
537 + describe('[When] the managed PATH block records a stale bin dir', () => {
538 + layer(InstallTestLive())(it => {
539 + it.scoped('[Then] replaces only the managed block and keeps unmanaged content', () =>
540 + Effect.gen(function* () {
541 + const os = yield* NodeOs;
542 + const fs = yield* FileSystem.FileSystem;
543 + vi.stubEnv('SHELL', '/bin/zsh');
544 + const expectedBinDir = expectedRuntimeBinDir();
545 +
546 + const rcPath = path.join(os.homedir, '.zshrc');
547 + yield* fs.writeFileString(
548 + rcPath,
549 + '# user prologue\n# Composio CLI\nexport PATH="/stale/bin:$PATH"\n# user epilogue\nalias ll="ls -la"\n'
550 + );
551 +
552 + yield* install();
553 +
554 + const contents = yield* fs.readFileString(rcPath);
555 + expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
556 + expect(contents).not.toContain('/stale/bin');
557 + expect(contents).toContain('# user prologue');
558 + expect(contents).toContain('# user epilogue');
559 + expect(contents).toContain('alias ll="ls -la"');
560 + expect(contents.match(/^# Composio CLI$/gm)?.length ?? 0).toBe(1);
561 +
562 + const output = (yield* MockConsole.getLines()).join('\n');
563 + expect(output).toContain('Updated ~/.zshrc');
564 + })
565 + );
566 + });
567 + });
568 +
569 + describe('[When] duplicate managed PATH blocks exist in one file', () => {
570 + layer(InstallTestLive())(it => {
571 + it.scoped('[Then] they collapse into a single current block', () =>
572 + Effect.gen(function* () {
573 + const os = yield* NodeOs;
574 + const fs = yield* FileSystem.FileSystem;
575 + vi.stubEnv('SHELL', '/bin/zsh');
576 + const expectedBinDir = expectedRuntimeBinDir();
577 +
578 + const rcPath = path.join(os.homedir, '.zshrc');
579 + yield* fs.writeFileString(
580 + rcPath,
581 + `# Composio CLI\nexport PATH="/stale/bin:$PATH"\n# unmanaged line\n# Composio CLI\nexport PATH="${expectedBinDir}:$PATH"\n`
582 + );
583 +
584 + yield* install();
585
526 - // File should not have grown
586 const contents = yield* fs.readFileString(rcPath);
528 - const markerCount = contents.split('# Composio CLI').length - 1;
529 - expect(markerCount).toBe(2);
587 + expect(contents.match(/^# Composio CLI$/gm)?.length ?? 0).toBe(1);
588 + expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
589 + expect(contents).not.toContain('/stale/bin');
590 + expect(contents).toContain('# unmanaged line');
591 + })
592 + );
593 + });
594 + });
595 +
596 + describe('[When] .bashrc and .bash_profile alias one physical file with a stale managed block', () => {
597 + layer(InstallTestLive())(it => {
598 + it.scoped('[Then] the physical file ends with exactly one current block', () =>
599 + Effect.gen(function* () {
600 + const os = yield* NodeOs;
601 + const fs = yield* FileSystem.FileSystem;
602 + vi.stubEnv('SHELL', '/bin/bash');
603 + const expectedBinDir = expectedRuntimeBinDir();
604 +
605 + const bashrcPath = path.join(os.homedir, '.bashrc');
606 + const bashProfilePath = path.join(os.homedir, '.bash_profile');
607 + const managedPath = path.join(os.homedir, '.managed-bashrc');
608 + yield* fs.remove(bashrcPath, { force: true });
609 + yield* fs.writeFileString(
610 + managedPath,
611 + '# managed prologue\n# Composio CLI\nexport PATH="/stale/bin:$PATH"\n'
612 + );
613 + yield* fs.symlink(managedPath, bashrcPath);
614 + yield* fs.symlink(managedPath, bashProfilePath);
615 +
616 + yield* install();
617 +
618 + const contents = yield* fs.readFileString(managedPath);
619 + expect(contents.match(/^# Composio CLI$/gm)?.length ?? 0).toBe(1);
620 + expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
621 + expect(contents).not.toContain('/stale/bin');
622 + expect(contents).toContain('# managed prologue');
623 +
624 + // Both aliases must survive as symlinks to the same physical file.
625 + expect(yield* fs.readLink(bashrcPath)).toBe(managedPath);
626 + expect(yield* fs.readLink(bashProfilePath)).toBe(managedPath);
627 + expect(yield* fs.exists(`${managedPath}.composio-tmp`)).toBe(false);
628 + })
629 + );
630 + });
631 + });
632 +
633 + describe('[When] COMPOSIO_CLI_INVOCATION_ORIGIN=installer delegates shell setup', () => {
634 + layer(InstallTestLive())(it => {
635 + it.scoped('[Then] keeps the Updated status line but suppresses the restart hint', () =>
636 + Effect.gen(function* () {
637 + vi.stubEnv('SHELL', '/bin/zsh');
638 + vi.stubEnv('COMPOSIO_CLI_INVOCATION_ORIGIN', 'installer');
639 +
640 + yield* install();
641 +
642 + const output = (yield* MockConsole.getLines()).join('\n');
643 + expect(output).toContain('Updated ~/.zshrc');
644 + expect(output).not.toContain('Restart your shell');
645 + expect(output).not.toContain('source ~/.zshrc');
646 + })
647 + );
648 + });
649 + });
650 +
651 + describe('[When] COMPOSIO_CLI_INVOCATION_ORIGIN=installer and integration is already current', () => {
652 + layer(InstallTestLive())(it => {
653 + it.scoped('[Then] keeps the already-current status line', () =>
654 + Effect.gen(function* () {
655 + const os = yield* NodeOs;
656 + const fs = yield* FileSystem.FileSystem;
657 + vi.stubEnv('SHELL', '/bin/zsh');
658 + vi.stubEnv('COMPOSIO_CLI_INVOCATION_ORIGIN', 'installer');
659 + const expectedBinDir = expectedRuntimeBinDir();
660 +
661 + const rcPath = path.join(os.homedir, '.zshrc');
662 + yield* fs.writeFileString(
663 + rcPath,
664 + `# Composio CLI\nexport PATH="${expectedBinDir}:$PATH"\n`
665 + );
666 +
667 + yield* install();
668 +
669 + const output = (yield* MockConsole.getLines()).join('\n');
670 + expect(output).toContain('Shell integration already configured');
671 + expect(output).not.toContain('Restart your shell');
672 + })
673 + );
674 + });
675 + });
676 +
677 + describe('[When] COMPOSIO_CLI_INVOCATION_ORIGIN has a non-installer value', () => {
678 + layer(InstallTestLive())(it => {
679 + it.scoped('[Then] the restart hint still prints', () =>
680 + Effect.gen(function* () {
681 + vi.stubEnv('SHELL', '/bin/zsh');
682 + vi.stubEnv('COMPOSIO_CLI_INVOCATION_ORIGIN', 'agent');
683 +
684 + yield* install();
685 +
686 + const output = (yield* MockConsole.getLines()).join('\n');
687 + expect(output).toContain('Updated ~/.zshrc');
688 + expect(output).toContain('Restart your shell to apply changes');
689 + expect(output).toContain('source ~/.zshrc');
690 })
691 );
692 });