Repository navigation
Conversation
…mmand Handler.handle_function_call executed any function the model's tool-call response named immediately, with only a one-line notice printed and no confirmation prompt. Since function-calling is enabled by default (OPENAI_USE_FUNCTIONS=true), and the bundled execute_shell_command function runs its argument via subprocess.Popen(shell=True, ...), this meant any tool call naming it ran with no chance to review or decline, unlike the tool's own --shell mode, which correctly requires an [E]xecute/[M]odify/[D]escribe/[A]bort confirmation before running an LLM-proposed command. Piping untrusted content into sgpt (git diff, log output, source files) is the tool's own advertised primary workflow, and any such content is a route for a prompt-injection payload to reach the model's context. Add a FUNCTION_CALL_CONFIRM config key, defaulting to "true", and gate the actual function execution in handle_function_call behind a typer.confirm prompt (printed to stderr, so it doesn't collide with the Rich Live-rendered response stream on stdout) when set. This mirrors the confirmation already required for --shell mode's equivalent action, rather than introducing a new pattern. See TheR1D#793.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #793.
Summary
Handler.handle_function_call(sgpt/handlers/handler.py) executed anyfunction the model's tool-call response named immediately, with only a
one-line notice printed and no confirmation prompt. Since function-calling
is enabled by default (
OPENAI_USE_FUNCTIONS=true), and the bundledexecute_shell_commandfunction runs its argument viasubprocess.Popen(shell=True, ...), this meant any tool call naming itran with no chance to review or decline, unlike the tool's own
--shellmode, which correctly requires an
[E]xecute/[M]odify/[D]escribe/[A]bortconfirmation before running an LLM-proposed command.
Piping untrusted content into
sgpt(git diffs, log output, sourcefiles) is the tool's own advertised primary workflow, and any such
content is a route for a prompt-injection payload to reach the model's
context and steer it toward calling
execute_shell_command.Fix
Adds a
FUNCTION_CALL_CONFIRMconfig key, defaulting to"true", andgates the actual function execution in
handle_function_callbehind atyper.confirmprompt when set. The prompt is printed to stderr(
err=True) so it doesn't collide with the RichLive-rendered responsestream on stdout. This mirrors the confirmation the tool already requires
for
--shellmode's equivalent action, rather than introducing a newpattern.
Testing
Handler.handle_function_calldirectly with a crafted tool-callpayload naming
execute_shell_command(this doesn't require a liveAPI call, since the method only processes an already-received tool
call), and confirmed a marker command executed immediately with no
confirmation step.
the prompt genuinely blocks on stdin, not a mocked confirmation):
confirmed declining (
n) leaves the marker file absent and yields a> Function call aborted.message, and confirming (y) lets it run asbefore.
pytest tests/): 23 passed. Note thatmaincurrently has 3 pre-existing failures unrelated to this change(a
UsageErrorexit-code mismatch for mutually-exclusive CLI flags,present on a completely clean, unpatched checkout of
main), and apre-existing test-collection error from
cfg.get("DEFAULT_TEMPERATURE")treating the float default
0.0as falsy inConfig.get'sif not valuecheck (also reproduced on a cleanmaincheckout, alsounrelated to this change). Neither is introduced or touched by this
PR; flagging them here in case they aren't already known.