1
0

feat: Implement direct typing for the Terminal skill with a new default delay for text injection.

This commit is contained in:
2026-02-28 17:05:14 +01:00
parent ee50b9464a
commit 8ec0629e1a
3 changed files with 8 additions and 34 deletions

View File

@@ -45,5 +45,6 @@ public static class Constants
{ {
public const string LlmModel = "openai/gpt-oss-20b"; public const string LlmModel = "openai/gpt-oss-20b";
public const string WhisperModel = "whisper-large-v3-turbo"; public const string WhisperModel = "whisper-large-v3-turbo";
public const int DefaultTypeDelayMs = 2;
} }
} }

View File

@@ -69,10 +69,9 @@ public static class SkillRegistry
new SkillDefinition new SkillDefinition
{ {
Name = "Terminal", Name = "Terminal",
Description = "Executes the spoken command in your shell.", Description = "Translates the spoken command into a bash command and types it.",
Hotwords = new[] { "System terminal", "System run", "System execute" }, Hotwords = new[] { "System terminal", "System run", "System execute" },
Action = "script", Action = "type",
ScriptPath = "~/.config/toak/skills/terminal_action.sh",
SystemPrompt = @"You are a Linux terminal expert. SystemPrompt = @"You are a Linux terminal expert.
Translate the user's request into a single, valid bash command. Translate the user's request into a single, valid bash command.
Output ONLY the raw command, no formatting, no markdown." Output ONLY the raw command, no formatting, no markdown."
@@ -124,32 +123,6 @@ Text: {transcript}"
File.WriteAllText(filename, json); File.WriteAllText(filename, json);
} }
// Create the default terminal wrapper script if it doesn't exist // No longer generating terminal_action.sh as Terminal skill now uses "type" action
string scriptPath = Path.Combine(SkillsDirectory, "terminal_action.sh");
if (!File.Exists(scriptPath))
{
string scriptContent = "#!/bin/bash\n" +
"export TOAK_PROPOSED_CMD=\"$1\"\n" +
"x-terminal-emulator -e bash -c 'echo -e \"\\033[1;32mToak Terminal Skill\\033[0m\"; " +
"echo \"Proposed command:\"; echo; " +
"echo -e \" \\033[33m$TOAK_PROPOSED_CMD\\033[0m\"; echo; " +
"read -p \"Execute command? [Y/n] \" resp; " +
"if [[ $resp =~ ^[Yy]$ ]] || [[ -z $resp ]]; then " +
"echo; echo -e \"\\033[1;36m>> Executing...\\033[0m\"; eval \"$TOAK_PROPOSED_CMD\"; " +
"else echo; echo \"Aborted.\"; fi; " +
"echo; echo \"Process finished. Press Enter to exit.\"; read;'\n";
File.WriteAllText(scriptPath, scriptContent);
// Try to make it executable
try {
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo {
FileName = "chmod",
Arguments = $"+x \"{scriptPath}\"",
CreateNoWindow = true,
UseShellExecute = false
})?.WaitForExit();
} catch { }
}
} }
} }

View File

@@ -29,7 +29,7 @@ public class TextInjector : ITextInjector
pInfo = new ProcessStartInfo pInfo = new ProcessStartInfo
{ {
FileName = Toak.Core.Constants.Commands.TypeWayland, FileName = Toak.Core.Constants.Commands.TypeWayland,
Arguments = $"\"{text.Replace("\"", "\\\"")}\"", Arguments = $"-d {Toak.Core.Constants.Defaults.DefaultTypeDelayMs} \"{text.Replace("\"", "\\\"")}\"",
UseShellExecute = false, UseShellExecute = false,
CreateNoWindow = true CreateNoWindow = true
}; };
@@ -51,7 +51,7 @@ public class TextInjector : ITextInjector
pInfo = new ProcessStartInfo pInfo = new ProcessStartInfo
{ {
FileName = Toak.Core.Constants.Commands.TypeX11, FileName = Toak.Core.Constants.Commands.TypeX11,
Arguments = $"type --clearmodifiers --delay 0 \"{text.Replace("\"", "\\\"")}\"", Arguments = $"type --clearmodifiers --delay {Toak.Core.Constants.Defaults.DefaultTypeDelayMs} \"{text.Replace("\"", "\\\"")}\"",
UseShellExecute = false, UseShellExecute = false,
CreateNoWindow = true CreateNoWindow = true
}; };
@@ -79,7 +79,7 @@ public class TextInjector : ITextInjector
pInfo = new ProcessStartInfo pInfo = new ProcessStartInfo
{ {
FileName = Toak.Core.Constants.Commands.TypeWayland, FileName = Toak.Core.Constants.Commands.TypeWayland,
Arguments = "-", Arguments = $"-d {Toak.Core.Constants.Defaults.DefaultTypeDelayMs} -",
UseShellExecute = false, UseShellExecute = false,
CreateNoWindow = true, CreateNoWindow = true,
RedirectStandardInput = true RedirectStandardInput = true
@@ -110,7 +110,7 @@ public class TextInjector : ITextInjector
pInfo = new ProcessStartInfo pInfo = new ProcessStartInfo
{ {
FileName = Toak.Core.Constants.Commands.TypeX11, FileName = Toak.Core.Constants.Commands.TypeX11,
Arguments = "type --clearmodifiers --delay 0 --file -", Arguments = $"type --clearmodifiers --delay {Toak.Core.Constants.Defaults.DefaultTypeDelayMs} --file -",
UseShellExecute = false, UseShellExecute = false,
CreateNoWindow = true, CreateNoWindow = true,
RedirectStandardInput = true RedirectStandardInput = true