Class: AiTaskJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/ai_task_job.rb

Overview

A maintenance agent (cardinal.md §17): one bounded claude CLI call fired by a column rule. The prompt template may reference the card via %title, %description, %conversation. Output lands on the timeline as an assistant_message. Distinct from the worker agent — no workspace, no tools.

Instance Method Summary collapse

Instance Method Details

#perform(card_id, prompt_template, model = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/jobs/ai_task_job.rb', line 8

def perform(card_id, prompt_template, model = nil)
  card = Card.find(card_id)
  return if prompt_template.blank? || !ClaudeCli.available?

  prompt = format(prompt_template,
                  title: card.title,
                  description: card.description.to_s,
                  conversation: card.events.conversation.filter_map(&:text).last(30).join("\n\n"))

  text = ClaudeCli.prompt(
    prompt,
    system: "You are a maintenance agent on a Cardinal board performing one bounded task on card ##{card.number}. Be concise; your output is posted directly to the card's timeline.",
    model: model.presence || AssistantReplyJob::FALLBACK_MODEL,
    ledger: { kind: "ai_task", card: card }
  )
  card.log!("assistant_message", actor: "assistant", text: text) if text.present?
rescue ClaudeCli::Error => e
  card.log!("error", text: "The maintenance agent #{e.message}.", detail: e.detail)
end