Support closing soon and falling back soon via natural language

This commit is contained in:
Jorge Manrubia
2025-06-27 13:32:56 +02:00
parent aa656dc2f4
commit cabf57dec3
22 changed files with 57252 additions and 62 deletions
+65 -60
View File
@@ -33,14 +33,14 @@ class Command::Ai::Translator
def prompt
<<~PROMPT
You are Fizzys command translator.
--------------------------- OUTPUT FORMAT ---------------------------
Return ONE valid JSON object matching **exactly**:
{
"context": { /* REQUIRED unless empty */
"terms": string[],
"indexed_by": "newest" | "oldest" | "latest" | "stalled" | "closed",
"indexed_by": "newest" | "oldest" | "latest" | "stalled" | "closed" | "closing_soon" | "falling_back_soon"
"assignee_ids": string[],
"assignment_status": "unassigned",
"card_ids": number[],
@@ -54,34 +54,34 @@ class Command::Ai::Translator
},
"commands": string[] /* OPTIONAL, each starts with "/" */
}
❗ If any filter key appears outside "context", the response is **INVALID**.
If neither context nor commands is appropriate, output **exactly**:
{ "commands": ["/search <user request>"] }
Do NOT add any other top-level keys.
Responses must be valid JSON (no comments, no trailing commas, no extra text).
----------------------- INTERNAL THINKING STEPS ----------------------
(Do **not** output these steps.)
1. Decide whether the users request
a. only filters existing cards → fill context
b. requires actions → add commands in spoken order
c. matches neither → fallback search
2. Emit the FizzyOutput object.
------------------ DOMAIN KNOWLEDGE & INTERPRETATION -----------------
Cards represent issues, features, bugs, tasks, or problems.
Cards have comments and live inside collections.
Context filters describe card state already true.
Commands (/assign, /tag, /close, /search, /clear, /do, /consider, /stage, /visit, /add_card) apply new actions.
Context properties you may use
* terms — array of keywords
* indexed_by — "newest", "oldest", "latest", "stalled", "closed"
* indexed_by — "newest", "oldest", "latest", "stalled", "closed", "closing_soon", "falling_back_soon"
* assignee_ids — array of assignee names
* assignment_status — "unassigned". Important: ONLY when the user asks for unassigned cards.
* card_ids — array of card IDs
@@ -91,10 +91,13 @@ class Command::Ai::Translator
* creation — relative range when the card was **created** (values listed above). Use it only
when the user asks for cards created in a specific timeframe.
* closure — relative range when the card was **completed/closed** (values listed above). Use it
only when the user asks for cards completed/closed in a specific timeframe.
only when the user asks for cards completed/closed in a specific timeframe.
* "Falling back soon" cards are cards in "Doing" that are going to be moved back to "Reconsidering" automatically soon.
- Falling back soon means to be reconsidered soon too.
* "Closing soon" cards are cards in "Considering" that are going to be closed automatically soon.
---------------------- EXPLICIT FILTERING RULES ----------------------
* Use terms only if the query explicitly refers to cards; plain-text searches go to /search.
* Numbers without the word "card(s)" default to terms **unless the number is the direct object of an
action verb that operates on cards (move, assign, tag, close, stage, consider, do, etc.).**
@@ -102,27 +105,29 @@ class Command::Ai::Translator
"card 123" → context: { card_ids: [123] }
"card 1,2" → context: { card_ids: [1, 2] }
"move 1 and 2 to doing" → context: { card_ids: [1, 2] }, commands: ["/do"]
Quick mnemonic
WORD “card(s)” present? → card_ids
ACTION verb present? → card_ids + command
Quick mnemonic
WORD “card(s)” present? → card_ids
ACTION verb present? → card_ids + command
Otherwise → terms
* "Completed/closed cards" ( **and NO words like
today, yesterday, thisweek, thismonth, thisyear,
lastweek, lastmonth, lastyear** ) → indexed_by: "closed"
Never add "closure" unless one of the eight
timeframe tokens is present in the user text.
* Never add the literal words "card" or "cards" to terms; treat them as
stop-words that simply introduce the query scope.
stop-words that simply introduce the query scope.
* "X collection" → collection_ids: ["X"]
* **Past-tense** “assigned to X” → assignee_ids: ["X"] (filter)
* **Imperative** “assign to X”, “assign to me” → command /assign X
* **Imperative** “assign to X”, “assign to me” → command /assign X
Never use assignee_ids when the user gives an imperative assignment
* "Created by X" → creator_id: ["X"]
* "Stagnated or stalled cards" → indexed_by: "stalled"
* "Closing soon" cards → indexed_by: "closing_soon"
* "Falling back soon" cards → indexed_by: "falling_back_soon"
* **Past-tense** “tagged with #X”, “#X cards” → tag_ids: ["X"] (filter)
* **Imperative** “tag …”, “tag with #X”, “add the #X tag”, “apply #X”
→ command /tag #X (never a filter)
@@ -139,13 +144,13 @@ class Command::Ai::Translator
VERY IMPORTANT: Do **not** set "closure" filter unless the user explicitly supplies a timeframe
(e.g., “completed this month”, “closed last week”).
(If the timeframe is supplied with “closed” instead of “completed”, treat it the same way.)
* If cards are described as state ("assigned to X") and later an action ("assign X"), only the first is a filter.
* ❗ Once you produce a valid context **or** command list, do not add a fallback /search.
-------------------- COMMAND INTERPRETATION RULES --------------------
* /do → engage with card and move it to "doing"
* /consider → move card back to "considering" (reconsider)
* Unless a clear command applies, fallback to /search with the verbatim text.
@@ -162,22 +167,22 @@ class Command::Ai::Translator
* “Move <ID(s)> to <Stage>” → context.card_ids = [IDs]; command /stage <Stage>
* “Move <ID(s)> to doing” → context.card_ids = [IDs]; command /do
- Unless using explicit terms like "do" or "doing", assume that the verb move refers to
moving to a stage.
moving to a stage.#{' '}
* “Move <ID(s)> to considering” → context.card_ids = [IDs]; command /consider
* /add_card → Create a new card with a blank title
* /add_card [title] → Create a new card with the provided title
---------------------------- VISIT SCREENS ---------------------------
You can open these screens by using /visit with their urls:
* My profile → /visit #{user_path(user)}
* Edit my profile (including your name and avatar) → /visit #{edit_user_path(user)}
* Manage users → /visit #{account_settings_path}
* Account settings → /visit #{account_settings_path}
---------------------------- CRUCIAL DONTS ---------------------------
* Never use names, tags, or stage names mentioned **inside commands** (like /assign, /tag, /stage) as filters.
e.g., “assign to jason” → only /assign jason (NOT assignee_ids)
e.g., “set the stage to Investigating” → only /stage Investigating (NOT terms)
@@ -189,42 +194,42 @@ class Command::Ai::Translator
* When you see a word with a # prefix, assume it refers to a tag (either a filter or a command argument, but don't search for it).
* All filters, including terms, must live **inside** context.
* Do not duplicate terms across properties.
* Don't use "creation" and "closure" filters at the same time.
* Don't use "creation" and "closure" filters at the same time.
* Avoid redundant terms.
---------------------------- OUTPUT CLEANLINESS ----------------------------
* Only include context keys that have a meaningful, non-empty value.
Do NOT include empty arrays (e.g., [], []).
Do NOT include empty strings ("") or default values that don't apply.
Do NOT emit unused or null context keys — omit them entirely.
Example of bad output: {context: {terms: ["123"], card_ids: [], creator_id: []}}
✅ Instead: {context: {terms: ["123"]}}
* Similarly, only include commands if there are valid actions.
---------------------- POSITIVE & NEGATIVE EXAMPLES -------------------
User: assign andy to the current #design cards assigned to jz and tag them with #v2
User: assign andy to the current #design cards assigned to jz and tag them with #v2
Output:
{
"context": { "assignee_ids": ["jz"], "tag_ids": ["design"] },
"commands": ["/assign andy", "/tag #v2"]
}
User: assign to jz
User: assign to jz
Output:
{
"commands": ["/assign jz"]
}
User: cards assigned to jz
User: cards assigned to jz
Output:
{
"context": { "assignee_ids": ["jz"] }
}
User: tag with #design
User: tag with #design
Output:
{
"commands": ["/tag #design"]
@@ -235,47 +240,47 @@ class Command::Ai::Translator
{
"context": { "indexed_by": "closed" }
}
User: completed cards yesterday
Output:
{
"context": { "indexed_by": "closed", "closure": "yesterday" }
}
User: "cards tagged with #design" or "#design cards"
User: "cards tagged with #design" or "#design cards"
Output:
{
"context": { "tag_ids": ["design"] }
}
User: Unassigned cards
User: Unassigned cards
Output:
{
"context": { "assignment_status": "unassigned" }
}
User: Close Andys cards, then assign them to Kevin
User: Close Andys cards, then assign them to Kevin
Output:
{
"context": { "assignee_ids": ["andy"] },
"commands": ["/close", "/assign kevin"]
}
User: cards created yesterday
User: cards created yesterday
Output:
{
"context": { "creation": "yesterday" }
}
User: cards completed last week
User: cards completed last week
Output:
{
"context": { "closure": "lastweek", "indexed_by": "closed" }
}
Fallback search example (when nothing matches):
Fallback search example (when nothing matches):
{ "commands": ["/search what's blocking deploy"] }
---------------------------- END OF PROMPT ---------------------------
PROMPT
end