mirror of
https://github.com/mark3labs/kit.git
synced 2026-06-14 03:30:26 +00:00
--no-exit in script mode
This commit is contained in:
+1
-4
@@ -453,11 +453,8 @@ func runNonInteractiveMode(ctx context.Context, mcpAgent *agent.Agent, cli *ui.C
|
||||
// Add assistant response to history
|
||||
messages = append(messages, response)
|
||||
|
||||
// If --no-exit flag is set, show the input and continue to interactive mode
|
||||
// If --no-exit flag is set, continue to interactive mode
|
||||
if noExit && !quiet && cli != nil {
|
||||
// Display the original prompt that was processed
|
||||
cli.DisplayInfo(fmt.Sprintf("Original prompt: %s", prompt))
|
||||
|
||||
// Prepare data for slash commands in interactive mode
|
||||
var serverNames []string
|
||||
for name := range mcpConfig.MCPServers {
|
||||
|
||||
@@ -65,6 +65,7 @@ func init() {
|
||||
scriptCmd.Flags().BoolVar(&debugMode, "debug", false, "enable debug logging")
|
||||
scriptCmd.Flags().StringVarP(&promptFlag, "prompt", "p", "", "override the prompt from the script file")
|
||||
scriptCmd.Flags().BoolVar(&quietFlag, "quiet", false, "suppress all output")
|
||||
scriptCmd.Flags().BoolVar(&noExitFlag, "no-exit", false, "prevent script from exiting, show input prompt instead")
|
||||
scriptCmd.Flags().IntVar(&maxSteps, "max-steps", 0, "maximum number of agent steps (0 for unlimited)")
|
||||
scriptCmd.Flags().StringVar(&providerURL, "provider-url", "", "base URL for the provider API (applies to OpenAI, Anthropic, Ollama, and Google)")
|
||||
scriptCmd.Flags().StringVar(&providerAPIKey, "provider-api-key", "", "API key for the provider (applies to OpenAI, Anthropic, and Google)")
|
||||
@@ -184,6 +185,11 @@ func runScriptCommand(ctx context.Context, scriptFile string, variables map[stri
|
||||
promptFlag = mcpConfig.Prompt
|
||||
}
|
||||
|
||||
// Validate that --no-exit is only used when there's a prompt
|
||||
if noExitFlag && promptFlag == "" {
|
||||
return fmt.Errorf("--no-exit flag can only be used when there's a prompt (either from script content or --prompt flag)")
|
||||
}
|
||||
|
||||
// Clean up script config after execution
|
||||
defer func() {
|
||||
scriptMCPConfig = nil
|
||||
@@ -215,6 +221,9 @@ func mergeScriptConfig(mcpConfig *config.Config, scriptConfig *config.Config) {
|
||||
if scriptConfig.Prompt != "" {
|
||||
mcpConfig.Prompt = scriptConfig.Prompt
|
||||
}
|
||||
if scriptConfig.NoExit {
|
||||
mcpConfig.NoExit = scriptConfig.NoExit
|
||||
}
|
||||
if scriptConfig.MaxTokens != 0 {
|
||||
mcpConfig.MaxTokens = scriptConfig.MaxTokens
|
||||
}
|
||||
@@ -254,6 +263,10 @@ func setScriptValuesInViper(mcpConfig *config.Config, cmd *cobra.Command) {
|
||||
if mcpConfig.ProviderURL != "" && !cmd.Flags().Changed("provider-url") {
|
||||
viper.Set("provider-url", mcpConfig.ProviderURL)
|
||||
}
|
||||
if mcpConfig.NoExit && !cmd.Flags().Changed("no-exit") {
|
||||
// Set the global noExitFlag variable if it wasn't explicitly set via command line
|
||||
noExitFlag = mcpConfig.NoExit
|
||||
}
|
||||
if mcpConfig.MaxTokens != 0 && !cmd.Flags().Changed("max-tokens") {
|
||||
viper.Set("max-tokens", mcpConfig.MaxTokens)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ type Config struct {
|
||||
ProviderAPIKey string `json:"provider-api-key,omitempty" yaml:"provider-api-key,omitempty"`
|
||||
ProviderURL string `json:"provider-url,omitempty" yaml:"provider-url,omitempty"`
|
||||
Prompt string `json:"prompt,omitempty" yaml:"prompt,omitempty"`
|
||||
NoExit bool `json:"no-exit,omitempty" yaml:"no-exit,omitempty"`
|
||||
|
||||
// Model generation parameters
|
||||
MaxTokens int `json:"max-tokens,omitempty" yaml:"max-tokens,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user