2code icon indicating copy to clipboard operation
2code copied to clipboard

open terminal file paths in 2code file tabs

Open AkaraChen opened this issue 6 months ago • 1 comments

Feature Description

Make terminal file paths and stack trace locations clickable, opening the referenced file inside 2code.

2code already detects and handles URL links in terminal output via xterm's web links addon. The same workflow should apply to local source locations emitted by compilers, test runners, linters, and stack traces.

Motivation

A lot of development work starts from terminal output:

  • TypeScript / ESLint errors
  • Rust compiler errors and panics
  • Vitest/Jest/Pytest failures
  • stack traces
  • grep/search results
  • build tool diagnostics

These commonly contain file locations like:

src/features/terminal/Terminal.tsx:172:10
src-tauri/crates/service/src/profile.rs:88:5
./tests/linkOpening.test.ts:14
/Users/me/project/src/main.ts:42:7

Clicking these should open the file in the current 2code profile, ideally at the line/column, instead of requiring users to copy/paste paths manually.

Proposed Solution

1. Detect file path links in terminal output

Add link detection for common source-location patterns:

  • Relative paths: src/foo.ts:12, ./src/foo.ts:12:3
  • Absolute paths inside the current project/worktree
  • Rust/TS/Vite/Vitest/Jest/Pytest-style diagnostics
  • Stack trace frames where a filepath, line, and optional column are present

2. Resolve paths against the active profile cwd

For relative paths, resolve against the terminal session/profile working directory.

Expected behavior:

  • Only open files that resolve inside the current project/profile workspace by default.
  • If a path is outside the workspace, either ignore it or ask for confirmation before opening.
  • Handle line/column when present.

3. Open in 2code file tabs

When a terminal file location is clicked:

  • Open or focus the file tab in the current profile.
  • Jump to the detected line/column if supported.
  • Reuse an existing file tab for the same file instead of opening duplicates.

4. Preserve URL behavior

This should not regress existing URL link handling. URL links and file-path links should coexist cleanly.

Suggested Implementation Notes

  • The existing terminal link handling lives in src/features/terminal/Terminal.tsx with xterm addons.
  • xterm supports custom link providers; consider adding a dedicated file-link provider rather than overloading URL handling.
  • The existing file tab state is already combined into src/features/terminal/TerminalTabs.tsx, so the target action should probably call the file tab store/open-file pathway.
  • Path validation/resolution may need a Tauri command so frontend code does not guess filesystem boundaries incorrectly.
  • Keep i18n strings in messages/en.json and messages/zh.json for any confirmation or error UI.

Acceptance Criteria

  • [ ] Terminal output file paths like src/foo.ts:12:3 are clickable.
  • [ ] Clicking a detected file path opens/focuses that file in the current profile's file tabs.
  • [ ] Line and column are preserved when available.
  • [ ] Relative paths resolve against the current profile/session working directory.
  • [ ] Existing URL link behavior still works.
  • [ ] Unsafe/out-of-workspace paths are handled safely with a clear fallback or confirmation.
  • [ ] Common diagnostics from TypeScript, Rust, and test runners are covered by tests.

AkaraChen avatar May 23 '26 04:05 AkaraChen

@copilot please implement this feature and open a PR. Please follow the existing 2code architecture: add terminal file/path link detection without regressing URL links, resolve relative paths against the active profile/session cwd, open or focus the file in the current profile file tabs with line/column when available, validate paths safely, and include tests/i18n where appropriate.

AkaraChen avatar May 23 '26 05:05 AkaraChen