Commit 666d3f0

mo khan <mo@mokhan.ca>
2025-08-20 07:50:26
feat: add a prompt tool
1 parent 2aed760
lib/elelem/states/working/executing.rb
@@ -11,7 +11,7 @@ module Elelem
             end
           end
 
-          Waiting.new(agent)
+          Thinking.new(agent, "*", :yellow)
         end
       end
     end
lib/elelem/states/working.rb
@@ -19,7 +19,7 @@ module Elelem
             end
 
             break if state.nil?
-            break if done && agent.conversation.history.last[:role] != :tool
+            break if agent.conversation.history.last[:role] == :assistant && agent.conversation.history.last[:content]&.strip&.end_with?("I am finished with the task.")
           end
 
           agent.transition_to(States::Idle.new)
lib/elelem/toolbox/prompt.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module Elelem
+  module Toolbox
+    class Prompt < Tool
+      def initialize
+        super(
+          name: "prompt",
+          description: "Ask the user a question and get their response.",
+          parameters: {
+            type: :object,
+            properties: {
+              question: {
+                type: :string,
+                description: "The question to ask the user."
+              }
+            },
+            required: [:question]
+          }
+        )
+      end
+
+      def call(agent, **args)
+        agent.tui.prompt(args[:question])
+      end
+    end
+  end
+end
lib/elelem/configuration.rb
@@ -37,7 +37,7 @@ module Elelem
     end
 
     def tools
-      @tools ||= Tools.new(self, [Toolbox::Bash.new(self)] + mcp_tools)
+      @tools ||= Tools.new(self, [Toolbox::Bash.new(self), Toolbox::Prompt.new] + mcp_tools)
     end
 
     def cleanup
lib/elelem/system_prompt.erb
@@ -1,5 +1,23 @@
 **Shell Master** — bash>code; compose>write; pipe everything; /proc/sys native; automate fast; streams/transforms; POSIX+GNU; man(1) first; no cleverness.
 
+When you are asked to perform a task, follow these steps:
+1.  **Think**: First, think step-by-step about how you will approach the task. Show your thinking process.
+2.  **Act**: Use the available tools to perform the task. You can use multiple tools in sequence.
+3.  **Finish**: When you have completed the task, and you are ready for the next instruction, you MUST end your response with the following message on a new line:
+    I am finished with the task.
+
+## Agent Operational Context
+
+You are interacting with a command-line agent that operates in a continuous loop. Your responses drive the agent's state transitions and its interaction with the user.
+
+The agent's states include:
+- **Thinking**: When you are providing your thought process.
+- **Executing**: When you are calling a tool.
+- **Talking**: When you are providing a direct response to the user.
+- **Waiting**: When the agent is waiting for your next response.
+
+The agent uses a Text-based User Interface (TUI) to communicate with the user. The user can see your thinking process, tool executions, and direct responses. You can also use the `prompt` tool to ask the user questions and get their input.
+
 Time: `<%= Time.now.strftime("%Y-%m-%d %H:%M:%S") %>`
 Project Directory: `<%= Dir.pwd %>`
 System Info: `<%= `uname -a`.strip %>`
lib/elelem.rb
@@ -32,6 +32,7 @@ require_relative "elelem/states/working/waiting"
 require_relative "elelem/tool"
 require_relative "elelem/toolbox/bash"
 require_relative "elelem/toolbox/mcp"
+require_relative "elelem/toolbox/prompt"
 require_relative "elelem/tools"
 require_relative "elelem/tui"
 require_relative "elelem/version"