Skip to content

feat(repl): add OSC 7 terminal cwd tracking#196

Merged
kunchenguid merged 1 commit intomainfrom
feat/same-dir
Mar 14, 2026
Merged

feat(repl): add OSC 7 terminal cwd tracking#196
kunchenguid merged 1 commit intomainfrom
feat/same-dir

Conversation

@kunchenguid
Copy link
Copy Markdown
Owner

Summary

Adds OSC 7 escape sequence support to the REPL loop so that terminal emulators (Terminal.app, iTerm2, etc.) can track the current working directory. This enables new tabs or windows opened from the terminal to start in the same directory as the gsh session.

Risk Assessment: 🟢 Low — Well-bounded additive feature emitting OSC 7 terminal escape sequences, with unit tests and no changes to existing logic.

Architecture

flowchart TD
    repl_run["REPL.Run loop (updated)"]
    osc["emitOSC7 (added)"]
    osc_test["emitOSC7 tests (added)"]
    executor["Executor.GetPwd (unchanged)"]
    terminal["term.IsTerminal check (unchanged)"]
    stdout["os.Stdout (unchanged)"]

    repl_run -->|"calls on each iteration"| osc
    repl_run -->|"gets working directory"| executor
    repl_run -->|"guards with TTY check"| terminal
    osc -->|"writes escape sequence to"| stdout
    osc_test -->|"validates"| osc
Loading

Key changes made

  • New emitOSC7 function (internal/repl/osc.go): Writes the ESC]7;file://HOSTNAME/path ESC\ escape sequence to an io.Writer, with proper per-segment URL encoding to handle special characters (spaces, #, etc.) while preserving / separators.
  • REPL loop integration (internal/repl/repl.go): Caches the hostname at REPL startup and emits OSC 7 before each prompt, but only when stdout is a terminal and a working directory is available.
  • Unit tests (internal/repl/osc_test.go): Covers normal paths, paths with spaces, paths with #, and empty hostname scenarios.
  • AGENTS.md: Adds a TDD policy section for agent-assisted development.

How was this tested

  • Unit tests cover normal paths, paths with spaces, paths with #, and empty hostname scenarios
  • All tests pass

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.04%. Comparing base (09b2818) to head (610a815).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/repl/repl.go 33.33% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #196   +/-   ##
=======================================
  Coverage   64.03%   64.04%           
=======================================
  Files         102      103    +1     
  Lines       13292    13301    +9     
=======================================
+ Hits         8512     8519    +7     
- Misses       4219     4221    +2     
  Partials      561      561           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kunchenguid kunchenguid merged commit aa49cdc into main Mar 14, 2026
1 check passed
@kunchenguid kunchenguid deleted the feat/same-dir branch March 14, 2026 18:42
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