feat: lock_workstation + screenshot + net_info packs + modernise power pack

Three handy daily-driver packs + cleanup of the oldest power/act.lua.

power pack — added lock_workstation (resources/commands/power/)
  - New command id: lock_workstation
  - Phrase: "заблокируй компьютер" / "заблокируй пк" / "заблокируй экран"
  - Action: rundll32.exe user32.dll,LockWorkStation
  - Sandbox: full (needs system.exec)
  - act.lua modernised:
    * No more inline PowerShell SAPI escape chain — now uses jarvis.speak
      (TTS backend abstraction respects user's chosen Piper/SAPI/Silero).
    * Returns via jarvis.cmd.ok/error helpers.
    * Logged warning for failing cmds without crashing the pack.
    * Cleaner per-action `warn` flag controls the "say cancel to abort" hint.

screenshot pack (NEW, resources/commands/screenshot/, 2 commands)
  - "сделай скрин" / "сделай скриншот" → screenshot.to_clipboard
    Uses [System.Windows.Forms.Clipboard]::SetImage() with a captured Bitmap.
    No file artifact, no LLM call — pure capture, fastest path.
  - "сохрани скрин" → screenshot.to_file
    Saves to ~/Pictures/Screenshots/jarvis-YYYYMMDD-HHMMSS.png.
    Creates dir if missing. Notifies with full path.
  - Distinct from vision/ pack which captures + describes via LLM.

net_info pack (NEW, resources/commands/net_info/, 3 commands)
  - "какая сеть" / "какой wifi" → net.wifi_ssid
    Parses `netsh wlan show interfaces` for SSID line (RU + EN field names).
  - "мой IP" / "локальный IP" → net.local_ip
    PowerShell Get-NetIPAddress, filters out 127.* and 169.* (link-local).
  - "внешний IP" / "публичный IP" → net.public_ip
    Hits api.ipify.org via jarvis.http.get (no key, plain text).

Tests: 99/99 pass (commands::tests auto-validates new packs).
Build: cargo build --release -p jarvis-app green.

Pack count: 59 → 62 (intro/echo from prior commit + screenshot + net_info; power
already counted — added a command, not a pack).
This commit is contained in:
Bossiara13 2026-05-15 18:32:13 +03:00
parent 77063fed86
commit 41eb47724c
8 changed files with 243 additions and 25 deletions

View file

@ -0,0 +1,56 @@
# Network info — WiFi SSID, local IP, public IP via PowerShell + free service.
# Separate from existing `network` pack which likely covers different things.
[[commands]]
id = "net.wifi_ssid"
type = "lua"
script = "wifi.lua"
sandbox = "full"
timeout = 5000
[commands.phrases]
ru = [
"к какой сети я подключен",
"какой wi-fi",
"какой вайфай",
"какая сеть",
"имя сети",
]
en = ["what wifi", "what network", "wifi name", "ssid"]
ua = ["до якої мережі"]
[[commands]]
id = "net.local_ip"
type = "lua"
script = "local_ip.lua"
sandbox = "full"
timeout = 5000
[commands.phrases]
ru = [
"мой локальный ip",
"мой ip",
"айпи адрес",
"локальный адрес",
]
en = ["my ip", "local ip", "ip address"]
ua = ["моя айпі", "локальна адреса"]
[[commands]]
id = "net.public_ip"
type = "lua"
script = "public_ip.lua"
sandbox = "full"
timeout = 10000
[commands.phrases]
ru = [
"мой внешний ip",
"публичный ip",
"внешний айпи",
"какой у меня внешний",
]
en = ["public ip", "external ip", "what's my ip online"]
ua = ["зовнішня айпі"]

View file

@ -0,0 +1,18 @@
-- Get first non-loopback IPv4 address via PowerShell Get-NetIPAddress.
local ps = "(Get-NetIPAddress -AddressFamily IPv4 | " ..
"Where-Object {$_.IPAddress -notlike '127.*' -and $_.IPAddress -notlike '169.*'} | " ..
"Select-Object -First 1).IPAddress"
local res = jarvis.system.exec(string.format(
'powershell -NoProfile -Command "%s"', ps
))
if not res.success then
return jarvis.cmd.error("Не получилось узнать IP.")
end
local ip = (res.stdout or ""):gsub("%s+", "")
if ip == "" then
return jarvis.cmd.not_found("Нет активного сетевого подключения.")
end
return jarvis.cmd.ok("Локальный адрес: " .. ip .. ".")

View file

@ -0,0 +1,12 @@
-- Free public-IP services: api.ipify.org → plain text body.
local r = jarvis.http.get("https://api.ipify.org")
if not r or not r.ok then
return jarvis.cmd.error("Не получилось узнать внешний IP.")
end
local ip = (r.body or ""):gsub("%s+", "")
if ip == "" then
return jarvis.cmd.error("Сервис вернул пустой ответ.")
end
return jarvis.cmd.ok("Внешний адрес: " .. ip .. ".")

View file

@ -0,0 +1,18 @@
-- "Какая сеть" → `netsh wlan show interfaces` → grep SSID
local res = jarvis.system.exec('netsh wlan show interfaces')
if not res.success then
return jarvis.cmd.error("Не получилось получить данные о Wi-Fi.")
end
local out = res.stdout or ""
local ssid = out:match("SSID%s+:%s+(.-)\r?\n")
-- Russian Windows: "SSID : MyNetwork"
-- The non-localised case: same format
if not ssid then ssid = out:match("Имя сети%s+:%s+(.-)\r?\n") end
ssid = ssid and ssid:gsub("^%s+", ""):gsub("%s+$", "") or ""
if ssid == "" or ssid == "(нет)" or ssid == "(none)" then
return jarvis.cmd.not_found("Wi-Fi не подключен или адаптер выключен.")
end
return jarvis.cmd.ok("Сеть: " .. ssid .. ".")