1
0

refactor: modernize code, improve performance, and clean up various components.

This commit is contained in:
2026-03-01 21:05:35 +01:00
parent 15f9647f8a
commit a6c7df0a71
37 changed files with 240 additions and 627 deletions

View File

@@ -1,11 +1,10 @@
using System;
using System.Diagnostics;
namespace Toak.Core.Skills;
public class DynamicSkill : ISkill
public class DynamicSkill(SkillDefinition def) : ISkill
{
private readonly SkillDefinition _def;
private readonly SkillDefinition _def = def;
public string Name => _def.Name;
public string Description => _def.Description;
@@ -13,11 +12,6 @@ public class DynamicSkill : ISkill
public bool HandlesExecution => _def.Action.ToLowerInvariant() == "script";
public DynamicSkill(SkillDefinition def)
{
_def = def;
}
public string GetSystemPrompt(string rawTranscript)
{
return _def.SystemPrompt.Replace("{transcript}", rawTranscript);

View File

@@ -4,7 +4,7 @@ public class SkillDefinition
{
public string Name { get; set; } = "";
public string Description { get; set; } = "";
public string[] Hotwords { get; set; } = System.Array.Empty<string>();
public string[] Hotwords { get; set; } = [];
public string Action { get; set; } = "type"; // "type" or "script"
public string SystemPrompt { get; set; } = "";
public string? ScriptPath { get; set; }

View File

@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using Toak.Serialization;
@@ -9,7 +5,7 @@ namespace Toak.Core.Skills;
public static class SkillRegistry
{
public static List<ISkill> AllSkills = new List<ISkill>();
public static List<ISkill> AllSkills = [];
public static string SkillsDirectory => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
@@ -28,7 +24,7 @@ public static class SkillRegistry
{
try
{
string json = File.ReadAllText(file);
var json = File.ReadAllText(file);
var def = JsonSerializer.Deserialize(json, AppJsonSerializerContext.Default.SkillDefinition);
if (def != null)
{
@@ -47,7 +43,7 @@ public static class SkillRegistry
if (AllSkills.Count == 0) Initialize();
var activeSkills = AllSkills.Where(s => activeSkillNames.Contains(s.Name, StringComparer.OrdinalIgnoreCase)).ToList();
string normalizedTranscript = transcript.Trim();
var normalizedTranscript = transcript.Trim();
foreach (var skill in activeSkills)
{
@@ -72,9 +68,11 @@ public static class SkillRegistry
Description = "Translates the spoken command into a bash command and types it.",
Hotwords = ["System terminal", "System run", "System execute"],
Action = "type",
SystemPrompt = @"You are a Linux terminal expert.
Translate the user's request into a single, valid bash command.
Output ONLY the raw command, no formatting, no markdown."
SystemPrompt = """
You are a Linux terminal expert.
Translate the user's request into a single, valid bash command.
Output ONLY the raw command, no formatting, no markdown.
"""
},
new SkillDefinition
{
@@ -82,10 +80,12 @@ Output ONLY the raw command, no formatting, no markdown."
Description = "Translates the spoken text into another language on the fly.",
Hotwords = ["System translate to", "System translate into"],
Action = "type",
SystemPrompt = @"You are an expert translator. The user wants to translate the following text.
The first few words identify the target language (e.g. 'Translate to Spanish:', 'Translate into Hungarian:').
Translate the REST of the transcript into that target language.
Output ONLY the final translated text. Do not include markdown, explanations, or quotes."
SystemPrompt = """
You are an expert translator. The user wants to translate the following text.
The first few words identify the target language (e.g. 'Translate to Spanish:', 'Translate into Hungarian:').
Translate the REST of the transcript into that target language.
Output ONLY the final translated text. Do not include markdown, explanations, or quotes.
"""
},
new SkillDefinition
{
@@ -93,13 +93,15 @@ Output ONLY the final translated text. Do not include markdown, explanations, or
Description = "Rewrites text into a formal, articulate tone.",
Hotwords = ["System professional", "System formalize", "System formal"],
Action = "type",
SystemPrompt = @"Rewrite the following text to be articulate and formal.
The text will start with 'System professional', 'System formalize', or 'System formal',
or something along the lines of that. You can ignore those words.
Do not add any conversational filler.
Make sure to preserve the meaning of the original text.
Output ONLY the final professional text.
Text: {transcript}"
SystemPrompt = """
Rewrite the following text to be articulate and formal.
The text will start with 'System professional', 'System formalize', or 'System formal',
or something along the lines of that. You can ignore those words.
Do not add any conversational filler.
Make sure to preserve the meaning of the original text.
Output ONLY the final professional text.
Text: {transcript}
"""
},
new SkillDefinition
{
@@ -107,19 +109,21 @@ Text: {transcript}"
Description = "Provides a direct, crisp summary of the dictation.",
Hotwords = ["System summary", "System concise", "System summarize"],
Action = "type",
SystemPrompt = @"Summarize the following text to be as concise
and direct as possible.
The text will start with 'System summary', 'System concise', or 'System summarize',
and you shoul ignore that part of the text.
Output ONLY the final summary text.
Text: {transcript}"
SystemPrompt = """
Summarize the following text to be as concise
and direct as possible.
The text will start with 'System summary', 'System concise', or 'System summarize',
and you shoul ignore that part of the text.
Output ONLY the final summary text.
Text: {transcript}
"""
}
};
foreach (var def in defaults)
{
string filename = Path.Combine(SkillsDirectory, $"{def.Name.ToLowerInvariant()}.json");
string json = JsonSerializer.Serialize(def, AppJsonSerializerContext.Default.SkillDefinition);
var filename = Path.Combine(SkillsDirectory, $"{def.Name.ToLowerInvariant()}.json");
var json = JsonSerializer.Serialize(def, AppJsonSerializerContext.Default.SkillDefinition);
File.WriteAllText(filename, json);
}