arch + features: jarvis.text API + brightness/window_switch/spelling/network/summarize (41 packs)
Architecture — close the trigger-strip duplication:
lua/api/text.rs (new):
+ jarvis.text.strip_trigger(phrase, triggers) — case-insensitive
"longest trigger wins" stripping, returns trimmed remainder. The
11 packs that previously inlined a `for _, t in ipairs(triggers) do
string.find ... s == 1 then sub` loop can drop to one call.
Demonstrated in spelling/, window_switch/, summarize/.
+ jarvis.text.contains_any(phrase, needles) — boolean check for any
of N substrings, case-insensitive. Useful for keyword routing.
5 new portable Lua packs (sandbox=full). 36 → 41 total. cargo test
commands::tests still 3/3.
brightness/ — brightness_up / down / max / min. WMI WmiMonitorBrightness
(read CurrentBrightness) + WmiMonitorBrightnessMethods.WmiSetBrightness
(write). ±20% step for up/down; max=100, min=10. Desktop monitors that
don'\''t expose the WMI namespace get a friendly "не поддерживается"
toast instead of a silent failure.
window_switch/ — switch_to_window. Strip trigger ("переключись на" /
"switch to" / etc.), apply the same alias map as process_kill
(хром→chrome, телега→telegram, ...), then PowerShell finds processes
by name OR window-title substring sorted by StartTime desc and uses
(New-Object -ComObject WScript.Shell).AppActivate($pid) on the top
match. Speaks the window title that got focus.
spelling/ — spell_out. Strips "произнеси по буквам" / "spell out" /
etc., iterates `word:gmatch(".")`, joins letters with ". " so SAPI
gives each one a natural micro-pause. Uses jarvis.text.strip_trigger
+ jarvis.speak — 24 lines total.
network/ — open_wifi_settings (ms-settings:network-wifi) +
open_bluetooth_settings (ms-settings:bluetooth) + my_ip. my_ip pulls
the first non-loopback, non-APIPA IPv4 with Get-NetIPAddress and
fetches WAN IP from api.ipify.org (5s timeout); speaks "Локальный X.
Внешний Y".
summarize/ — summarize_selection. Synthesises Ctrl+C through user32!
keybd_event (so the focused window copies its selection), waits
220 ms for the clipboard to populate, reads via
jarvis.system.clipboard.get(), bails if < 20 chars, truncates at
8000, sends to Groq @ temp 0.3 with a "3-5 sentences, keep names"
prompt, drops the summary back into the clipboard and speaks it.
Lets you select ANY text in ANY app (browser, PDF, IDE) and say
"суммируй" to get a spoken TL;DR.
The new packs explicitly use the new jarvis.text + jarvis.llm +
jarvis.speak API surface — no inline PS-SAPI boilerplate, no inline
Groq plumbing. Code is now intent-first.
This commit is contained in:
parent
a16d2401e7
commit
a7c002c9d4
14 changed files with 432 additions and 1 deletions
50
resources/commands/brightness/command.toml
Normal file
50
resources/commands/brightness/command.toml
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
[[commands]]
|
||||
id = "brightness_up"
|
||||
type = "lua"
|
||||
script = "set.lua"
|
||||
sandbox = "full"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = ["ярче", "сделай ярче", "увеличь яркость", "поярче"]
|
||||
en = ["brighter", "increase brightness"]
|
||||
ua = ["яскравіше", "збільш яскравість"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "brightness_down"
|
||||
type = "lua"
|
||||
script = "set.lua"
|
||||
sandbox = "full"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = ["темнее", "сделай темнее", "уменьши яркость", "потемнее"]
|
||||
en = ["darker", "decrease brightness"]
|
||||
ua = ["темніше", "зменш яскравість"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "brightness_max"
|
||||
type = "lua"
|
||||
script = "set.lua"
|
||||
sandbox = "full"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = ["максимальная яркость", "яркость на максимум"]
|
||||
en = ["max brightness", "brightness max"]
|
||||
ua = ["максимальна яскравість"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "brightness_min"
|
||||
type = "lua"
|
||||
script = "set.lua"
|
||||
sandbox = "full"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = ["минимальная яркость", "яркость на минимум"]
|
||||
en = ["min brightness", "brightness min"]
|
||||
ua = ["мінімальна яскравість"]
|
||||
44
resources/commands/brightness/set.lua
Normal file
44
resources/commands/brightness/set.lua
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
local lang = jarvis.context.language
|
||||
local cmd_id = jarvis.context.command_id
|
||||
|
||||
local ps = [[
|
||||
$ErrorActionPreference = 'Stop'
|
||||
try {
|
||||
$cur = (Get-WmiObject -Namespace root\WMI -Class WmiMonitorBrightness -ErrorAction Stop).CurrentBrightness
|
||||
} catch {
|
||||
Write-Output 'no_wmi'
|
||||
exit 0
|
||||
}
|
||||
$target = switch ('__OP__') {
|
||||
'up' { [Math]::Min(100, $cur + 20) }
|
||||
'down' { [Math]::Max(0, $cur - 20) }
|
||||
'max' { 100 }
|
||||
'min' { 10 }
|
||||
default { $cur }
|
||||
}
|
||||
$m = Get-WmiObject -Namespace root\WMI -Class WmiMonitorBrightnessMethods
|
||||
$m.WmiSetBrightness(1, $target) | Out-Null
|
||||
Write-Output $target
|
||||
]]
|
||||
|
||||
local op = ({
|
||||
brightness_up = "up", brightness_down = "down",
|
||||
brightness_max = "max", brightness_min = "min",
|
||||
})[cmd_id] or "up"
|
||||
|
||||
local script = ps:gsub("__OP__", op)
|
||||
local cmd = string.format('powershell -NoProfile -ExecutionPolicy Bypass -Command "%s"', script:gsub('"', '\\"'))
|
||||
local res = jarvis.system.exec(cmd)
|
||||
local out = (res.stdout or ""):gsub("[\r\n]+$", ""):gsub("^%s+", "")
|
||||
|
||||
if out == "no_wmi" or not res.success then
|
||||
jarvis.system.notify("Brightness",
|
||||
lang == "ru" and "Не поддерживается на этом дисплее"
|
||||
or "Not supported on this display")
|
||||
jarvis.audio.play_error()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
jarvis.system.notify(lang == "ru" and "Яркость" or "Brightness", out .. "%")
|
||||
jarvis.audio.play_ok()
|
||||
return { chain = false }
|
||||
Loading…
Add table
Add a link
Reference in a new issue