-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[draft] [feat] add term command #5847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c345c82
6cb829f
f36f678
3b9d53b
5b768e5
155e086
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,5 +6,6 @@ pub mod project; | |
| pub mod recipe; | ||
| pub mod schedule; | ||
| pub mod session; | ||
| pub mod term; | ||
| pub mod update; | ||
| pub mod web; | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,192 @@ | ||||||
| use anyhow::{anyhow, Result}; | ||||||
| use goose::session::session_manager::SessionType; | ||||||
| use goose::session::SessionManager; | ||||||
| use uuid::Uuid; | ||||||
|
|
||||||
| use crate::session::{build_session, SessionBuilderConfig}; | ||||||
|
|
||||||
| const TERMINAL_SESSION_PREFIX: &str = "term:"; | ||||||
|
|
||||||
| /// Handle `goose term init <shell>` - print shell initialization script | ||||||
| pub fn handle_term_init(shell: &str) -> Result<()> { | ||||||
| let terminal_id = Uuid::new_v4().to_string(); | ||||||
|
|
||||||
| // Get the path to the current goose binary | ||||||
| let goose_bin = std::env::current_exe() | ||||||
| .map(|p| p.to_string_lossy().into_owned()) | ||||||
| .unwrap_or_else(|_| "goose".to_string()); | ||||||
|
|
||||||
| let script = match shell.to_lowercase().as_str() { | ||||||
| "bash" => { | ||||||
| format!( | ||||||
| r#"export GOOSE_TERMINAL_ID="{terminal_id}" | ||||||
| alias gt='{goose_bin} term run' | ||||||
|
|
||||||
| # Log commands to goose (runs silently in background) | ||||||
| goose_preexec() {{ | ||||||
| [[ "$1" =~ ^goose\ term ]] && return | ||||||
| [[ "$1" =~ ^gt\ ]] && return | ||||||
|
||||||
| ("{goose_bin}" term log "$1" &) 2>/dev/null | ||||||
|
||||||
| }} | ||||||
|
|
||||||
| # Install preexec hook for bash | ||||||
| if [[ -z "$goose_preexec_installed" ]]; then | ||||||
| goose_preexec_installed=1 | ||||||
| trap 'goose_preexec "$BASH_COMMAND"' DEBUG | ||||||
| fi"# | ||||||
| ) | ||||||
| } | ||||||
| "zsh" => { | ||||||
| format!( | ||||||
| r#"export GOOSE_TERMINAL_ID="{terminal_id}" | ||||||
| alias gt='{goose_bin} term run' | ||||||
|
|
||||||
| # Log commands to goose (runs silently in background) | ||||||
| goose_preexec() {{ | ||||||
| [[ "$1" =~ ^goose\ term ]] && return | ||||||
| [[ "$1" =~ ^gt\ ]] && return | ||||||
|
||||||
| ("{goose_bin}" term log "$1" &) 2>/dev/null | ||||||
|
||||||
| }} | ||||||
|
|
||||||
| # Install preexec hook for zsh | ||||||
| autoload -Uz add-zsh-hook | ||||||
| add-zsh-hook preexec goose_preexec"# | ||||||
| ) | ||||||
| } | ||||||
| "fish" => { | ||||||
| format!( | ||||||
| r#"set -gx GOOSE_TERMINAL_ID "{terminal_id}" | ||||||
| alias gt='{goose_bin} term run' | ||||||
|
||||||
| alias gt='{goose_bin} term run' | |
| function gt; {goose_bin} term run $argv; end |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pattern ^gt requires space after gt but won't match standalone gt. Should be '^gt(\s|$)' or '^gt'.
| string match -q -r '^gt ' -- $argv[1]; and return | |
| string match -q -r '^gt(\\s|$)' -- $argv[1]; and return |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing quotes around $argv[1] in Fish shell. Commands with spaces or special characters will fail. Use {goose_bin} term log \"$argv[1]\" 2>/dev/null &
| {goose_bin} term log $argv[1] 2>/dev/null & | |
| {goose_bin} term log "$argv[1]" 2>/dev/null & |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PowerShell Set-Alias -Value doesn't accept scriptblocks with parameters. Use a function instead: function gt {{ & {goose_bin} term run @args }}
| Set-Alias -Name gt -Value {{ {goose_bin} term run $args }} | |
| function gt { {goose_bin} term run $args } |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pattern ^gt won't match standalone gt command. Should be ^gt(\s|$) or ^gt\b.
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the goose binary path contains spaces, this command will fail. Quote the path in PowerShell: & '{goose_bin}' term log $using:line
| Start-Job -ScriptBlock {{ {goose_bin} term log $using:line }} | Out-Null | |
| Start-Job -ScriptBlock {{ '{goose_bin}' term log $using:line }} | Out-Null |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated session creation logic appears in both handle_term_log (lines 110-121) and handle_term_run (lines 151-163). Extract to a helper function like ensure_terminal_session to reduce duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure I follow what we are fetching here. doesn't each session add at least one message to the conversation so isn't this then automatically empty?
in general though, adding shell commands to the session manager seems rather specific for this application. couldn't we just list the messages from session and exclude the <shell_history></shell_history> from that to get the same result? or if that doesn't work, maybe add a message content type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually you could just create the session here and then use the session id of that session as the terminal_id