Prevent recursion when invoking AI

This can result in stack overflow errors for missing commands.

https://fizzy.37signals.com/5986089/collections/7/cards/1135

Follow up to https://github.com/basecamp/fizzy/pull/766
This commit is contained in:
Jorge Manrubia
2025-07-21 10:23:16 +02:00
parent 7a1b90c0d7
commit 2cd4dd8709
3 changed files with 29 additions and 3 deletions
+15 -2
View File
@@ -3,8 +3,9 @@ class Command::Parser
delegate :user, :cards, :filter, :script_name, to: :context
def initialize(context)
def initialize(context, fall_back_to_ai: true)
@context = context
@fall_back_to_ai = fall_back_to_ai
end
def parse(string)
@@ -17,6 +18,10 @@ class Command::Parser
end
private
def fall_back_to_ai?
@fall_back_to_ai
end
def as_plain_text(string)
ActionText::Content.new(string).to_plain_text
end
@@ -100,7 +105,7 @@ class Command::Parser
elsif card = single_card_from(string)
Command::GoToCard.new(card_id: card.id)
else
Command::Ai::Parser.new(context).parse(string)
parse_with_fallback(string)
end
end
@@ -114,4 +119,12 @@ class Command::Parser
def single_card_from(string)
user.accessible_cards.find_by_id(string)
end
def parse_with_fallback(string)
if fall_back_to_ai?
Command::Ai::Parser.new(context).parse(string)
else
Command::Search.new(terms: string)
end
end
end