Skip to content

refactor(launcher): extract shared launcher logic into util.ts#144

Open
amondnet wants to merge 1 commit intomainfrom
111-refactor-extract-shared-launcher-logic-from-clits-and-mcpts-into-a-shared-utility
Open

refactor(launcher): extract shared launcher logic into util.ts#144
amondnet wants to merge 1 commit intomainfrom
111-refactor-extract-shared-launcher-logic-from-clits-and-mcpts-into-a-shared-utility

Conversation

@amondnet
Copy link
Contributor

@amondnet amondnet commented Feb 28, 2026

Summary

  • Extracted duplicated detectLibc, getPackageSuffix, and findBinary functions from scripts/launcher/cli.ts and scripts/launcher/mcp.ts into a new shared scripts/launcher/util.ts module
  • Reduced each launcher file from ~119 lines to ~17 lines by importing from util.ts
  • Applied minor else-block style fix in scripts/bump-version.ts

Changes

  • scripts/launcher/util.ts — new shared utility with detectLibc, getPackageSuffix, findBinary
  • scripts/launcher/cli.ts — simplified to delegate binary lookup to findBinary('soop', import.meta.url)
  • scripts/launcher/mcp.ts — simplified to delegate binary lookup to findBinary('soop-mcp', import.meta.url)
  • scripts/bump-version.ts — minor else-block formatting fix

Test Plan

  • Verify soop CLI binary resolves correctly on Linux (glibc and musl) and macOS
  • Verify soop-mcp binary resolves correctly on the same platforms
  • Confirm no regression in existing launcher behavior

Closes #111


Summary by cubic

Extracted shared launcher logic into scripts/launcher/util.ts to remove duplication and simplify the CLI and MCP launchers. Improves cross‑platform binary resolution and satisfies Linear #111.

  • Refactors
    • Added util.ts with detectLibc, getPackageSuffix, and findBinary(binaryName, importMetaUrl).
    • Updated cli.ts and mcp.ts to use findBinary('soop', ...) and findBinary('soop-mcp', ...).
    • Minor else-block formatting fix in scripts/bump-version.ts.

Written for commit 8ec8eb9. Summary will update on new commits.

Consolidate duplicated detectLibc, getPackageSuffix, and findBinary
functions from cli.ts and mcp.ts into a shared scripts/launcher/util.ts
module. Each launcher is reduced from ~119 lines to ~17 lines.

Also apply minor else-block style fix in scripts/bump-version.ts.

Closes #111
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the launcher scripts by centralizing common utility functions into a new shared module. This significantly reduces code duplication in the cli.ts and mcp.ts files, making them more concise and easier to maintain. The change improves the overall organization and reusability of the launcher logic.

Highlights

  • Code Extraction: Extracted duplicated detectLibc, getPackageSuffix, and findBinary functions from scripts/launcher/cli.ts and scripts/launcher/mcp.ts into a new shared scripts/launcher/util.ts module.
  • Code Simplification: Reduced the size of cli.ts and mcp.ts launcher files significantly by importing common logic from the new util.ts.
  • Minor Formatting Fix: Applied a minor else-block style fix in scripts/bump-version.ts.
Changelog
  • scripts/bump-version.ts
    • Applied a minor formatting fix to an else-block.
  • scripts/launcher/cli.ts
    • Simplified the file to delegate binary lookup to the new findBinary function from util.ts.
  • scripts/launcher/mcp.ts
    • Simplified the file to delegate binary lookup to the new findBinary function from util.ts.
  • scripts/launcher/util.ts
    • Added a new shared utility file containing detectLibc, getPackageSuffix, and findBinary functions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively refactors duplicated launcher logic into a new shared utility file, scripts/launcher/util.ts, which significantly improves code reuse and maintainability across the cli.ts and mcp.ts launchers. The changes are well-executed. I have a couple of suggestions for the new util.ts file to further enhance its readability and maintainability.


// 2. Walk up directory tree from this file looking for node_modules/<package>/
let dir = __dirname
for (let i = 0; i < 10; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability and maintainability, it's recommended to replace the magic number 10 with a named constant that describes its purpose (e.g., const MAX_SEARCH_DEPTH = 10). This makes the code's intent clearer and simplifies future modifications.

Comment on lines +84 to +90
throw new Error(
`Could not find the ${packageName} binary.\n`
+ `Searched:\n${searchPaths.map(p => ` - ${p}`).join('\n')}\n\n`
+ `Make sure @pleaseai/soop is installed — the optional platform package `
+ `should be installed automatically on supported platforms.\n`
+ `If you used --no-optional, re-run without that flag.`,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The construction of this multi-line error message using string concatenation can be simplified. Using an array of strings and join('\n') would be more readable and easier to maintain.

  throw new Error(
    [
      `Could not find the ${packageName} binary.`,
      'Searched:',
      ...searchPaths.map(p => `  - ${p}`),
      '',
      'Make sure @pleaseai/soop is installed — the optional platform package should be installed automatically on supported platforms.',
      'If you used --no-optional, re-run without that flag.',
    ].join('\n'),
  )

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: extract shared launcher logic from cli.ts and mcp.ts into a shared utility

1 participant