refactor: Implement dynamic skill loading from definitions, replacing hardcoded skills, and add a new skill management command.
This commit is contained in:
53
Core/Skills/DynamicSkill.cs
Normal file
53
Core/Skills/DynamicSkill.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Toak.Core.Skills;
|
||||
|
||||
public class DynamicSkill : ISkill
|
||||
{
|
||||
private readonly SkillDefinition _def;
|
||||
|
||||
public string Name => _def.Name;
|
||||
public string Description => _def.Description;
|
||||
public string[] Hotwords => _def.Hotwords;
|
||||
|
||||
public bool HandlesExecution => _def.Action.ToLowerInvariant() == "script";
|
||||
|
||||
public DynamicSkill(SkillDefinition def)
|
||||
{
|
||||
_def = def;
|
||||
}
|
||||
|
||||
public string GetSystemPrompt(string rawTranscript)
|
||||
{
|
||||
return _def.SystemPrompt.Replace("{transcript}", rawTranscript);
|
||||
}
|
||||
|
||||
public void Execute(string llmResult)
|
||||
{
|
||||
if (HandlesExecution && !string.IsNullOrWhiteSpace(_def.ScriptPath))
|
||||
{
|
||||
var expandedPath = Environment.ExpandEnvironmentVariables(_def.ScriptPath);
|
||||
if (expandedPath.StartsWith("~"))
|
||||
{
|
||||
expandedPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + expandedPath.Substring(1);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var process = Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = expandedPath,
|
||||
Arguments = $"\"{llmResult.Replace("\"", "\\\"")}\"",
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
});
|
||||
process?.WaitForExit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[DynamicSkill] Error executing script '{expandedPath}': {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user