Skip to content

Display terminal links in cursor #1998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 1, 2025
Merged

Display terminal links in cursor #1998

merged 7 commits into from
May 1, 2025

Conversation

nicktrn
Copy link
Collaborator

@nicktrn nicktrn commented Apr 30, 2025

Our previous patch was never applied to CLI releases. Easiest fix was to pull in the required package code directly into the CLI and add our patch there. This also removes the old patch and terminal-link package.

Summary by CodeRabbit

  • New Features
    • Enhanced terminal output with clickable links, including support for both stdout and stderr streams, and customizable fallback behavior when hyperlinks are unsupported.
  • Chores
    • Updated and cleaned up dependencies related to terminal hyperlink support.
    • Improved detection of terminal environments that support hyperlinks.
    • Removed deprecated or unused packages and type declarations.

Copy link

changeset-bot bot commented Apr 30, 2025

⚠️ No Changeset found

Latest commit: 641ca67

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Apr 30, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This set of changes updates how terminal hyperlink support is detected and how clickable links are generated in terminal output within the CLI package. A new local implementation replaces the previous reliance on external dependencies for hyperlink detection and link formatting. New utility modules are introduced for these purposes, and related dependencies are updated in the package configuration files. The patch for "supports-hyperlinks" is removed, and the "terminal-link" dependency is eliminated from both the CLI and SDK packages. Type declarations for the previous "terminal-link" module are also deleted.

Changes

File(s) Change Summary
package.json, patches/supports-hyperlinks@2.3.0.patch Removed the patch entry and patch file for "supports-hyperlinks@2.3.0" from the root package configuration.
packages/cli-v3/package.json, packages/trigger-sdk/package.json Updated dependencies: removed "terminal-link" and added "ansi-escapes", "has-flag", and "supports-color" to the CLI package; removed "terminal-link" from the SDK package.
packages/cli-v3/src/utilities/cliOutput.ts Changed import of terminalLink from external "terminal-link" to a new local module "./terminalLink.js".
packages/cli-v3/src/utilities/supportsHyperlinks.ts Added a new module to detect terminal hyperlink support, exporting detection functions and precomputed support objects for stdout and stderr.
packages/cli-v3/src/utilities/terminalLink.ts Added a new module to generate clickable terminal links, with support for both stdout and stderr, customizable fallback, and detection of hyperlink support.
packages/cli-v3/types.d.ts Deleted TypeScript type declarations for the "terminal-link" module, including the deprecated terminalLink function and its options interface.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant supportsHyperlinks
    participant terminalLink

    User->>CLI: Runs command that outputs a link
    CLI->>terminalLink: Call terminalLink(text, url, options)
    terminalLink->>supportsHyperlinks: Check if hyperlinks are supported (stdout/stderr)
    supportsHyperlinks-->>terminalLink: Returns boolean (supported or not)
    alt Hyperlinks supported
        terminalLink-->>CLI: Return clickable link (with escape sequences)
    else Not supported
        terminalLink-->>CLI: Return fallback text (text + URL)
    end
    CLI-->>User: Outputs formatted link to terminal
Loading

Suggested reviewers

  • ericallam

Poem

🐇
A hop and a skip, our links now gleam,
No more old patches—just local and clean!
Hyperlinks checked with a whisker’s twitch,
CLI output’s gotten a clever new switch.
Out with the old, in with the new,
Terminal links now sparkle for you!
—Your code rabbit, hopping through.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 641ca67 and 4d62046.

📒 Files selected for processing (1)
  • .changeset/itchy-games-sort.md (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/cli-v3/src/utilities/terminalLink.ts (2)

40-54: Consider adding URL validation for security.

The function doesn't validate the URL parameter, which could lead to security issues if user input is directly passed without sanitization, especially since this generates terminal escape sequences.

Consider adding basic URL validation:

function terminalLink(
  text: string,
  url: string,
  { target = "stdout", ...options }: { target?: "stdout" | "stderr" } & TerminalLinkOptions = {}
) {
+  // Basic URL validation
+  try {
+    new URL(url);
+  } catch (error) {
+    console.warn(`Invalid URL passed to terminalLink: ${url}`);
+  }
+
  if (!supportsHyperlinks[target]) {
    // If the fallback has been explicitly disabled, don't modify the text itself.
    if (options.fallback === false) {
      return text;
    }

    return typeof options.fallback === "function"
      ? options.fallback(text, url)
      : `${text} (\u200B${url}\u200B)`;
  }

94-94: Consider using a more direct export pattern.

The current pattern of naming the function and then re-exporting it could be simplified if there's no need to reference the function internally.

If the function doesn't need to be referenced elsewhere in this file, consider simplifying to:

- function terminalLink(
+ export function terminalLink(
  text: string,
  url: string,
  { target = "stdout", ...options }: { target?: "stdout" | "stderr" } & TerminalLinkOptions = {}
) {
  // implementation
}
terminalLink.isSupported = supportsHyperlinks.stdout;
terminalLink.stderr = terminalLinkStderr;

// ...terminalLinkStderr implementation...

- export { terminalLink };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf9460a and 641ca67.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (8)
  • package.json (1 hunks)
  • packages/cli-v3/package.json (3 hunks)
  • packages/cli-v3/src/utilities/cliOutput.ts (1 hunks)
  • packages/cli-v3/src/utilities/supportsHyperlinks.ts (1 hunks)
  • packages/cli-v3/src/utilities/terminalLink.ts (1 hunks)
  • packages/cli-v3/types.d.ts (0 hunks)
  • packages/trigger-sdk/package.json (0 hunks)
  • patches/supports-hyperlinks@2.3.0.patch (0 hunks)
💤 Files with no reviewable changes (3)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: units / 🧪 Unit Tests
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (17)
package.json (1)

75-83: Dependency cleanup: Patch removal is appropriate.

The removal of the "supports-hyperlinks@2.3.0" patch from patchedDependencies is correct since this functionality has been internalized with a custom implementation in packages/cli-v3/src/utilities/supportsHyperlinks.ts. This aligns with the PR objective to directly incorporate the necessary code into the CLI.

packages/cli-v3/src/utilities/cliOutput.ts (1)

3-3: Import update looks good.

The import statement has been updated to use the local implementation of terminalLink from a relative path instead of the external package. This change is consistent with the PR objective to directly incorporate the necessary code into the CLI.

packages/cli-v3/package.json (3)

94-94: Dependencies addition: ansi-escapes is appropriate.

The addition of the ansi-escapes package is necessary for the new terminal link implementation to generate hyperlink escape sequences.


107-107: Dependencies addition: has-flag is appropriate.

The addition of the has-flag package is necessary for the new hyperlinks support detection utility to parse CLI flags.


128-128: Dependencies replacement: supports-color replaces terminal-link.

The change from terminal-link to supports-color is appropriate as part of the transition to an internal implementation. The supports-color package is used by the new hyperlinks support detection utility.

packages/cli-v3/src/utilities/supportsHyperlinks.ts (5)

1-8: License attribution is properly included.

The MIT license attribution to the original authors (Sindre Sorhus and James Talmage) is correctly included, which is good practice when adapting open-source code.


13-30: Version parsing implementation looks good.

The parseVersion function correctly handles different version string formats, including the 4-digit format sometimes used in environment variables.


38-150: Comprehensive hyperlink support detection implementation.

The createSupportsHyperlinks function thoroughly checks various conditions to determine if hyperlinks are supported:

  • Environment variables (FORCE_HYPERLINK, NETLIFY, etc.)
  • CLI flags
  • Color support
  • TTY status
  • Various terminal types and versions

The implementation properly handles edge cases and includes the CURSOR_TRACE_ID environment variable check.


99-101: CURSOR_TRACE_ID support included.

This check for the CURSOR_TRACE_ID environment variable ensures compatibility with the cursor tracing functionality, addressing the core issue mentioned in the PR objective.


153-158: Efficient implementation with precomputed values.

The exported supportsHyperlinks object precomputes the support status for stdout and stderr, which is an efficient approach that avoids redundant calculations.

packages/cli-v3/src/utilities/terminalLink.ts (7)

1-7: Correctly attributed MIT license header.

The license header properly credits Sindre Sorhus as the original author, which is important since this appears to be an adaptation of his terminal-link package now implemented locally.


9-10: Clean dependency management with local imports.

Good job replacing the external terminal-link dependency with local implementation. Using ansiEscapes for the escape sequences and a dedicated local supportsHyperlinks utility follows good separation of concerns.


12-18: Well-documented type definition with flexible fallback options.

The TerminalLinkOptions type provides good flexibility for handling fallback behavior with proper JSDoc documentation.


51-54: Smart use of zero-width spaces in the fallback format.

Good implementation detail using zero-width spaces (\u200B) around the URL in the default fallback to prevent terminal parsing issues.


56-57: Clean implementation for supported terminals.

Properly leverages the ansiEscapes.link method for terminals that support hyperlinks.


58-64: Static properties and methods nicely enhance the main function.

Good pattern of extending the function with static properties and methods for checking support and providing an alternative output stream.


66-85: Well-documented stderr function with good code reuse.

The terminalLinkStderr function effectively reuses the main function logic with different target settings, accompanied by thorough documentation.

@nicktrn nicktrn merged commit c0807ad into main May 1, 2025
7 of 11 checks passed
@nicktrn nicktrn deleted the fix/terminal-links branch May 1, 2025 07:53
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.

2 participants