feat(commands): tier-1 — translate, math, theme toggle, project opener, sound panel
Five more portable Lua command packs. Bumps the total from 16 to 21
packs. cargo test -p jarvis-core --lib commands::tests still 3/3.
translate/ — translate.lua. Picks the target language from triggers
like "переведи на английский" / "translate to russian"; falls back to
English when only "переведи X" is heard. Sends to Groq with a strict
"translation only" system prompt at temp 0.3. Drops the result into
the clipboard, fires a notify, and speaks via PowerShell SAPI in the
matching ISO voice (ru-RU / uk-UA / en-US / de-DE etc.) so a German
translation actually sounds German.
math/ — math.lua. Strips the trigger ("посчитай" / "calculate" /
"сколько будет" / "what is" / ...), sends the remainder to Groq with
temp=0.0 and max_tokens=64, asking ONLY for the numeric result. If
the model replies "нет" (the system-prompt sentinel for non-math),
plays not_found instead of speaking nonsense. Otherwise speaks
"Получилось X" via SAPI.
theme/ — set.lua dispatched by command_id (theme_dark / theme_light).
Flips AppsUseLightTheme + SystemUsesLightTheme under
HKCU\...\Themes\Personalize via Set-ItemProperty. No reboot needed,
Windows shell re-themes immediately.
projects/ — open.lua + list.lua. Reads/creates
%USERPROFILE%\Documents\jarvis-projects.json (a flat
[{"name": ..., "path": ...}] list). open.lua strips the trigger,
exact-matches then substring-matches the project name, opens the path
in VS Code if `code.cmd` is on PATH, otherwise in Explorer. First
call creates a sample config with jarvis-rust / jarvis-python /
dietpi entries pointing under USERPROFILE so it works on any machine.
list.lua just notifies the configured project names.
sound_panel/ — open.lua. Two-liner: rundll32 mmsys.cpl,,1 (Recording
tab). Useful both as a standalone "открой настройки звука" and as
the place to fix the mic-disabled state that prevents jarvis-app
from starting.
Portability: USERPROFILE / SystemDrive / PATH lookup throughout.
This commit is contained in:
parent
01ea46c091
commit
100db82bd6
11 changed files with 515 additions and 0 deletions
36
resources/commands/projects/command.toml
Normal file
36
resources/commands/projects/command.toml
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
[[commands]]
|
||||
id = "open_project"
|
||||
type = "lua"
|
||||
script = "open.lua"
|
||||
sandbox = "full"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"открой проект",
|
||||
"запусти проект",
|
||||
"проект",
|
||||
"открой папку проекта",
|
||||
]
|
||||
en = [
|
||||
"open project",
|
||||
"launch project",
|
||||
"project",
|
||||
]
|
||||
ua = [
|
||||
"відкрий проект",
|
||||
"запусти проект",
|
||||
]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "list_projects"
|
||||
type = "lua"
|
||||
script = "list.lua"
|
||||
sandbox = "full"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = ["какие у меня проекты", "список проектов", "покажи проекты"]
|
||||
en = ["list projects", "show projects"]
|
||||
ua = ["які в мене проекти", "перелік проектів"]
|
||||
34
resources/commands/projects/list.lua
Normal file
34
resources/commands/projects/list.lua
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
local lang = jarvis.context.language
|
||||
local userprofile = jarvis.system.env("USERPROFILE") or "C:\\Users\\Public"
|
||||
local config_path = userprofile .. "\\Documents\\jarvis-projects.json"
|
||||
|
||||
if not jarvis.fs.exists(config_path) then
|
||||
jarvis.system.notify(
|
||||
lang == "ru" and "Проекты" or "Projects",
|
||||
lang == "ru" and "Конфиг ещё не создан — скажи «открой проект» один раз"
|
||||
or "Config not created yet — say 'open project' once"
|
||||
)
|
||||
jarvis.audio.play_not_found()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
local content = jarvis.fs.read(config_path)
|
||||
local names = {}
|
||||
for name in content:gmatch('"name"%s*:%s*"([^"]+)"') do
|
||||
table.insert(names, name)
|
||||
end
|
||||
|
||||
if #names == 0 then
|
||||
jarvis.system.notify("Projects", lang == "ru" and "Список пуст" or "Empty")
|
||||
jarvis.audio.play_not_found()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
local body = table.concat(names, ", ")
|
||||
jarvis.system.notify(
|
||||
(lang == "ru" and "Проектов: " or "Projects: ") .. #names,
|
||||
body
|
||||
)
|
||||
jarvis.log("info", "projects: " .. body)
|
||||
jarvis.audio.play_ok()
|
||||
return { chain = false }
|
||||
97
resources/commands/projects/open.lua
Normal file
97
resources/commands/projects/open.lua
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
local lang = jarvis.context.language
|
||||
local userprofile = jarvis.system.env("USERPROFILE") or "C:\\Users\\Public"
|
||||
local config_path = userprofile .. "\\Documents\\jarvis-projects.json"
|
||||
|
||||
if not jarvis.fs.exists(config_path) then
|
||||
local sample = string.format([[[
|
||||
{"name": "jarvis-rust", "path": "%s\\Jarvis\\rust"},
|
||||
{"name": "jarvis-python", "path": "%s\\Jarvis\\python"},
|
||||
{"name": "dietpi", "path": "%s\\Desktop\\Dietpi"}
|
||||
]
|
||||
]], userprofile, userprofile, userprofile)
|
||||
jarvis.fs.write(config_path, sample)
|
||||
jarvis.system.notify(
|
||||
lang == "ru" and "Проекты" or "Projects",
|
||||
lang == "ru" and "Создан шаблон в Documents/jarvis-projects.json — отредактируй и повтори"
|
||||
or "Template created at Documents/jarvis-projects.json — edit and retry"
|
||||
)
|
||||
jarvis.system.open(config_path)
|
||||
jarvis.audio.play_not_found()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
local content = jarvis.fs.read(config_path)
|
||||
|
||||
local entries = {}
|
||||
for name, path in content:gmatch('"name"%s*:%s*"([^"]+)"%s*,%s*"path"%s*:%s*"([^"]+)"') do
|
||||
table.insert(entries, { name = name:lower(), original_name = name, path = path:gsub('\\\\', '\\') })
|
||||
end
|
||||
|
||||
if #entries == 0 then
|
||||
jarvis.system.notify("Projects", lang == "ru" and "Проектов в конфиге не нашёл" or "No projects in config")
|
||||
jarvis.audio.play_not_found()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
local phrase = (jarvis.context.phrase or ""):lower()
|
||||
local triggers = {
|
||||
"открой папку проекта", "запусти проект", "открой проект", "проект",
|
||||
"open project", "launch project", "project",
|
||||
"відкрий проект", "запусти проект",
|
||||
}
|
||||
local query = phrase
|
||||
for _, t in ipairs(triggers) do
|
||||
local s, e = string.find(query, t, 1, true)
|
||||
if s == 1 then
|
||||
query = query:sub(e + 1)
|
||||
break
|
||||
end
|
||||
end
|
||||
query = query:gsub("^%s+", ""):gsub("%s+$", "")
|
||||
|
||||
if query == "" then
|
||||
jarvis.system.notify("Projects", lang == "ru" and "Какой проект?" or "Which project?")
|
||||
jarvis.audio.play_error()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
local match = nil
|
||||
for _, e in ipairs(entries) do
|
||||
if e.name == query then match = e; break end
|
||||
end
|
||||
if not match then
|
||||
for _, e in ipairs(entries) do
|
||||
if string.find(e.name, query, 1, true) or string.find(query, e.name, 1, true) then
|
||||
match = e; break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not match then
|
||||
jarvis.system.notify("Projects",
|
||||
(lang == "ru" and "Не нашёл: " or "Not found: ") .. query)
|
||||
jarvis.audio.play_not_found()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
if not jarvis.fs.exists(match.path) then
|
||||
jarvis.system.notify("Projects",
|
||||
(lang == "ru" and "Путь не существует: " or "Path missing: ") .. match.path)
|
||||
jarvis.audio.play_error()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
local code_check = jarvis.system.exec("where code.cmd")
|
||||
if code_check.success and (code_check.stdout or ""):gsub("[\r\n]+$", "") ~= "" then
|
||||
jarvis.system.exec(string.format('code "%s"', match.path))
|
||||
else
|
||||
jarvis.system.open(match.path)
|
||||
end
|
||||
|
||||
jarvis.system.notify(
|
||||
lang == "ru" and "Проект" or "Project",
|
||||
match.original_name .. "\n" .. match.path
|
||||
)
|
||||
jarvis.log("info", "opened project: " .. match.original_name .. " at " .. match.path)
|
||||
jarvis.audio.play_ok()
|
||||
return { chain = false }
|
||||
Loading…
Add table
Add a link
Reference in a new issue