Skip to content

Conversation

@Cprakhar
Copy link

@Cprakhar Cprakhar commented Jan 20, 2026

Summary

Convert embedded LLM file citations (e.g. @file:{github.com/owner/repo::path/to/file.ext:10-20})
into portable, clickable URLs that point to a file on the originating code host.

This change ensures links emitted by the model are usable by users (not local paths).

Closes #576

What I changed

  • Updated link conversion logic in packages/web/src/features/chat/utils.ts
    • Added buildCodeHostFileUrl() to construct file URLs for GitHub, GitLab, Bitbucket, Azure DevOps, Gitea, Gerrit and generic git hosts.
    • convertLLMOutputToPortableMarkdown() now accepts an optional sources array so it can use the indexed revision for a file when available, falling back to main.
  • Added/updated tests in packages/web/src/features/chat/utils.test.ts covering multiple hosts, line anchors, ranges, .md/.mdx handling, and branch resolution from sources.

Why

LLM responses embed file references for traceability. Previously those produced local paths (e.g., /path/to/file), which are not portable when copying as Markdown. This change converts them into full remote URLs matching the code host's expected blob/src format and preserves line anchors.

Notes on platform support

Supported hosts and behaviors:

  • GitHub (github.com and GH Enterprise): .../blob/{branch}/{path}#L{n} (adds ?plain=1 for raw markdown views where appropriate)
  • GitLab: .../-/blob/{branch}/{path}#L{n}
  • Bitbucket: .../src/{branch}/{path}#lines-{n}
  • Azure DevOps: .../_git/{repo}?path=/{path}&version=GB{branch}&line={n}
  • Gitea, Gerrit, generic git hosts: reasonable fallbacks supported

If a file source (from the LLM retrieval metadata) is provided, the code will prefer the revision from that source to construct the URL instead of defaulting to main.

Summary by CodeRabbit

Release Notes

  • New Features
    • Answer cards now display file references as clickable links, with support for multiple code hosting platforms including GitHub, GitLab, Bitbucket, Azure DevOps, Gitea, and Gerrit.
    • File links automatically include line number and line range information when available.
    • Added enhanced markdown conversion for LLM-generated content to properly format code file references.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 20, 2026

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The PR adds support for resolving relative file links in Ask responses to absolute URLs within code hosts. It introduces a new buildCodeHostFileUrl helper function and updates convertLLMOutputToPortableMarkdown to accept source information for generating code-host-specific URLs instead of relative paths.

Changes

Cohort / File(s) Summary
Component prop threading
packages/web/src/features/chat/components/chatThread/answerCard.tsx, packages/web/src/features/chat/components/chatThread/chatThreadListItem.tsx
Added optional sources prop to AnswerCard and propagated it through component hierarchy. Updated copy logic to pass sources to convertLLMOutputToPortableMarkdown for URL resolution.
Core utility enhancements
packages/web/src/features/chat/utils.ts
Introduced buildCodeHostFileUrl() to construct code-host-specific URLs for GitHub, GitLab, Bitbucket, Azure DevOps, Gitea, and Gerrit with line ranges. Enhanced convertLLMOutputToPortableMarkdown() to accept sources and resolve file references to absolute URLs.
Test coverage
packages/web/src/features/chat/utils.test.ts
Exported convertLLMOutputToPortableMarkdown and buildCodeHostFileUrl. Added comprehensive test suite (+457 lines) covering multiple code hosts, line range handling, branch resolution, markdown files, and edge cases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • msukkari
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: resolving embedded file links to full code-host URLs, which is the primary objective of this PR.
Linked Issues check ✅ Passed The PR successfully implements all coding objectives from issue #576: it resolves relative file links to absolute code-host URLs via buildCodeHostFileUrl(), supports multiple hosts (GitHub, GitLab, Bitbucket, etc.), preserves line references, and includes comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving embedded file links: answerCard component receives sources prop, chatThreadListItem filters and passes sources, utils functions handle URL conversion with extensive tests. No unrelated changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@brendan-kellam
Copy link
Contributor

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jan 20, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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: 2

🤖 Fix all issues with AI agents
In `@packages/web/src/features/chat/utils.ts`:
- Around line 403-412: Normalize the referenced file path before matching and
URL construction: strip any leading slashes (or run a POSIX normalize) on
fileName before using it to find matchingSource in options?.sources and before
calling buildCodeHostFileUrl so revision lookup doesn’t miss entries when paths
include a leading slash; update the use of fileName in the matching logic and
the url call (references: matchingSource, options?.sources, fileName, repo,
revision, buildCodeHostFileUrl).
- Around line 260-365: The buildCodeHostFileUrl function constructs URLs by
interpolating raw filePath, revision and ownerRepo which can break for spaces or
special chars; update buildCodeHostFileUrl to percent-encode path and revision
components before interpolation (e.g., encode each segment of filePath and
ownerRepo via split('/').map(encodeURIComponent).join('/'), and encode revision
with encodeURIComponent) and ensure query parameter values used for Azure DevOps
(version, path, line, lineEnd) are encoded with encodeURIComponent; keep
line/anchor logic (startLine/endLine) intact but do not percent-encode the
leading “#L” or “:”-style anchors themselves.

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.

[FR] Resolve links embedded in Ask responses to URLs rather than relative paths

2 participants