feat: Implement a modular skill system with hotword detection, streaming text output, and enhanced logging.
This commit is contained in:
41
Core/Skills/TerminalSkill.cs
Normal file
41
Core/Skills/TerminalSkill.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Toak.Core.Skills;
|
||||
|
||||
public class TerminalSkill : ISkill
|
||||
{
|
||||
public string Name => "Terminal";
|
||||
public string Description => "Translates an intent into a bash command and runs it in the background.";
|
||||
public string[] Hotwords => new[] { "System terminal", "System command" };
|
||||
|
||||
public bool HandlesExecution => true;
|
||||
|
||||
public string GetSystemPrompt(string rawTranscript)
|
||||
{
|
||||
return @"You are a command-line assistant. The user will ask you to perform a task.
|
||||
Translate the request into a single bash command.
|
||||
Output ONLY the raw bash command to achieve this task. Do not include markdown formatting, backticks, or explanations.";
|
||||
}
|
||||
|
||||
public void Execute(string llmResult)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine($"[TerminalSkill] Executing: {llmResult}");
|
||||
var escapedCmd = llmResult.Replace("\"", "\\\"");
|
||||
var pInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "bash",
|
||||
Arguments = $"-c \"{escapedCmd}\"",
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
Process.Start(pInfo);
|
||||
IO.Notifications.Notify("Toak Terminal Executed", llmResult);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[TerminalSkill Error] {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user