1
0

refactor: Implement dynamic skill loading from definitions, replacing hardcoded skills, and add a new skill management command.

This commit is contained in:
2026-02-28 13:43:23 +01:00
parent a1037edb29
commit 7b144aedd7
11 changed files with 310 additions and 125 deletions

View 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}");
}
}
}
}