Class: Pikuri::Tasks::Create
- Inherits:
-
Pikuri::Tool
- Object
- Pikuri::Tool
- Pikuri::Tasks::Create
- Defined in:
- lib/pikuri/tasks/create.rb
Overview
The task_create tool: mass-create pending items in a single call from a newline-separated items string. Why newline-separated rather than a JSON array: it stays within pikuri’s scalar-only Tool::Parameters DSL (no array support to extend), and a smaller model never has to balance brackets or escape quotes — fewer formatting failure modes on the burst of items that opens most multi-step work.
Each line is right- and left-stripped; blank lines are skipped. If any input is a duplicate (within the batch, or already in the list), the whole call aborts with an “Error: …” string and nothing is added — the LLM resends a corrected batch on the next turn. Atomic semantics keep the list in a coherent state the LLM doesn’t have to reconcile.
On success returns the rendered current list via List#render, so the LLM always sees fresh state without a separate read tool.
Constant Summary collapse
- DESCRIPTION =
Returns static description shown to the LLM, opencode-shape (summary +
Usage:bullets). <<~DESC Create one or more new task items in a single call. All items start as `pending`. Usage: - Use at the start of a multi-step task to capture the plan. - `items` is a single newline-separated string — one task per line. Blank lines are ignored. - Duplicate content (within the batch or already on the list) aborts the whole call with `Error: ...` and adds nothing — resend a corrected batch. - Empty input is rejected the same way. - On success the full current list is returned for you to read back. DESC
Class Method Summary collapse
-
.execute(list:, items:) ⇒ String
Validate and apply the batch.
Instance Method Summary collapse
- #initialize(list:) ⇒ Create constructor
Constructor Details
#initialize(list:) ⇒ Create
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pikuri/tasks/create.rb', line 40 def initialize(list:) super( name: 'task_create', description: DESCRIPTION, parameters: Pikuri::Tool::Parameters.build { |p| p.required_string :items, 'Newline-separated list of task contents, e.g. ' \ '"Add dark mode toggle\nWrite unit tests\nUpdate README". ' \ 'Blank lines are ignored.' }, execute: lambda { |items:| Create.execute(list: list, items: items) } ) end |
Class Method Details
.execute(list:, items:) ⇒ String
Validate and apply the batch. Public so specs can drive it without constructing a tool instance.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pikuri/tasks/create.rb', line 63 def self.execute(list:, items:) cleaned = items.lines.map(&:strip).reject(&:empty?) return 'Error: task_create requires at least one non-blank item' if cleaned.empty? seen_in_batch = {} cleaned.each do |c| return "Error: duplicate item in batch: '#{c}'" if seen_in_batch[c] seen_in_batch[c] = true end existing = list.items.map(&:content) clash = cleaned.find { |c| existing.include?(c) } return "Error: task already exists: '#{clash}'" if clash cleaned.each { |c| list.add(c) } list.render end |