[PR #14708] cmd: support tilde path expansion for image files in chat #61497

Open
opened 2026-04-29 16:35:32 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14708
Author: @alvinttang
Created: 3/8/2026
Status: 🔄 Open

Base: mainHead: fix/image-tilde-path-expansion


📝 Commits (2)

  • b5c6a34 cmd: support tilde (~/) path expansion for image files in chat
  • 4abd82b cmd: add debug logging for tilde expansion failure and edge case tests

📊 Changes

2 files changed (+48 additions, -2 deletions)

View changed files

📝 cmd/interactive.go (+13 -2)
📝 cmd/interactive_test.go (+35 -0)

📄 Description

Summary

When users reference images using tilde paths (e.g., ~/photos/cat.jpg) in interactive chat mode, the image silently fails to load because:

  1. The extractFileNames regex only matches paths starting with /, ./, or \ -- not ~/
  2. Even if matched, the tilde is never expanded to the user's home directory

This is a common pattern on Unix/macOS systems where users naturally type ~/Downloads/photo.jpg.

Changes

  • Updated the regex in extractFileNames to also match ~/ prefixed paths
  • Added tilde-to-home-directory expansion in normalizeFilePath, performed before unescape processing so that escaped tildes (\~) are preserved as literal tildes
  • Added tests for both the regex matching and path expansion

Reproduction

>>> describe this image ~/Downloads/photo.jpg
# Before: image silently not loaded, only text sent
# After: image correctly loaded from home directory

Test plan

  • go test ./cmd/ -run TestExtractFileNamesTildePaths -- verifies regex matches ~/ paths
  • go test ./cmd/ -run TestNormalizeFilePathExpandsTilde -- verifies tilde expansion and escaped tilde handling
  • go test ./cmd/ -run TestExtractFilenames -- existing tests still pass
  • go test ./cmd/ -run TestExtractFileDataRemovesQuotedFilepath -- existing tests still pass

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/14708 **Author:** [@alvinttang](https://github.com/alvinttang) **Created:** 3/8/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/image-tilde-path-expansion` --- ### 📝 Commits (2) - [`b5c6a34`](https://github.com/ollama/ollama/commit/b5c6a341d694767e240139595933b3b06b0ab919) cmd: support tilde (~/) path expansion for image files in chat - [`4abd82b`](https://github.com/ollama/ollama/commit/4abd82bc47780dd74d93bb537f86c57c6e6466c2) cmd: add debug logging for tilde expansion failure and edge case tests ### 📊 Changes **2 files changed** (+48 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `cmd/interactive.go` (+13 -2) 📝 `cmd/interactive_test.go` (+35 -0) </details> ### 📄 Description ## Summary When users reference images using tilde paths (e.g., `~/photos/cat.jpg`) in interactive chat mode, the image silently fails to load because: 1. The `extractFileNames` regex only matches paths starting with `/`, `./`, or `\` -- not `~/` 2. Even if matched, the tilde is never expanded to the user's home directory This is a common pattern on Unix/macOS systems where users naturally type `~/Downloads/photo.jpg`. ### Changes - Updated the regex in `extractFileNames` to also match `~/` prefixed paths - Added tilde-to-home-directory expansion in `normalizeFilePath`, performed before unescape processing so that escaped tildes (`\~`) are preserved as literal tildes - Added tests for both the regex matching and path expansion ## Reproduction ``` >>> describe this image ~/Downloads/photo.jpg # Before: image silently not loaded, only text sent # After: image correctly loaded from home directory ``` ## Test plan - [x] `go test ./cmd/ -run TestExtractFileNamesTildePaths` -- verifies regex matches `~/` paths - [x] `go test ./cmd/ -run TestNormalizeFilePathExpandsTilde` -- verifies tilde expansion and escaped tilde handling - [x] `go test ./cmd/ -run TestExtractFilenames` -- existing tests still pass - [x] `go test ./cmd/ -run TestExtractFileDataRemovesQuotedFilepath` -- existing tests still pass --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-29 16:35:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#61497