Skip to content

About

Clickable file paths and URLs in pi transcripts: paths reveal in the file manager, URLs open in the default browser.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

pi-clickable-links

English · 简体中文 · 繁體中文 · 日本語 · 한국어 · Español · Français · Deutsch · Русский

Clickable file paths and URLs in pi transcripts.

  • Path → opens the containing folder in your file manager with the file selected (never guesses which application should open it).
  • URL → opens in your default browser.

Nothing is sent anywhere; the extension only rewrites Markdown for display, so the session and the model context stay untouched.

see /home/you/projects/api/src/server.ts:42   ← click: file manager at src/, server.ts selected
docs: https://example.com/guide               ← click: default browser

Why an extension and a URI handler

A terminal can only "click" URLs that pi emits as OSC 8 hyperlinks, and the terminal hands those URIs to the desktop's default handler. So there are two halves:

Half File Job
pi extension src/open-links.ts rewrites [text](url) links into the transcript: local paths become pi-open://open?p=…, URLs stay http(s)
URI handler bin/pi-open receives the click, resolves the path, reveals it in the file manager (nautilus --select), or calls xdg-open for URLs

Requirements

  • pi 1.7 or newer
  • A terminal with OSC 8 hyperlink support (GNOME Terminal / VTE, kitty, foot, WezTerm, iTerm2, …)
  • python3 (the handler is a small stdlib-only script)
  • Linux desktop with xdg-mime; Nautilus is used when present, otherwise xdg-open

Install

1. The extension

# from GitHub
pi install git:github.com/bbjson/pi-clickable-links

# or from npm
pi install npm:pi-clickable-links

# or from a local checkout
git clone https://github.com/bbjson/pi-clickable-links
cd pi-clickable-links
./install.sh --link-extension

2. The URI handler

On the first session after installing, the extension installs the handler and the desktop entry itself and tells you in the status area — no manual step needed. Run the installer yourself to do it up front (or to redo it after moving files):

./install.sh

It will:

  1. copy bin/pi-open to ~/.local/bin/pi-open
  2. write ~/.local/share/applications/pi-open.desktop and register the pi-open:// scheme with xdg-mime
  3. set terminal.hyperlinks: true in ~/.pi/agent/settings.json (a timestamped backup is written first; skip with --no-settings)

Doing the same steps by hand is fine too:

install -m 0755 bin/pi-open ~/.local/bin/pi-open
sed "s|@PI_OPEN_BIN@|$HOME/.local/bin/pi-open|" share/pi-open.desktop.in \
  > ~/.local/share/applications/pi-open.desktop
update-desktop-database ~/.local/share/applications
xdg-mime default pi-open.desktop x-scheme-handler/pi-open

3. Restart pi

Extensions and settings are read at startup. Run /reload or restart pi.

Why terminal.hyperlinks: true is required

pi decides whether it may emit OSC 8 links from TERM_PROGRAM. GNOME Terminal (VTE) does not set that variable, so pi disables hyperlinks by default and the transcript contains no links at all — even for plain https:// URLs. Forcing the setting on fixes both. If your terminal sets TERM_PROGRAM (kitty, WezTerm, iTerm2, …), the setting is redundant but harmless.

Usage

Click any path or URL in the transcript.

Also available from the keyboard, which works even without OSC 8 support:

/open /home/you/projects/api/src/server.ts
/open https://example.com/guide
/open ~/Downloads

What gets linked

Input in a transcript Result
/home/you/app/main.py clickable → file manager opens app/, main.py selected
~/Downloads clickable → file manager opens ~/Downloads
/home/you/app/main.py:42 clickable, :42 kept in the label, file selected
/home/you/My Documents/notes.md clickable (spaces handled)
/home/you/视频/第八集.mp4 clickable (non-ASCII percent-encoded in the URI)
https://example.com clickable by pi itself, pointing at the URL
`cat /home/you/file` / fenced code left as code, not linked
[docs](/home/you/file.md) (already a link) left alone
/home/you/does-not-exist.txt not linked, stays plain text
src/app.ts (relative) not linked — a relative path cannot be resolved at click time

Configuration

Variable Effect
PI_OPEN_DRY=1 make the handler print what it would run instead of opening anything
PI_OPEN_BIN path to the handler, if you did not install it under ~/.local/bin

The file manager is chosen at the top of bin/pi-open (nautilus is used when present, otherwise xdg-open). Change FM there for Thunar, Nemo, Dolphin, …

Troubleshooting

Symptom Cause / fix
No link styling at all, not even on https:// URLs terminal.hyperlinks is off: rerun ./install.sh, restart pi
Link is styled but clicking does nothing the terminal cannot open the scheme: check xdg-mime query default x-scheme-handler/pi-open
Clicking opens a text editor instead of the folder pi rendered its own file:// link (tool output paths), which bypasses this handler; click the path in the assistant text instead
Nothing happens on paths with spaces the path must exist at render time — the extension only links existing absolute paths
pi-open: command not found run ./install.sh (step 2)
Fullscreen mode swallows clicks hold Ctrl+Shift while clicking to use the terminal's native link handling

Run the handler directly to debug:

PI_OPEN_DRY=1 ~/.local/bin/pi-open 'pi-open://open?p=/home/you/Desktop'

Tests

npm test          # node >= 22: TypeScript is stripped natively
  • test/linkify.mjs — Markdown transformer (paths, code fences, spaces, CJK, :line suffixes)
  • test/setup.mjs — self-install path, in a throwaway $HOME

Uninstall

./uninstall.sh
pi remove git:github.com/bbjson/pi-clickable-links
# optionally revert terminal.hyperlinks in ~/.pi/agent/settings.json

License

MIT — see LICENSE.

About

Clickable file paths and URLs in pi transcripts: paths reveal in the file manager, URLs open in the default browser.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages