feat(app): PC control through agent-desktop, with the emergency stop and the anti-cheat block

app/src/pc.rs runs every pc_action from the worker (admin.spec.md, "PC
control"): one agent-desktop 1.2.0 run per command with a 15 s limit and
its state in the data folder, never --force or raw input, typed text
only through stdin. Each action is decided by permissions::decide for
its asker (not registered, never, ask without consent), then refused
during the emergency stop, while an anti-cheat game runs (Vanguard,
EAC, BattlEye, FACEIT, GameGuard, XIGNCODE3 and the person's list), on
an administrator window and in a password field. Results carry the
window and its elements read again (200 at most, cut to 120 chars),
agent-desktop's error codes become Korean reasons, and each action is
recorded as pc.<action> with the program's file name only.

The emergency stop is a global hotkey (pcControl.stopHotkey, default
Ctrl+Shift+F12) on its own message loop; it kills the running command
and blocks everything but reading until pressed again or lifted on the
PC control screen. features.pcControl (on by default, nothing happens
until someone is registered) and the pinned exe hash decide whether
the brain gets the tool. The installer ships agent-desktop.exe from the
pinned release archive, both hashes checked.

Tested with a fake agent-desktop (342 lib tests pass) and cargo check
for x86_64-pc-windows-gnu; not yet run against real agent-desktop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-18 22:42:48 +09:00
parent 7539be07a5
commit 39ac20682e
18 changed files with 1658 additions and 55 deletions

View File

@@ -50,7 +50,7 @@ codegen-units = 4
strip = "symbols"
[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_Globalization", "Win32_Security_Cryptography", "Win32_System_SystemInformation", "Win32_Devices_DeviceAndDriverInstallation", "Win32_Graphics_Gdi", "Win32_UI_WindowsAndMessaging", "Win32_System_Registry", "Win32_UI_Shell", "Win32_System_Threading", "Win32_System_Performance", "Win32_System_Diagnostics_ToolHelp", "Win32_Graphics_Dwm"] }
windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_Globalization", "Win32_Security", "Win32_Security_Cryptography", "Win32_System_SystemInformation", "Win32_Devices_DeviceAndDriverInstallation", "Win32_Graphics_Gdi", "Win32_UI_WindowsAndMessaging", "Win32_UI_Input_KeyboardAndMouse", "Win32_System_Registry", "Win32_UI_Shell", "Win32_System_Threading", "Win32_System_Performance", "Win32_System_Diagnostics_ToolHelp", "Win32_Graphics_Dwm"] }
windows = { version = "0.62", features = ["Foundation", "Graphics", "Graphics_Capture", "Graphics_DirectX", "Graphics_DirectX_Direct3D11", "Win32_Foundation", "Win32_Graphics_Gdi", "Win32_Graphics_Direct3D", "Win32_Graphics_Direct3D11", "Win32_Graphics_Dxgi", "Win32_Graphics_Dxgi_Common", "Win32_System_WinRT", "Win32_System_WinRT_Direct3D11", "Win32_System_WinRT_Graphics_Capture"] }
[target.'cfg(unix)'.dependencies]

View File

@@ -226,6 +226,8 @@ Section "Jarvis (필수)" SecMain
SetOutPath "$INSTDIR"
File "${SRC}/jarvis.exe"
File "${SRC}/WebView2Loader.dll"
; PC control's agent-desktop (the app checks its hash before every start).
File "${SRC}/agent-desktop.exe"
; The shortcuts' icon, named by its content: Windows keeps an icon it has shown by the file's path,
; so a changed icon under the old path would stay the old one on the desktop and in search.
Delete "$INSTDIR\jarvis-*.ico"
@@ -334,6 +336,7 @@ Section "Uninstall"
; folder the person chose may hold other things; folders go only when empty.
Delete "$INSTDIR\jarvis.exe"
Delete "$INSTDIR\WebView2Loader.dll"
Delete "$INSTDIR\agent-desktop.exe"
Delete "$INSTDIR\jarvis-*.ico"
!include "${UNINSTALL_LIST}"
Delete "$INSTDIR\uninstall.exe"

View File

@@ -19,7 +19,7 @@ list="$target/uninstall-list.nsh"
setup="$out/Jarvis-Setup-$version.exe"
# The uninstall entry's size: what this setup installs, counted here. Counting the install folder on
# the user's PC would also walk a data folder kept inside it (models, runtime: many thousand files).
size_kb=$(cd "$out/Jarvis" && du -sk --apparent-size -c jarvis.exe WebView2Loader.dll python-src display-driver | tail -1 | cut -f1)
size_kb=$(cd "$out/Jarvis" && du -sk --apparent-size -c jarvis.exe WebView2Loader.dll agent-desktop.exe python-src display-driver | tail -1 | cut -f1)
# The shortcuts' icon file is named by its content, so a new icon gets a path Windows has not seen.
icon_file="jarvis-$(sha256sum "$here/icons/icon.ico" | cut -c1-12).ico"
makensis -V2 -DVERSION="$version" -DSRC="$out/Jarvis" -DOUT="$setup" -DICON="$here/icons/icon.ico" -DICON_FILE="$icon_file" \

View File

@@ -1,8 +1,9 @@
#!/bin/sh
# Build the Windows management app from Linux and lay it out ready to zip (admin.spec.md, "Windows build"):
# Jarvis/jarvis.exe, Jarvis/WebView2Loader.dll, Jarvis/python-src/{voice_worker,jarvis},
# Jarvis/display-driver/ (Virtual Display Driver 25.7.23, MIT, SignPath-signed; "Virtual monitor")
# Needs the x86_64-pc-windows-gnu Rust target, mingw-w64, cmake (for Opus), curl and unzip.
# Jarvis/display-driver/ (Virtual Display Driver 25.7.23, MIT, SignPath-signed; "Virtual monitor"),
# Jarvis/agent-desktop.exe (agent-desktop 1.2.0, Apache-2.0; "PC control")
# Needs the x86_64-pc-windows-gnu Rust target, mingw-w64, cmake (for Opus), curl, unzip and tar.
# app/shell/package.sh <output folder>
set -eu
here=$(cd "$(dirname "$0")" && pwd)
@@ -30,4 +31,14 @@ unzip -q "$vdd_zip" -d "$tmp"
mkdir -p "$out/Jarvis/display-driver"
cp "$tmp/VirtualDisplayDriver/MttVDD.inf" "$tmp/VirtualDisplayDriver/mttvdd.cat" "$tmp/VirtualDisplayDriver/MttVDD.dll" "$out/Jarvis/display-driver/"
rm -rf "$tmp"
# PC control's agent-desktop, the archive and the program pinned by hash as in app/src/pc.rs (the
# app checks the program's hash again before every start of the services).
ad_url=https://github.com/vercel-labs/agent-desktop/releases/download/v1.2.0/agent-desktop-v1.2.0-x86_64-pc-windows-msvc.tar.gz
ad_sha=a4199f741a441cedd349bf56c5eba01783b1261258b498efeb7ec9945220c3e8
ad_exe_sha=d274667031322e50b9c2b1ab81c2ca46835d52cc932769a5c34bd4d481fd94c3
ad_tgz="$target/agent-desktop-1.2.0.tar.gz"
[ -f "$ad_tgz" ] || curl -fsSL -o "$ad_tgz" "$ad_url"
echo "$ad_sha $ad_tgz" | sha256sum -c - >/dev/null || { rm -f "$ad_tgz"; echo "agent-desktop hash mismatch" >&2; exit 1; }
tar -xzf "$ad_tgz" -C "$out/Jarvis" agent-desktop.exe
echo "$ad_exe_sha $out/Jarvis/agent-desktop.exe" | sha256sum -c - >/dev/null || { echo "agent-desktop.exe hash mismatch" >&2; exit 1; }
echo "$out/Jarvis"

View File

@@ -66,9 +66,10 @@ manages the MCP servers it connects.
"Virtual monitor"), off by default; `schedule` (reminders and scheduled tasks, below
"Schedules", and the brain tool `schedule`), on by default; `notes` (personal notes, below
"Personal notes", and the brain tool `personalNotes`), on by default; `screen` (화면 보기, below
"Screen viewing", and the brain tool `screenView`), on by default. The tools of a feature that
is off go into the brain's `disabled_tools`: they are neither offered nor run
(`voice_worker.spec.md`, "Tools"). PC control comes with its milestone (M7).
"Screen viewing", and the brain tool `screenView`), on by default; `pcControl` (PC 제어, below "PC
control", and the brain tool `pcControl`), on by default (like `screen`, nothing is done until
someone is in `pcControl.allowedUsers`). The tools of a feature that is off go into the brain's
`disabled_tools`: they are neither offered nor run (`voice_worker.spec.md`, "Tools").
- `mcpServers` (new list): each `{name, command, args, env, enabled}`. `name` is 1-32 letters,
digits, `-` or `_` without `__` (the brain names a server's tools `<name>__<tool>`), not listed
twice; `command` is not empty; `args` a list of strings; `env` the names of the environment
@@ -166,8 +167,12 @@ decision 2026-11-14). What Jarvis may do on this PC and for whom; the PC control
agrees in their next message (checked by the PC control tool like the chat delete consent).
- Never done, whatever the settings: payments, passwords and other secrets, deleting files, and
anything that needs administrator rights. They have no setting.
- The PC 제어 screen edits the section and shows, read-only, what is never done and each registered
chat channel's send and delete switches (changed on the 채팅 채널 screen).
- `antiCheatGames` (program file names, ".exe" may be left out, at most 100, no folders; empty by
default) and `stopHotkey` (modifiers `Ctrl`, `Alt`, `Shift`, `Win` and one letter, digit or
F1-F24, at least one modifier; default `Ctrl+Shift+F12`): below "PC control".
- The PC 제어 screen edits the section and shows the emergency stop's state with 풀기 (below "PC
control"), and, read-only, what is never done and each registered chat channel's send and
delete switches (changed on the 채팅 채널 screen).
## Screen viewing (`app/src/screen.rs`)
@@ -220,10 +225,25 @@ agent-desktop and decides who may.
- **agent-desktop**: version 1.2.0 (Apache-2.0), pinned with its SHA-256, shipped in the installer
next to `jarvis.exe` (`agent-desktop.exe`, about 4 MB) and checked before every start of the
services (a wrong hash means not available). One CLI run per command (M0 `desktop`: 0.10 s, as
fast as its MCP server), its APPDATA and LOCALAPPDATA in the data folder (`runtime/agent-desktop`),
a 15 s limit per command. Actions are headless (no cursor, no focus), except `keys`, which brings
the window to the front first. `--force` (which lifts its block on Alt+F4, Win+R, Ctrl+Shift+Esc
and the like) and the raw mouse and key commands are never used.
fast as its MCP server), its APPDATA, LOCALAPPDATA and state folder (`AGENT_DESKTOP_HOME`, where
it keeps its readings) in the data folder (`runtime/agent-desktop`), a 15 s limit per command. A
program it starts gets the person's own APPDATA and LOCALAPPDATA back and starts in their user
folder. Actions are headless (no cursor, no focus), except `keys`, which brings the window to the
front first (`focus-window`, then `press`). `--force` (which lifts its block on Alt+F4, Win+R,
Ctrl+Shift+Esc and the like) and the raw mouse and key commands are never used; what the brain
sends is checked so nothing in it reads as an option, and typed text goes in through stdin
(`set-value --stdin`), never in the arguments. The commands: `list-windows`, `snapshot
--window-id` (`read`), `click`, `get --property states` then `set-value` (`type`), `focus-window`
then `press` (`keys`), `launch` (`run`), `close-app` (`close`: agent-desktop has no command for
one window, so the program closes gracefully with all its windows), `restore`.
- **Windows**: as `list-windows` gives them, without this app's own windows, windows without a
title and the programs of `pcControl.screenExclude` (never listed, read or acted on, as for
screen viewing); at most 30. `window` is a window id or part of a title or program name (the
focused match first, else the first listed). An element (`@<snapshot>:e<n>`) acts on the window
it was read from; one from a reading this run did not make gets `STALE_REF`'s reason. `run` takes
a program name only (no folders): one in Windows' folders as it is, else the file Windows' App
Paths or a Start menu shortcut without arguments points at; the window is the one `launch` names,
else a new one of its process or name, else the only new one, waited for up to 5 s.
- **Available** only on Windows with `features.pcControl` on, someone in `pcControl.allowedUsers`
and agent-desktop present; otherwise `pcControl` is in the brain's `disabled_tools`. Settings
apply on the next start.
@@ -243,18 +263,26 @@ agent-desktop and decides who may.
(VALORANT, League of Legends; the driver is always loaded), Easy Anti-Cheat, BattlEye, FACEIT,
nProtect GameGuard and XIGNCODE3 by their own processes (list in `pc.rs`, grown by updates), and
`pcControl.antiCheatGames` (program file names the person added on the PC 제어 screen; no switch
turns the check off). The game's name is the game detection's when it runs, else the program's.
turns the check off). The game's name is the game detection's when it runs, else the program's
(Riot's processes are named as their games). Processes are found by their file names in Windows'
process list, also those this user may not open.
- **Emergency stop**: a global hotkey (`pcControl.stopHotkey`, default `Ctrl+Shift+F12`) stops at
once: the running agent-desktop command is killed and every action but `windows` and `read` is
refused ("비상 정지 중입니다. 단축키를 한 번 더 누르거나 PC 제어 화면에서 풀어 주세요") until the
hotkey is pressed again or the PC 제어 screen lifts it. The dashboard shows "PC 제어: 비상 정지";
an app restart lifts it.
an app restart lifts it. The hotkey is registered (`RegisterHotKey`, its own thread and message
loop) while the services run with PC control available; one Windows refuses (another program
holds it) is a warning in the log. A reading started while the stop is on runs to its end.
- **Results**: `read` and every action answer with the window `{id, program, title}` and its
interactive elements read afresh after the action (at most 200), so the brain says it was done
only from what it sees. agent-desktop's error codes come back as Korean reasons (`STALE_REF`: "화면이
바뀌었습니다. 다시 읽어 주세요"; a minimised window is restored before acting).
- **Refused before asking**: the stop, the anti-cheat, an administrator window (a process whose
elevation cannot be read counts as one) and a password field are refused without asking.
`windows` and `read` at `ask` answer `ask: true` like the rest.
- **Activity**: each action but `windows` and `read` is `pc.<action>` with the program's file name
(never a title, element name or text), who asked and whether it worked ("Activity").
(never a title, element name or text), who asked and whether it worked, with the refusal's reason
("Activity"); an `ask` answer is not recorded (nothing was done).
- Logs carry the action, the result code and the time taken; never a title, element name, value or
typed text.
@@ -309,7 +337,7 @@ records and "Traces"), so it works while the services are stopped. Nothing it re
`docs/v2/proactive.md` (제안 5). What Jarvis did outside its answers, for the 로그 screen's 한 일 view: each chat
channel action the brain's tool asked for (`chat.send`, `chat.edit`, `chat.react`, `chat.delete`,
`chat.pin`, `chat.unpin`), each schedule delivery (`schedule.remind`, `schedule.task`) and each
news notification (`collect.notify`), each screen capture (`screen.view`, "Screen viewing"), done or failed. The other PC control actions join it with M7. Ordinary answers are not recorded.
news notification (`collect.notify`), each screen capture (`screen.view`, "Screen viewing") and each PC control action (`pc.click`, `pc.type`, `pc.keys`, `pc.run`, `pc.close`, "PC control"), done or failed. Ordinary answers are not recorded.
- One JSON line per action in `activity/<YYYY-MM-DD>.jsonl` (the folder is made at the first one):
`{at, kind, target, by, ok, note}`. `target` is the channel (and message) id or `예약 <id>`; `by`
@@ -772,6 +800,7 @@ back as Korean messages for the screen. The Tauri shell passes the screens' `inv
| `settings_fields` / `settings_view` / `settings_apply` `{changes}` | the settings editor above; `restartNeeded` when the services run and something other than `voice.tts.speed` changed (the speed reaches the running worker at once, `discord_core.spec.md`); `sync` with the chat channels sent to Discord (below) |
| `service_start` / `service_stop` / `service_restart` / `dashboard` | the controller and its snapshot; start and restart run in the background, stop also cancels a start |
| `discord_channel_info` `{id}` / `channel_sync_status` | a channel's Discord name and topic / each synced chat channel's last result (above) |
| `pc_stop_status` / `pc_stop_lift` | `{stopped}`: PC control's emergency stop (above, "PC control") / lift it |
| `notes_list` / `note_update` `{id, text}` / `note_delete` `{id}` | everyone's personal notes (above) / change one's text / delete one |
| `history_query` `{said, answered, thought, via, person, channel, find, since, until, session, before, from, limit}` | the 대화 screen's records and answer traces (above, "Conversations") |
| `history_stamp` | `{stamp}`: changes when what the 대화 screen shows may have changed (above, "Conversations") |
@@ -920,7 +949,8 @@ both to a release with that tag. The repository's other releases (v1's `v1.x`) a
`icons/icon.png` 512 px): voice bars in a ring on the accent colour's gradient; at 32 px and below
only three thicker bars, so it stays readable in the taskbar and tray.
- `app/shell/package.sh <folder>` builds it on Linux (`x86_64-pc-windows-gnu`, mingw-w64) and lays
out `Jarvis/`: `jarvis.exe`, `WebView2Loader.dll`, `python-src/` (the `voice_worker` and
out `Jarvis/`: `jarvis.exe`, `WebView2Loader.dll`, `agent-desktop.exe` (PC control, from the
pinned release archive, both hashes checked), `python-src/` (the `voice_worker` and
`jarvis` packages, no caches or specs) and `display-driver/` (the virtual monitor's driver). The worker's sources are `python-src` next to the
executable when it is there, also over a `voiceWorker.cwd` the settings keep (another install's
first-run setup may have written its own folder there, and an update must never run those older
@@ -1049,7 +1079,16 @@ moves or is brought back during the capture never shown (taken again, or refused
moving), a window of a program that cannot be told treated as excluded, windows by title or program
front first (never excluded, secondary or the app's own), minimised and black pictures refused, the
detail sizes and parts; the worker protocol test carries a 4K capture's pictures to a fake brain and
back. Performance stages (on every system, with a fake
back. PC control (on every system, with a fake agent-desktop): people not registered and kinds at
`never` refused before any command, `ask` answered without consent and done with it, the
anti-cheat refusing every action but reading (its own processes and the person's list, named by
game detection), the emergency stop refusing and lifted, and the real runner killing a running
command when it is pressed and at its time limit, a password field and an administrator window
refused before acting, readings capped at 200 elements (interactive first) and cut to 120
characters, `STALE_REF`'s reason, a minimised window restored and `keys` brought to the front,
excluded and own windows never listed, `run` reading its new window, the activity naming the
program only, the hotkey and shortcut formats, and one pin of agent-desktop in `pc.rs`,
`package.sh` and M0. Performance stages (on every system, with a fake
Strata and card): a game moves the LLM to the game placement (measured once at 16K and one request,
2 GiB on the game PC's numbers, half the 16 engine threads) and back after the wait, pause stops
it, a card with no room for a game pauses, the normal stage counts a program opened since, the game

View File

@@ -410,6 +410,12 @@ impl AdminApi {
v
}).collect::<Vec<_>>()}))
}
// PC control's emergency stop (admin.spec.md, "PC control"): its state, and 풀기.
"pc_stop_status" => Ok(json!({"stopped": crate::pc::emergency().on()})),
"pc_stop_lift" => {
crate::pc::emergency().lift();
Ok(json!({"stopped": false}))
}
// Personal notes (admin.spec.md, "Personal notes"): everyone's, editable on the screen.
"notes_list" => {
let items = crate::notes::Notes::new(self.dir()?.path()).all()?;

View File

@@ -303,6 +303,7 @@ impl Controller {
view["llm"] = self.host.llm();
view["game"] = status.get("game").cloned().unwrap_or(Value::Null);
view["performance"] = status.get("performance").cloned().unwrap_or(Value::Null);
view["pcStop"] = json!(crate::pc::emergency().on());
view
}

View File

@@ -207,6 +207,8 @@ struct Inner {
notes: OnceLock<Arc<crate::notes::Notes>>,
/// What Jarvis did outside its answers (admin.spec.md, "Activity").
activity: OnceLock<Arc<crate::activity::Activity>>,
/// PC control, when it is available (admin.spec.md, "PC control").
pc: OnceLock<Arc<crate::pc::Pc>>,
/// Speech requests whose end someone waits for (`say_to_end`), by request id.
speech_waits: Mutex<HashMap<String, tokio::sync::oneshot::Sender<PlaybackEnd>>>,
/// The spoken transcription notice of the current voice session.
@@ -334,6 +336,7 @@ impl DiscordCore {
notice: Mutex::new(JoinNotice::default()),
activity: OnceLock::new(),
notes: OnceLock::new(),
pc: OnceLock::new(),
});
tokio::spawn(player_task(Arc::downgrade(&inner), player_rx));
tokio::spawn(worker_task(Arc::downgrade(&inner), worker_events));
@@ -597,6 +600,11 @@ impl DiscordCore {
let _ = self.inner.activity.set(activity);
}
/// PC control for the brain's pcControl tool; without it its actions are refused.
pub fn set_pc(&self, pc: Arc<crate::pc::Pc>) {
let _ = self.inner.pc.set(pc);
}
/// Run a scheduled task in the brain (read-only tools, not spoken) and wait for its answer.
pub async fn run_task(&self, id: &str, user: u64, text: &str) -> Option<String> {
let (tx, rx) = tokio::sync::oneshot::channel();
@@ -1018,6 +1026,26 @@ async fn worker_task(core: std::sync::Weak<Inner>, mut rx: mpsc::UnboundedReceiv
inner.worker.screen_action_result(&a.id, result);
});
}
WorkerEvent::PcAction(a) => {
let inner = inner.clone();
tokio::spawn(async move {
let started = std::time::Instant::now();
let pc = inner.pc.get().cloned();
let req = a.clone();
let out = tokio::task::spawn_blocking(move || pc.map(|pc| pc.act(&req))).await.ok().flatten();
let out = out.unwrap_or_else(|| crate::pc::Outcome {
reply: serde_json::json!({"ok": false, "error": "이 PC에서는 PC 제어를 쓸 수 없습니다"}),
code: "unavailable".into(), activity: None });
// The action, its result code and the time only: never a title, element or text.
debug_log!("conversation", "pc {} {} {} ms={}", a.id, a.action.chars().take(10).collect::<String>(),
out.code, started.elapsed().as_millis());
if let (Some(r), Some(activity)) = (&out.activity, inner.activity.get()) {
let by = a.user.parse().ok().map(|u| format!("{u} {}", name_of(&inner, u)));
activity.record(&r.kind, &r.target, by, r.ok, r.note.clone());
}
inner.worker.pc_action_result(&a.id, out.reply);
});
}
WorkerEvent::ScheduleAction(a) => {
let result = match inner.schedules.get() {
Some(store) => {

View File

@@ -22,13 +22,17 @@ pub const FEATURE_TOOLS: &[(&str, &[&str])] = &[
("collect", &["collectedNews"]),
];
/// The built-in tools of the features that are off, and `screenView` unless screen viewing is
/// available (admin.spec.md, "Screen viewing").
pub fn disabled_tools(s: &Settings) -> Vec<&'static str> {
/// The built-in tools of the features that are off, `screenView` unless screen viewing is
/// available (admin.spec.md, "Screen viewing") and `pcControl` unless PC control is (`pc`: checked
/// with agent-desktop's hash as the services start, admin.spec.md, "PC control").
pub fn disabled_tools(s: &Settings, pc: bool) -> Vec<&'static str> {
let mut off = feature_tools_off(&s.features);
if !crate::screen::available(s) {
off.push("screenView");
}
if !pc {
off.push("pcControl");
}
off
}
@@ -120,15 +124,18 @@ mod tests {
let mut s = Settings::default();
s.pc_control.allowed_users = vec![1];
let screen = if cfg!(windows) { vec![] } else { vec!["screenView"] };
assert_eq!(disabled_tools(&s), screen, "all on by default");
s.features = FeatureSettings { weather: false, web_search: true, meals: false, collect: false, browser: false, browser_share: false, schedule: false, notes: false, screen: true };
assert_eq!(disabled_tools(&s, true), screen, "all on by default");
s.features = FeatureSettings { weather: false, web_search: true, meals: false, collect: false, browser: false, browser_share: false, schedule: false, notes: false, screen: true, pc_control: true };
let mut want = vec!["getWeather", "logMeal", "fetchMeals", "deleteMeal", "botBrowser", "schedule", "personalNotes", "collectedNews"];
want.extend(&screen);
assert_eq!(disabled_tools(&s), want);
assert_eq!(disabled_tools(&s, true), want);
// Screen viewing needs someone registered for PC control (and Windows).
assert!(disabled_tools(&Settings::default()).contains(&"screenView"));
assert!(disabled_tools(&Settings::default(), true).contains(&"screenView"));
s.features.screen = false;
assert!(disabled_tools(&s).contains(&"screenView"));
assert!(disabled_tools(&s, true).contains(&"screenView"));
// PC control is offered only when it is available (`pc::available` and agent-desktop).
assert!(disabled_tools(&s, false).contains(&"pcControl"));
assert!(!disabled_tools(&s, true).contains(&"pcControl"));
}
#[test]

View File

@@ -274,6 +274,11 @@ impl GameWatch {
self.state.lock().unwrap().current().is_some()
}
/// The game's name while game mode is on (PC control's anti-cheat sentence).
pub fn name(&self) -> Option<String> {
self.state.lock().unwrap().current().map(|d| d.name.clone())
}
/// The game for the dashboard: `{name, reason}` or null.
pub fn view(&self) -> serde_json::Value {
serde_json::json!(self.state.lock().unwrap().current())

View File

@@ -25,6 +25,7 @@ pub mod install;
pub mod logs;
pub mod notes;
pub mod playback;
pub mod pc;
pub mod perf;
pub mod permissions;
pub mod placement;

1391
app/src/pc.rs Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -31,6 +31,8 @@ pub struct Services {
pub schedules: std::sync::Mutex<Option<tokio::task::JoinHandle<()>>>,
/// Announces new collected items (admin.spec.md, "News notifications").
pub news: std::sync::Mutex<Option<tokio::task::JoinHandle<()>>>,
/// PC control's emergency-stop hotkey while PC control is available (admin.spec.md, "PC control").
pub pc_hotkey: std::sync::Mutex<Option<crate::pc::Hotkey>>,
}
/// The bot browser of a run (admin.spec.md, "Bot browser").
@@ -82,6 +84,9 @@ impl Services {
n.abort();
let _ = n.await;
}
if let Some(h) = self.pc_hotkey.lock().unwrap().take() {
h.end();
}
self.game.stop();
self.core.close().await;
self.worker.close();
@@ -155,8 +160,10 @@ pub async fn start_services(data_dir: &Path, llm: Arc<Llm>) -> Result<Services,
hub.set_secrets_in_use(secrets_in_use(&token, &mcp_env, kma_key.as_deref()));
}
// PC control: agent-desktop's hash is checked once per start (admin.spec.md, "PC control").
let pc_exe = crate::pc::check(&settings);
let (base_url, model) = llm.start(&settings).await?;
let brain_config = match crate::strata::write_brain_config(data_dir, &base_url, &model, &settings) {
let brain_config = match crate::strata::write_brain_config(data_dir, &base_url, &model, &settings, pc_exe.is_some()) {
Ok(f) => f,
Err(e) => return Err(after_llm_stop(&llm, format!("could not write the brain settings: {e}")).await.into()),
};
@@ -214,7 +221,19 @@ pub async fn start_services(data_dir: &Path, llm: Arc<Llm>) -> Result<Services,
let chat_calls = conversation::ChatCalls::from_settings(&settings);
let schedule_channel = settings.schedule_channel;
let news_settings = settings.clone();
let pc = pc_exe.as_ref().map(|exe| {
let g = game.clone();
crate::pc::Pc::new(settings.clone(), Box::new(crate::pc::Cli::new(exe, data_dir)), crate::pc::emergency(),
Box::new(move || g.name()))
});
let stop_hotkey = settings.pc_control.stop_hotkey.clone();
let (core, core_events) = DiscordCore::new(settings, token, worker.clone(), worker_events);
let pc_hotkey = std::sync::Mutex::new(None);
if let Some(pc) = pc {
core.set_pc(Arc::new(pc));
*pc_hotkey.lock().unwrap() = crate::pc::Hotkey::start(&stop_hotkey, crate::pc::emergency());
crate::info_log!("conversation", "PC control available (agent-desktop {})", crate::pc::AGENT_DESKTOP_VERSION);
}
let schedule_store = Arc::new(crate::schedule::Store::new(data_dir));
core.set_schedules(schedule_store.clone());
let activity = Arc::new(crate::activity::Activity::new(data_dir));
@@ -237,7 +256,7 @@ pub async fn start_services(data_dir: &Path, llm: Arc<Llm>) -> Result<Services,
Arc::new(core.clone()), activity))));
let on = { let g = game.clone(); Arc::new(move || g.on()) };
let perf = std::sync::Mutex::new(Some(tokio::spawn(perf_loop(perf_settings, llm.clone(), Arc::new(worker.clone()), on, RETRY_AFTER))));
Ok(Services { core, events, worker, worker_process, missed, llm, browser, game, perf, schedules, news })
Ok(Services { core, events, worker, worker_process, missed, llm, browser, game, perf, schedules, news, pc_hotkey })
}
/// The voice worker writes its recordings where this names (voice_worker.spec.md, "Recordings").

View File

@@ -106,6 +106,8 @@ pub struct FeatureSettings {
pub notes: bool,
/// Screen viewing (admin.spec.md, "Screen viewing").
pub screen: bool,
/// Operating programs through agent-desktop (admin.spec.md, "PC control").
pub pc_control: bool,
}
/// Game detection (admin.spec.md, "Game detection"): on by default; the person's own games and
@@ -187,6 +189,11 @@ pub struct PcControlSettings {
pub run: Level,
/// Programs never seen on the screen (file names, ".exe" may be left out).
pub screen_exclude: Vec<String>,
/// Programs with an anti-cheat the person added (file names, ".exe" may be left out): while one
/// runs, nothing but reading is done (admin.spec.md, "PC control").
pub anti_cheat_games: Vec<String>,
/// The emergency stop's global hotkey (`Ctrl+Shift+F12`).
pub stop_hotkey: String,
}
/// An MCP server the brain starts (stdio). The values of `env` are in the secrets, never here.
@@ -276,14 +283,15 @@ impl Default for Settings {
response: PolicySettings::default(),
memory: Map::new(),
llm: LlmSettings { url: None, port: 8080, context: 32768 },
features: FeatureSettings { weather: true, web_search: true, meals: true, collect: true, browser: true, browser_share: false, schedule: true, notes: true, screen: true },
features: FeatureSettings { weather: true, web_search: true, meals: true, collect: true, browser: true, browser_share: false, schedule: true, notes: true, screen: true, pc_control: true },
mcp_servers: vec![],
collect: CollectSettings { keep_days: 30, targets: vec![], notify_channel: None, digest_hour: 9 },
game: GameSettings { detect: true, games: vec![], not_games: vec![], other_room_gb: 1.0, reserve_gb: 8.0, revert_seconds: 30, pause_in_game: false },
schedule_channel: None,
pc_control: PcControlSettings { allowed_users: vec![], view: Level::Auto, click: Level::Ask,
type_text: Level::Ask, run: Level::Ask,
screen_exclude: ["1Password", "Bitwarden", "KeePass", "KeePassXC"].map(String::from).into() },
screen_exclude: ["1Password", "Bitwarden", "KeePass", "KeePassXC"].map(String::from).into(),
anti_cheat_games: vec![], stop_hotkey: crate::pc::DEFAULT_STOP_HOTKEY.into() },
close_to_tray: false,
location: Some(DEFAULT_LOCATION.into()),
}
@@ -627,6 +635,7 @@ pub fn parse_settings(raw: &Value) -> Result<Settings, SettingsError> {
schedule: get_bool(f, "schedule", "features", d.features.schedule)?,
notes: get_bool(f, "notes", "features", d.features.notes)?,
screen: get_bool(f, "screen", "features", d.features.screen)?,
pc_control: get_bool(f, "pcControl", "features", d.features.pc_control)?,
}
},
mcp_servers: parse_mcp_servers(raw)?,
@@ -660,20 +669,27 @@ fn parse_pc_control(raw: &Map<String, Value>, d: &PcControlSettings) -> Result<P
Some(_) => err(format!("pcControl.{key} must be auto, ask or never")),
}
};
let programs = |key: &str, default: &[String]| -> Result<Vec<String>, SettingsError> {
let v: Vec<String> = get_str_list(p, key, "pcControl", default)?.into_iter()
.map(|e| e.trim().to_owned()).filter(|e| !e.is_empty()).collect();
if v.len() > 100 || v.iter().any(|e| e.chars().count() > 100 || e.contains(['\\', '/'])) {
return err(format!("pcControl.{key} must be at most 100 program names (no folders)"));
}
Ok(v)
};
let stop_hotkey = get_str(p, "stopHotkey", "pcControl", &d.stop_hotkey)?.trim().to_owned();
if crate::pc::parse_hotkey(&stop_hotkey).is_none() {
return err("pcControl.stopHotkey must be modifiers and a key, such as Ctrl+Shift+F12");
}
Ok(PcControlSettings {
allowed_users: snowflake_list(p, "allowedUsers", "pcControl")?,
view: level("view", d.view)?,
click: level("click", d.click)?,
type_text: level("type", d.type_text)?,
run: level("run", d.run)?,
screen_exclude: {
let v: Vec<String> = get_str_list(p, "screenExclude", "pcControl", &d.screen_exclude)?.into_iter()
.map(|e| e.trim().to_owned()).filter(|e| !e.is_empty()).collect();
if v.len() > 100 || v.iter().any(|e| e.chars().count() > 100 || e.contains(['\\', '/'])) {
return err("pcControl.screenExclude must be at most 100 program names (no folders)");
}
v
},
screen_exclude: programs("screenExclude", &d.screen_exclude)?,
anti_cheat_games: programs("antiCheatGames", &d.anti_cheat_games)?,
stop_hotkey,
})
}
@@ -1054,13 +1070,13 @@ mod tests {
#[test]
fn features_and_mcp_servers_are_read_and_checked() {
let s = parse_settings(&json!({}));
assert_eq!(s.unwrap().features, FeatureSettings { weather: true, web_search: true, meals: true, collect: true, browser: true, browser_share: false, schedule: true, notes: true, screen: true });
assert_eq!(s.unwrap().features, FeatureSettings { weather: true, web_search: true, meals: true, collect: true, browser: true, browser_share: false, schedule: true, notes: true, screen: true, pc_control: true });
let s = parse_settings(&json!({
"features": {"weather": false, "meals": false, "browserShare": true, "schedule": false, "notes": false, "screen": false},
"features": {"weather": false, "meals": false, "browserShare": true, "schedule": false, "notes": false, "screen": false, "pcControl": false},
"mcpServers": [{"name": "brave", "command": "npx", "args": ["-y", "brave"], "env": ["BRAVE_API_KEY", " "]},
{"name": "time-2", "command": "uvx", "enabled": false}]
})).unwrap();
assert_eq!(s.features, FeatureSettings { weather: false, web_search: true, meals: false, collect: true, browser: true, browser_share: true, schedule: false, notes: false, screen: false });
assert_eq!(s.features, FeatureSettings { weather: false, web_search: true, meals: false, collect: true, browser: true, browser_share: true, schedule: false, notes: false, screen: false, pc_control: false });
assert_eq!(s.mcp_servers, vec![
McpServerSettings { name: "brave".into(), command: "npx".into(), args: vec!["-y".into(), "brave".into()],
env: vec!["BRAVE_API_KEY".into()], enabled: true },
@@ -1071,13 +1087,23 @@ mod tests {
assert!(pc.allowed_users.is_empty());
assert_eq!((pc.view, pc.click, pc.type_text, pc.run), (Level::Auto, Level::Ask, Level::Ask, Level::Ask));
assert!(pc.screen_exclude.contains(&"KeePassXC".to_owned()), "password managers are never seen by default");
assert!(pc.anti_cheat_games.is_empty());
assert_eq!(pc.stop_hotkey, "Ctrl+Shift+F12");
let pc = parse_settings(&json!({"pcControl": {"allowedUsers": ["123456789012345678"], "view": "never",
"click": "auto", "type": "never", "run": "auto", "screenExclude": [" bank.exe ", ""]}})).unwrap().pc_control;
"click": "auto", "type": "never", "run": "auto", "screenExclude": [" bank.exe ", ""],
"antiCheatGames": ["MyShooter"], "stopHotkey": "Ctrl+Shift+Nope"}})).unwrap_err();
assert!(pc.0.contains("pcControl.stopHotkey"), "{pc}");
let pc = parse_settings(&json!({"pcControl": {"allowedUsers": ["123456789012345678"], "view": "never",
"click": "auto", "type": "never", "run": "auto", "screenExclude": [" bank.exe ", ""],
"antiCheatGames": ["MyShooter"], "stopHotkey": " ctrl+alt+s "}})).unwrap().pc_control;
assert_eq!(pc.allowed_users, vec![123456789012345678]);
assert_eq!(pc.screen_exclude, vec!["bank.exe".to_owned()]);
assert_eq!(pc.anti_cheat_games, vec!["MyShooter".to_owned()]);
assert_eq!(pc.stop_hotkey, "ctrl+alt+s");
assert_eq!((pc.view, pc.click, pc.type_text, pc.run), (Level::Never, Level::Auto, Level::Never, Level::Auto));
for bad in [json!({"pcControl": {"click": "yes"}}), json!({"pcControl": {"allowedUsers": ["1"]}}),
json!({"pcControl": {"screenExclude": ["C:\\bank\\bank.exe"]}}), json!({"pcControl": {"screenExclude": "x"}})] {
json!({"pcControl": {"screenExclude": ["C:\\bank\\bank.exe"]}}), json!({"pcControl": {"screenExclude": "x"}}),
json!({"pcControl": {"antiCheatGames": ["D:\\games\\x.exe"]}}), json!({"pcControl": {"stopHotkey": "F12"}})] {
assert!(parse_settings(&bad).unwrap_err().0.contains("pcControl."), "{bad}");
}
// A schedule channel must be a registered one that Jarvis may send in.

View File

@@ -141,6 +141,7 @@ pub fn fields() -> Vec<Field> {
f("features.schedule", Features, Bool, json!(true), "예약 알림과 정기 작업"),
f("features.notes", Features, Bool, json!(true), "사람별 지침"),
f("features.screen", Features, Bool, json!(true), "화면 보기(Windows, PC 제어에 등록한 사람만)"),
f("features.pcControl", Features, Bool, json!(true), "PC 제어(Windows, PC 제어에 등록한 사람만, 다음 시작부터)"),
f("mcpServers", Features, McpServers, json!([]), "MCP 서버"),
// Background collection (admin.spec.md, "Background collection"): no targets by default.
f("collect.targets", Collect, CollectTargets, json!([]), "수집 대상"),
@@ -157,7 +158,11 @@ pub fn fields() -> Vec<Field> {
f("pcControl.type", PcControl, Choice { values: LEVELS }, json!("ask"), "글자·키 입력"),
f("pcControl.run", PcControl, Choice { values: LEVELS }, json!("ask"), "프로그램 실행"),
f("pcControl.screenExclude", PcControl, TextList { max_items: 100, nullable: false },
json!(["1Password", "Bitwarden", "KeePass", "KeePassXC"]), "화면 보기에서 뺄 프로그램(파일 이름, 은행·비밀번호 관리자 등)"),
json!(["1Password", "Bitwarden", "KeePass", "KeePassXC"]), "화면 보기와 PC 제어에서 뺄 프로그램(파일 이름, 은행·비밀번호 관리자 등)"),
f("pcControl.antiCheatGames", PcControl, TextList { max_items: 100, nullable: false }, json!([]),
"안티치트가 있는 게임(파일 이름, 실행 중이면 키보드·마우스 제어를 하지 않음)"),
f("pcControl.stopHotkey", PcControl, Text { max: 40, non_empty: true }, json!(crate::pc::DEFAULT_STOP_HOTKEY),
"비상 정지 단축키(예: Ctrl+Shift+F12, 다음 시작부터)"),
// Game detection (admin.spec.md, "Game detection").
f("game.detect", Game, Bool, json!(true), "게임 감지"),
f("game.games", Game, TextList { max_items: 100, nullable: false }, json!([]), "게임으로 볼 프로그램(파일 이름, 예: MyGame.exe)"),

View File

@@ -236,17 +236,17 @@ async fn warm_up(base: &str) -> Result<(), String> {
}
/// The brain's settings (`config/brain.json`, the worker's `JARVIS_CONFIG_PATH`): the LLM, the
/// memory database inside the data folder, the tools of the features that are off and the enabled
/// MCP servers (without their environment values, `features.rs`). The app owns this file and writes
/// it on every start.
pub fn write_brain_config(data: &Path, base_url: &str, model: &str, settings: &crate::settings::Settings)
/// memory database inside the data folder, the tools of the features that are off (`pc`: whether PC
/// control is available) and the enabled MCP servers (without their environment values,
/// `features.rs`). The app owns this file and writes it on every start.
pub fn write_brain_config(data: &Path, base_url: &str, model: &str, settings: &crate::settings::Settings, pc: bool)
-> Result<std::path::PathBuf, String> {
let file = data.join("config").join("brain.json");
let cfg = json!({
"ollama_base_url": base_url,
"ollama_chat_model": model,
"db_path": data.join("memory").join("jarvis.db").to_string_lossy(),
"disabled_tools": crate::features::disabled_tools(settings),
"disabled_tools": crate::features::disabled_tools(settings, pc),
"mcps": crate::features::brain_mcps(&settings.mcp_servers),
"location_name": settings.location,
"_config_version": 1,
@@ -722,16 +722,17 @@ pub(crate) mod tests {
let l = layout("llm2");
let s = parse_settings(&json!({"features": {"weather": false},
"mcpServers": [{"name": "brave", "command": "npx", "env": ["BRAVE_API_KEY"]}]})).unwrap();
let f = write_brain_config(&l.data, "http://127.0.0.1:8080/v1", "m", &s).unwrap();
let f = write_brain_config(&l.data, "http://127.0.0.1:8080/v1", "m", &s, false).unwrap();
let v: Value = serde_json::from_str(&std::fs::read_to_string(f).unwrap()).unwrap();
assert_eq!(v["ollama_base_url"], "http://127.0.0.1:8080/v1");
assert_eq!(v["ollama_chat_model"], "m");
assert!(Path::new(v["db_path"].as_str().unwrap()).starts_with(&l.data));
assert_eq!(v["disabled_tools"], json!(crate::features::disabled_tools(&s)));
assert_eq!(v["disabled_tools"], json!(crate::features::disabled_tools(&s, false)));
assert!(v["disabled_tools"].as_array().unwrap().contains(&json!("pcControl")));
assert_eq!(v["mcps"], crate::features::brain_mcps(&s.mcp_servers));
assert_eq!(v["location_name"], crate::settings::DEFAULT_LOCATION, "the people are in Korea by default");
let none = parse_settings(&json!({"brain": {"location": ""}})).unwrap();
let f = write_brain_config(&l.data, "http://127.0.0.1:8080/v1", "m", &none).unwrap();
let f = write_brain_config(&l.data, "http://127.0.0.1:8080/v1", "m", &none, false).unwrap();
let v: Value = serde_json::from_str(&std::fs::read_to_string(f).unwrap()).unwrap();
assert_eq!(v["location_name"], Value::Null);
}

View File

@@ -184,6 +184,35 @@ pub struct ScreenAction {
pub detail: Option<String>,
}
/// The brain's pcControl tool asks the app for the person asking (voice_worker.spec.md, "PC control").
#[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct PcAction {
pub id: String,
/// `windows`, `read`, `click`, `type`, `keys`, `run` or `close`.
pub action: String,
pub user: String,
/// `voice` or `chat`: where they asked.
#[serde(default)]
pub via: Option<String>,
#[serde(default)]
pub channel: Option<String>,
/// A window id from `windows`, or part of a program name or title.
#[serde(default)]
pub window: Option<String>,
/// An element from the latest reading (`@<snapshot>:e<n>`).
#[serde(default, rename = "ref")]
pub element: Option<String>,
#[serde(default)]
pub text: Option<String>,
#[serde(default)]
pub keys: Option<String>,
#[serde(default)]
pub program: Option<String>,
/// The person agreed in their next message (the tool checked it).
#[serde(default)]
pub consent: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub enum WorkerEvent {
Ready(HelloOk),
@@ -197,6 +226,7 @@ pub enum WorkerEvent {
ScheduleAction(ScheduleAction),
NoteAction(NoteAction),
ScreenAction(ScreenAction),
PcAction(PcAction),
/// The brain's answer to `reply` (empty and `failed` when it gave none).
ReplyText { id: String, text: String, failed: bool },
/// Was the utterance said to Jarvis? (a failed judgement is a no)
@@ -404,6 +434,14 @@ impl WorkerClient {
self.app_action_result("screen_action_result", id, result);
}
/// The outcome of a `pc_action`: `{ok, item}`, `{ok: false, error}` or `{ok: false, ask, kinds,
/// window}`, as `pc.rs` made it.
pub fn pc_action_result(&self, id: &str, mut reply: Value) {
reply["type"] = json!("pc_action_result");
reply["id"] = json!(id);
self.send_json(reply);
}
fn app_action_result(&self, kind: &str, id: &str, result: Result<Value, String>) {
let msg = match result {
Ok(Value::Object(mut m)) => {
@@ -718,6 +756,7 @@ fn on_text(inner: &Inner, t: &str) {
"schedule_action" => serde_json::from_value(v).ok().map(WorkerEvent::ScheduleAction),
"note_action" => serde_json::from_value(v).ok().map(WorkerEvent::NoteAction),
"screen_action" => serde_json::from_value(v).ok().map(WorkerEvent::ScreenAction),
"pc_action" => serde_json::from_value(v).ok().map(WorkerEvent::PcAction),
"llm_idle" => {
if let Some(id) = v["id"].as_u64() {
inner.llm_idle.send_if_modified(|got| if id > *got { *got = id; true } else { false });

View File

@@ -340,6 +340,26 @@ async function scheduleList() {
h("div", { class: "field" }, h("button", { class: "btn", onclick: load }, "새로 고침")), list);
}
/** PC control's emergency stop (admin.spec.md, "PC control"): its state and 풀기. */
async function pcStopCard() {
const state = h("div");
const load = async () => {
try {
const { stopped } = await api("pc_stop_status");
state.replaceChildren(stopped
? h("div", {}, h("span", { class: "badge bad" }, "비상 정지 중"), " ", h("button", { class: "btn", onclick: async () => {
try { await api("pc_stop_lift"); toast("비상 정지를 풀었습니다"); load(); } catch (e) { fail(e); }
} }, "풀기"))
: h("div", { class: "muted" }, "비상 정지 중이 아닙니다"));
} catch (e) { fail(e); }
};
load();
return h("div", { class: "card" }, h("h2", {}, "비상 정지"),
h("div", { class: "hint" }, "비상 정지 단축키를 누르면 하던 조작을 바로 멈추고, 다시 누르거나 여기서 풀 때까지 화면 보기와 창 목록 말고는 하지 않습니다. " +
"앱을 다시 시작해도 풀립니다. 안티치트가 있는 게임이 실행 중일 때도 키보드·마우스 제어는 하지 않습니다."),
h("div", { class: "field" }, h("button", { class: "btn", onclick: load }, "새로 고침")), state);
}
/** What is never done, and the chat channels' send and delete switches, beside the PC control levels. */
async function permissionsCard() {
const view = await api("settings_view");
@@ -802,7 +822,8 @@ function dashboardBody(d) {
h("span", { class: "k" }, "게임 모드"), h("span", { class: d.game ? "" : "muted" },
d.game ? `켜짐 (${d.game.name}, ${GAME_REASON[d.game.reason.kind]?.(d.game.reason) ?? d.game.reason.kind})` : "꺼짐"),
h("span", { class: "k" }, "성능 단계"), h("span", { class: d.performance && d.performance.stage !== "normal" ? "" : "muted" },
perfText(d.performance))))),
perfText(d.performance)),
d.pcStop ? [h("span", { class: "k" }, "PC 제어"), h("span", {}, h("span", { class: "badge bad" }, "비상 정지"))] : null))),
h("div", { class: "grid" },
h("div", { class: "card" }, h("h2", {}, "실시간 자막"), h("div", { class: "captions" },
(d.captions || []).length ? d.captions.map((c) => h("div", { class: "cap" + (c.final ? "" : " partial") }, h("b", {}, c.name), c.text))
@@ -1018,7 +1039,7 @@ async function show(name) {
const view = await settingsScreen(name, titles[name], extra);
if (name === "collect") view.append(await collectResults());
if (name === "schedule") view.append(await scheduleList());
if (name === "pcControl") view.append(await permissionsCard());
if (name === "pcControl") view.append(await pcStopCard(), await permissionsCard());
if (my !== gen) return;
screen.replaceChildren(view);
if (update) ticker = setInterval(update.tick, 1000);