feat: Wave 5 — sysinfo speaks, smart reminders, outlook COM, time tracker, WOL, conversation tools
Some checks are pending
Rust CI / cargo test (jarvis-core) (push) Waiting to run
Rust CI / cargo clippy (push) Waiting to run
Rust CI / cargo check (workspace) (push) Waiting to run

Voice sysinfo overhaul (6 scripts: battery/cpu/ram/disk/time/all):
- Now SPEAK the result via jarvis.cmd.ok instead of notify-only. Toast
  still fires for visual reference, but real Jarvis tells you out loud.
- `all` joins lines with commas so TTS doesn't over-pause on linebreaks.

Smart reminders (`reminders/set.lua` rewrite):
- Was: detached `Start-Sleep` PowerShell subprocesses that died on
  jarvis-app restart and spawned a hidden process per timer.
- Now: routes through `jarvis.scheduler.add(... type=speak ...)`. Persists
  to schedule.json, survives restart, no zombie processes. Trade-off:
  sub-minute timers round up to 1 min (rare in voice UX).
- Drops UA triggers from earlier UA-removal sweep.

Translation polish (`translate/translate.lua` + `clipboard.lua`):
- Drops UA target language; adds Italian, Polish, Turkish, French ru
  triggers + English target detectors.
- `language_iso()` helper picks the SAPI voice locale for the TARGET
  language (German translation → German SAPI voice if installed).

LLM system prompt (config.rs):
- New LLM_SYSTEM_PROMPT_EN counterpart. Both languages now mention the
  assistant's tooling (memory / scheduler / profiles / macros / vision /
  clipboard) so the LLM knows it can DO things, not suggest the user
  install something.
- `get_llm_system_prompt(lang)` picks EN/RU.

Conversation pack (NEW `conversation/`):
- 2 commands. `conversation.summary` ("о чём мы говорили") pulls the
  last 12 turns from persisted history, asks LLM for a 1-3 sentence
  recap in Jarvis tone. Falls back gracefully when offline.
- `conversation.repeat` ("повтори") re-speaks the last assistant message.
- New Lua API `jarvis.llm_history()` returns array of {role, content}
  tables, excluding the system prompt.

WOL pack (NEW `wol/`):
- Voice "разбуди сервер" / "wake server" fires a magic packet at a MAC
  stored in long-term memory under `wol_<alias>` (default alias "server").
- Setup via voice: "запомни wol_server AA:BB:CC:DD:EE:FF". Falls back to
  `JARVIS_WOL_TARGET` env if memory empty. Handles every standard MAC
  format (colons / dashes / dots / bare). Broadcast on UDP 9 via
  PowerShell System.Net.Sockets.UdpClient.

Outlook COM pack (NEW `outlook/`, via subagent):
- 4 commands: unread_count, latest, send_clipboard, summarize_inbox.
- PowerShell COM bridge `_outlook.ps1` with tab-delimited line protocol.
- summarize_inbox calls LLM for a one-paragraph summary. Graceful
  failure when Outlook isn't running.

Time tracker pack (NEW `time_tracker/`, via subagent):
- 5 commands: start, stop, today, week, reset.
- Persists via `jarvis.state` (structured object: current_session_start
  + sessions array of {start, end}).
- Local-calendar "today" boundary, full Russian pluralisation
  (час/часа/часов, минута/минуты/минут, сессия/сессии/сессий).

Tests: 139 rust (no regression), 81 python (60 → 81, +14 time_tracker
+7 outlook). Release build green for jarvis-app and jarvis-cli.

Pack count: 88 → 92 rust packs.
This commit is contained in:
Bossiara13 2026-05-16 14:34:29 +03:00
parent 919d565879
commit df799b6cd2
29 changed files with 1383 additions and 106 deletions

View file

@ -0,0 +1,184 @@
param(
[Parameter(Mandatory=$true)]
[ValidateSet("unread_count","latest","send_clipboard","summarize_inbox")]
[string]$Action,
[string]$Recipient = "",
[string]$Body = "",
[int]$Limit = 5
)
$ErrorActionPreference = 'Stop'
$OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# Output protocol (parsed by Lua scripts):
# First line: "OK" or "ERR:<code>" or "ERR:<code>:<message>"
# Subsequent lines depend on Action:
# unread_count -> "<count>"
# latest -> "FROM\t<name>" / "SUBJECT\t<subj>" / "PREVIEW\t<body200>"
# send_clipboard -> "TO\t<name>" / "ADDR\t<email>" / "SUBJECT\t<subj>"
# summarize_inbox -> repeated "FROM\t<name>\tSUBJECT\t<subj>"
#
# All multiline strings get newlines collapsed to spaces before printing.
function Clean-Line([string]$s) {
if (-not $s) { return "" }
$s = $s -replace "`r", " " -replace "`n", " " -replace "`t", " "
return ($s -replace '\s+', ' ').Trim()
}
function Fail($code, $msg = "") {
if ($msg) {
Write-Output ("ERR:{0}:{1}" -f $code, (Clean-Line $msg))
} else {
Write-Output ("ERR:{0}" -f $code)
}
exit 0
}
function Get-OutlookSession {
try {
$ol = New-Object -ComObject Outlook.Application
$ns = $ol.GetNamespace("MAPI")
return @{ App = $ol; Ns = $ns }
} catch {
Fail "outlook_unavailable" $_.Exception.Message
}
}
function Strip-Html([string]$s) {
if (-not $s) { return "" }
$s = [regex]::Replace($s, '<[^>]+>', ' ')
$s = $s -replace '&nbsp;', ' ' -replace '&amp;', '&' -replace '&lt;', '<' -replace '&gt;', '>' -replace '&quot;', '"' -replace "&#39;", "'"
return Clean-Line $s
}
function Resolve-Recipient([object]$ns, [string]$query) {
if ([string]::IsNullOrWhiteSpace($query)) { return $null }
try {
$r = $ns.CreateRecipient($query)
$null = $r.Resolve()
if ($r.Resolved) {
$addr = $null
try { $addr = $r.AddressEntry.GetExchangeUser().PrimarySmtpAddress } catch { }
if (-not $addr) {
try { $addr = $r.AddressEntry.Address } catch { }
}
if (-not $addr) { $addr = $r.Name }
return @{ Name = $r.Name; Address = $addr }
}
} catch { }
return $null
}
switch ($Action) {
"unread_count" {
$s = Get-OutlookSession
try {
$inbox = $s.Ns.GetDefaultFolder(6)
$count = 0
try { $count = [int]$inbox.UnReadItemCount } catch { }
if (-not $count) {
$count = ($inbox.Items | Where-Object { $_.UnRead -eq $true }).Count
}
Write-Output "OK"
Write-Output ([int]$count).ToString()
} catch {
Fail "inbox_failed" $_.Exception.Message
}
}
"latest" {
$s = Get-OutlookSession
try {
$inbox = $s.Ns.GetDefaultFolder(6)
$items = $inbox.Items
$items.Sort("[ReceivedTime]", $true)
$latest = $null
foreach ($it in $items) {
if ($it.Class -eq 43) { $latest = $it; break } # olMail = 43
}
if (-not $latest) { Fail "empty_inbox" }
$fromName = ""
try { $fromName = $latest.SenderName } catch { }
if (-not $fromName) { try { $fromName = $latest.SenderEmailAddress } catch { } }
$subject = ""
try { $subject = $latest.Subject } catch { }
$body = ""
try { $body = $latest.Body } catch { }
if (-not $body) {
try { $body = Strip-Html $latest.HTMLBody } catch { }
} else {
$body = Clean-Line $body
}
if ($body.Length -gt 200) { $body = $body.Substring(0, 200) + "..." }
Write-Output "OK"
Write-Output ("FROM`t{0}" -f (Clean-Line $fromName))
Write-Output ("SUBJECT`t{0}" -f (Clean-Line $subject))
Write-Output ("PREVIEW`t{0}" -f $body)
} catch {
Fail "latest_failed" $_.Exception.Message
}
}
"send_clipboard" {
if ([string]::IsNullOrWhiteSpace($Recipient)) { Fail "no_recipient" }
$s = Get-OutlookSession
try {
$resolved = Resolve-Recipient $s.Ns $Recipient
if (-not $resolved) { Fail "unresolved" $Recipient }
$bodyText = if ($Body) { $Body } else { "" }
$subject = ""
if ($bodyText) {
$firstLine = ($bodyText -split "`r?`n", 2)[0].Trim()
if ($firstLine.Length -gt 60) {
$subject = $firstLine.Substring(0, 60).Trim()
} else {
$subject = $firstLine
}
}
if ([string]::IsNullOrWhiteSpace($subject)) { $subject = "From J.A.R.V.I.S." }
$mail = $s.App.CreateItem(0)
$mail.To = $resolved.Address
$mail.Subject = $subject
$mail.Body = $bodyText
$mail.Send()
Write-Output "OK"
Write-Output ("TO`t{0}" -f (Clean-Line $resolved.Name))
Write-Output ("ADDR`t{0}" -f (Clean-Line $resolved.Address))
Write-Output ("SUBJECT`t{0}" -f (Clean-Line $subject))
} catch {
Fail "send_failed" $_.Exception.Message
}
}
"summarize_inbox" {
$s = Get-OutlookSession
try {
$inbox = $s.Ns.GetDefaultFolder(6)
$items = $inbox.Items
$items.Sort("[ReceivedTime]", $true)
$taken = 0
$lines = @()
foreach ($it in $items) {
if ($taken -ge $Limit) { break }
if ($it.Class -ne 43) { continue }
$unread = $false
try { $unread = [bool]$it.UnRead } catch { }
if (-not $unread) { continue }
$fromName = ""
try { $fromName = $it.SenderName } catch { }
$subj = ""
try { $subj = $it.Subject } catch { }
$lines += ("FROM`t{0}`tSUBJECT`t{1}" -f (Clean-Line $fromName), (Clean-Line $subj))
$taken += 1
}
Write-Output "OK"
foreach ($l in $lines) { Write-Output $l }
} catch {
Fail "summary_failed" $_.Exception.Message
}
}
}

View file

@ -0,0 +1,91 @@
[[commands]]
id = "outlook_unread_count"
type = "lua"
script = "unread_count.lua"
sandbox = "full"
timeout = 15000
[commands.phrases]
ru = [
"сколько у меня непрочитанных писем",
"сколько непрочитанных писем",
"проверь почту",
"проверь outlook",
"сколько новых писем",
]
en = [
"check unread mail",
"how many unread emails",
"check my inbox",
"unread email count",
"any new mail",
]
[[commands]]
id = "outlook_latest"
type = "lua"
script = "latest.lua"
sandbox = "full"
timeout = 15000
[commands.phrases]
ru = [
"прочитай последнее письмо",
"что в последнем письме",
"последнее письмо",
"покажи последнее письмо",
]
en = [
"read last email",
"read latest email",
"what is the last email",
"show me the latest email",
]
[[commands]]
id = "outlook_send_clipboard"
type = "lua"
script = "send_clipboard.lua"
sandbox = "full"
timeout = 20000
[commands.phrases]
ru = [
"отправь письмо {name}",
"отправь почту {name}",
"напиши письмо {name}",
"отправь это {name}",
]
en = [
"email this to {name}",
"send email to {name}",
"send this email to {name}",
"mail this to {name}",
]
[commands.slots.name]
entity = "person name"
[[commands]]
id = "outlook_summarize_inbox"
type = "lua"
script = "summarize_inbox.lua"
sandbox = "full"
timeout = 30000
[commands.phrases]
ru = [
"коротко расскажи про инбокс",
"расскажи что в инбоксе",
"сделай саммари инбокса",
"что нового в почте",
]
en = [
"summarize inbox",
"summarise my inbox",
"tell me about my inbox",
"what is new in my mail",
]

View file

@ -0,0 +1,68 @@
-- Read the most recent email in the default Inbox: speak FROM + SUBJECT +
-- a 1-sentence preview (~200 chars, HTML stripped) of the body.
local lang = jarvis.context.language
local helper = jarvis.context.command_path .. "\\_outlook.ps1"
local cmd = string.format(
'powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Action latest',
helper
)
local res = jarvis.system.exec(cmd)
local out = (res.stdout or ""):gsub("\r", "")
if not res.success or out == "" then
jarvis.log("error", "outlook latest exec failed: " .. tostring(res.stderr))
return jarvis.cmd.error(lang == "ru"
and "Outlook недоступен — запусти Outlook сначала."
or "Outlook is unavailable — start Outlook first.")
end
local lines = {}
for line in out:gmatch("[^\n]+") do
table.insert(lines, line)
end
local status = lines[1] or ""
if status:sub(1, 3) == "ERR" then
if status:find("empty_inbox", 1, true) then
return jarvis.cmd.not_found(lang == "ru"
and "Входящие пусты."
or "Inbox is empty.")
end
jarvis.log("warn", "outlook latest: " .. status)
return jarvis.cmd.error(lang == "ru"
and "Outlook недоступен — запусти Outlook сначала."
or "Outlook is unavailable — start Outlook first.")
end
local from, subject, preview = "", "", ""
for i = 2, #lines do
local key, val = lines[i]:match("^([A-Z]+)\t(.*)$")
if key == "FROM" then from = val or "" end
if key == "SUBJECT" then subject = val or "" end
if key == "PREVIEW" then preview = val or "" end
end
if from == "" and subject == "" then
return jarvis.cmd.error(lang == "ru" and "Не получилось прочитать письмо." or "Could not read the email.")
end
local speech
if lang == "ru" then
speech = string.format("Последнее письмо от %s. Тема: %s. %s",
from ~= "" and from or "неизвестного отправителя",
subject ~= "" and subject or "без темы",
preview)
else
speech = string.format("Latest email from %s. Subject: %s. %s",
from ~= "" and from or "unknown sender",
subject ~= "" and subject or "no subject",
preview)
end
jarvis.system.notify(
lang == "ru" and "Последнее письмо" or "Latest email",
string.format("%s\n%s\n%s", from, subject, preview)
)
return jarvis.cmd.ok(speech)

View file

@ -0,0 +1,103 @@
-- Send clipboard contents as an email to {name} via Outlook COM. The recipient
-- is resolved against the Global Address List + Contacts (Outlook's Recipient
-- .Resolve API). Subject = first line of the body truncated to 60 chars, or
-- "From J.A.R.V.I.S." for an empty clipboard.
local lang = jarvis.context.language
local slots = jarvis.context.slots or {}
local recipient = slots.name or ""
recipient = tostring(recipient):gsub("^%s+", ""):gsub("%s+$", "")
if recipient == "" then
return jarvis.cmd.not_found(lang == "ru"
and "Кому отправить? Назови имя."
or "Whom to send to? Please name them.")
end
local body = jarvis.system.clipboard.get() or ""
body = body:gsub("^%s+", ""):gsub("%s+$", "")
-- Write the body to a temp file so we don't have to escape it through the
-- PowerShell command-line. The PS helper reads it back via -Body parameter
-- value (passed as an arg). For very large bodies (>32 KB) the cmd-line
-- approach would break; in that case we read the file from inside PS.
local temp = jarvis.system.env("TEMP") or jarvis.system.env("TMP") or "C:\\Windows\\Temp"
local ts = jarvis.context.time.year .. jarvis.context.time.month .. jarvis.context.time.day
.. "_" .. jarvis.context.time.hour .. jarvis.context.time.minute .. jarvis.context.time.second
local body_path = temp .. "\\jarvis_outlook_body_" .. ts .. ".txt"
jarvis.fs.write(body_path, body)
-- Pass body via the file: the helper reads $Body if set, else falls back to
-- reading the saved file. To keep the helper simple we just inline the body
-- through -Body only when small; otherwise we still pass via -Body but quote
-- the path and let PS read it. We use the latter: PS reads its arg literally.
-- We instead encode the body so passing through args is safe.
local helper = jarvis.context.command_path .. "\\_outlook.ps1"
-- Build a single-line PowerShell expression that reads the body from the
-- temp file and invokes the helper. This avoids any shell-escape issues
-- with quotes/newlines in the clipboard.
local body_path_ps = body_path:gsub("'", "''")
local recipient_ps = recipient:gsub("'", "''")
local helper_ps = helper:gsub("'", "''")
local ps_expr = string.format(
"$b = Get-Content -LiteralPath '%s' -Raw -Encoding UTF8; if (-not $b) { $b = '' } else { $b = $b.TrimEnd() }; & '%s' -Action send_clipboard -Recipient '%s' -Body $b",
body_path_ps, helper_ps, recipient_ps
)
local cmd = string.format(
'powershell -NoProfile -ExecutionPolicy Bypass -Command "%s"',
ps_expr:gsub('"', '\\"')
)
local res = jarvis.system.exec(cmd)
jarvis.fs.remove(body_path)
local out = (res.stdout or ""):gsub("\r", "")
if not res.success or out == "" then
jarvis.log("error", "outlook send_clipboard exec failed: " .. tostring(res.stderr))
return jarvis.cmd.error(lang == "ru"
and "Outlook недоступен — запусти Outlook сначала."
or "Outlook is unavailable — start Outlook first.")
end
local lines = {}
for line in out:gmatch("[^\n]+") do table.insert(lines, line) end
local status = lines[1] or ""
if status:sub(1, 3) == "ERR" then
if status:find("unresolved", 1, true) then
return jarvis.cmd.not_found(lang == "ru"
and (string.format("Не нашёл контакт «%s».", recipient))
or (string.format("Could not find contact '%s'.", recipient)))
elseif status:find("no_recipient", 1, true) then
return jarvis.cmd.not_found(lang == "ru"
and "Кому отправить? Назови имя."
or "Whom to send to? Please name them.")
end
jarvis.log("warn", "outlook send_clipboard: " .. status)
return jarvis.cmd.error(lang == "ru"
and "Не получилось отправить — Outlook отказал."
or "Send failed — Outlook refused.")
end
local to_name, addr, subject = "", "", ""
for i = 2, #lines do
local key, val = lines[i]:match("^([A-Z]+)\t(.*)$")
if key == "TO" then to_name = val or "" end
if key == "ADDR" then addr = val or "" end
if key == "SUBJECT" then subject = val or "" end
end
local speech
if lang == "ru" then
speech = string.format("Отправил %s. Тема: %s.", to_name ~= "" and to_name or recipient, subject)
else
speech = string.format("Sent to %s. Subject: %s.", to_name ~= "" and to_name or recipient, subject)
end
jarvis.system.notify(
lang == "ru" and "Письмо отправлено" or "Email sent",
string.format("%s <%s>\n%s", to_name, addr, subject)
)
return jarvis.cmd.ok(speech)

View file

@ -0,0 +1,79 @@
-- Summarize the last few unread emails into one paragraph via the LLM.
-- Pulls FROM+SUBJECT of up to 5 unread items, then asks the model for a
-- short paragraph in the user's language.
local lang = jarvis.context.language
local helper = jarvis.context.command_path .. "\\_outlook.ps1"
local cmd = string.format(
'powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Action summarize_inbox -Limit 5',
helper
)
local res = jarvis.system.exec(cmd)
local out = (res.stdout or ""):gsub("\r", "")
if not res.success or out == "" then
jarvis.log("error", "outlook summarize_inbox exec failed: " .. tostring(res.stderr))
return jarvis.cmd.error(lang == "ru"
and "Outlook недоступен — запусти Outlook сначала."
or "Outlook is unavailable — start Outlook first.")
end
local lines = {}
for line in out:gmatch("[^\n]+") do table.insert(lines, line) end
local status = lines[1] or ""
if status:sub(1, 3) == "ERR" then
jarvis.log("warn", "outlook summarize_inbox: " .. status)
return jarvis.cmd.error(lang == "ru"
and "Outlook недоступен — запусти Outlook сначала."
or "Outlook is unavailable — start Outlook first.")
end
local emails = {}
for i = 2, #lines do
local from, subject = lines[i]:match("^FROM\t(.-)\tSUBJECT\t(.*)$")
if from then
table.insert(emails, { from = from, subject = subject or "" })
end
end
if #emails == 0 then
return jarvis.cmd.not_found(lang == "ru"
and "Непрочитанных писем нет."
or "No unread emails.")
end
-- Build the prompt
local list_str = ""
for i, m in ipairs(emails) do
list_str = list_str .. string.format("%d. From: %s | Subject: %s\n", i, m.from, m.subject)
end
local sys_prompt = lang == "ru"
and "Ты помощник по почте. Кратко опиши, что лежит в инбоксе, ОДНИМ абзацем (2-4 предложения). Сгруппируй по темам/отправителям если возможно. Без преамбулы, без перечисления списком."
or "You are an email assistant. Briefly describe the inbox in ONE paragraph (2-4 sentences). Group by topic/sender when possible. No preamble, no bullet list."
local user_prompt = (lang == "ru" and "Непрочитанные письма:\n" or "Unread emails:\n") .. list_str
local reply = jarvis.llm(
{ { role = "system", content = sys_prompt },
{ role = "user", content = user_prompt } },
{ max_tokens = 250, temperature = 0.4 }
)
if not reply or reply == "" then
-- Fallback: simple flat enumeration when LLM is unavailable.
local parts = {}
for _, m in ipairs(emails) do
table.insert(parts, string.format("%s — %s", m.from, m.subject))
end
local fallback = (lang == "ru"
and string.format("Непрочитанных: %d. ", #emails)
or string.format("Unread: %d. ", #emails)) .. table.concat(parts, "; ") .. "."
jarvis.system.notify(lang == "ru" and "Инбокс" or "Inbox", fallback)
return jarvis.cmd.ok(fallback)
end
jarvis.system.notify(lang == "ru" and "Инбокс" or "Inbox", reply)
return jarvis.cmd.ok(reply)

View file

@ -0,0 +1,55 @@
-- Voice-controlled Outlook: report number of unread emails in default Inbox.
-- The PowerShell helper talks to Outlook via COM; if Outlook is closed or
-- COM fails we degrade gracefully with an explanatory message.
local lang = jarvis.context.language
local helper = jarvis.context.command_path .. "\\_outlook.ps1"
local cmd = string.format(
'powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Action unread_count',
helper
)
local res = jarvis.system.exec(cmd)
local out = (res.stdout or ""):gsub("\r", "")
if not res.success or out == "" then
jarvis.log("error", "outlook unread_count exec failed: " .. tostring(res.stderr))
return jarvis.cmd.error(lang == "ru"
and "Outlook недоступен — запусти Outlook сначала."
or "Outlook is unavailable — start Outlook first.")
end
local first_line, rest = out:match("^([^\n]*)\n?(.*)$")
first_line = first_line or ""
if first_line:sub(1, 3) == "ERR" then
jarvis.log("warn", "outlook unread_count: " .. first_line)
return jarvis.cmd.error(lang == "ru"
and "Outlook недоступен — запусти Outlook сначала."
or "Outlook is unavailable — start Outlook first.")
end
local count_str = (rest or ""):match("(%d+)") or "0"
local count = tonumber(count_str) or 0
local speech
if lang == "ru" then
if count == 0 then
speech = "Непрочитанных писем нет."
elseif count == 1 then
speech = "Одно непрочитанное письмо."
else
speech = string.format("Непрочитанных писем: %d.", count)
end
else
if count == 0 then
speech = "No unread emails."
elseif count == 1 then
speech = "One unread email."
else
speech = string.format("You have %d unread emails.", count)
end
end
jarvis.system.notify(lang == "ru" and "Outlook" or "Outlook", speech)
return jarvis.cmd.ok(speech)