Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(agent): let a plain `jan plugin install` prompt for git credentials
James Dam7fc6535775ed
diff --git a/src-tauri/src/core/agent/git.rs b/src-tauri/src/core/agent/git.rsindex 61a8e4bf2..4bd36d6be 100644--- a/src-tauri/src/core/agent/git.rs+++ b/src-tauri/src/core/agent/git.rs@@ -31,15 +31,14 @@ use std::process::Command;/// A `git` command, resolved by [`jan_utils::git_program`] so Windows never/// runs a `git.exe` from Jan's own folder.///-/// It never talks to the user's terminal: no stdin, `GIT_TERMINAL_PROMPT=0`,-/// and (unix) its own session. Under the TUI, git asking for credentials on-/// `/dev/tty` -- or ssh asking to trust a host key -- would otherwise wait on-/// a prompt the TUI hides, with the TUI and git both reading the same-/// keystrokes. Now such a command fails with git's own error instead.+/// It never talks to the user's terminal: `GIT_TERMINAL_PROMPT=0` and (unix)+/// its own session, so neither git nor anything it runs (a credential helper,+/// ssh asking to trust a host key) can open `/dev/tty`. Under the TUI such a+/// prompt would wait behind the TUI's screen, with the TUI and git both+/// reading the same keystrokes; now the command fails with git's own error.+/// For a git that may prompt, see [`git_command_on_terminal`].pub(crate) fn git_command() -> Result<Command, String> {- let mut cmd = jan_utils::git_program()- .map(Command::new)- .map_err(|e| format!("failed to launch git: {e}"))?;+ let mut cmd = git_command_on_terminal()?;cmd.stdin(std::process::Stdio::null()).env("GIT_TERMINAL_PROMPT", "0");#[cfg(unix)]@@ -47,6 +46,15 @@ pub(crate) fn git_command() -> Result<Command, String> {Ok(cmd)}+/// A plain `git` that shares Jan's terminal, so it can ask for credentials+/// there. Only for a caller that knows nothing else is using the terminal --+/// a plain `jan plugin install`, never the TUI.+pub(crate) fn git_command_on_terminal() -> Result<Command, String> {+ jan_utils::git_program()+ .map(Command::new)+ .map_err(|e| format!("failed to launch git: {e}"))+}+/// Run `git` with literal args (callers pass their own `-C`). Returns trimmed/// stdout on success, trimmed stderr (or a generic message) on failure.fn git(args: &[&str]) -> Result<String, String> {diff --git a/src-tauri/src/core/agent/plugins.rs b/src-tauri/src/core/agent/plugins.rsindex 1ea076142..af2dcd1ac 100644--- a/src-tauri/src/core/agent/plugins.rs+++ b/src-tauri/src/core/agent/plugins.rs@@ -790,10 +790,30 @@ fn repo_dir_name(url: &str) -> Option<&str> {Some(name.strip_suffix(".git").unwrap_or(name))}+/// Whether the TUI holds the terminal (raw mode on). The desktop app has no+/// terminal to prompt on, so it counts as owned.+fn tui_owns_terminal() -> bool {+ #[cfg(feature = "cli")]+ {+ ratatui::crossterm::terminal::is_raw_mode_enabled().unwrap_or(true)+ }+ #[cfg(not(feature = "cli"))]+ {+ true+ }+}+fn git(args: &[&str]) -> Result<String, String> {- // Shared with the snapshot code, so a clone that needs credentials fails- // with git's error rather than prompting on the TUI's terminal.- let out = super::git::git_command()+ // A plain `jan plugin install` in a shell may let git ask for credentials+ // (a private https repo, a first-seen ssh host). Under the TUI -- raw mode+ // on -- that prompt would sit hidden behind the screen, so there git gets+ // no terminal and fails with its own error instead.+ let command = if tui_owns_terminal() {+ super::git::git_command()+ } else {+ super::git::git_command_on_terminal()+ };+ let out = command.map_err(|e| format!("ERROR: {e}"))?.args(args).output()