diff --git a/app/src/admin.spec.md b/app/src/admin.spec.md index eb72159..a1c6a50 100644 --- a/app/src/admin.spec.md +++ b/app/src/admin.spec.md @@ -143,6 +143,24 @@ check something at a time or regularly; the brain's `schedule` tool those are not delivered (and the screen says so). - Logs (tab `conversation`): ids, kinds, repeats, channel ids, counts and outcomes, never the text. +## PC control permissions (`app/src/permissions.rs`) + +`docs/v2/pc-features.md` ("키보드·마우스 제어와 안티치트") and `docs/v2/proactive.md` (제안 3; user +decision 2026-11-14). What Jarvis may do on this PC and for whom; the PC control module (M7) asks +`decide(settings, user, action)` before every action and gets allow, ask or refuse with a reason. + +- `pcControl` (new section): `allowedUsers` (Discord user IDs, empty by default) and a level per + kind of action that can be changed, each `auto`, `ask` or `never`: `view` (seeing the screen, a + monitor or a window, and the window list; default `auto`), `click` (buttons, menu items, a point + on the screen; `ask`), `type` (text and keys; `ask`) and `run` (starting a program; `ask`). +- Only people in `allowedUsers` may ask for anything, screen viewing too (the screen may show + anything); with nobody listed nobody may. `ask` means the action is done only once the person + 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). + ## Secrets (`app/src/secrets.rs`) `config/secrets.dat` holds a JSON object of named secrets (`discordToken`, the MCP servers' @@ -565,7 +583,7 @@ Plain HTML, CSS and an ES module, no build step, dark theme after `DESIGN.md`. A Strata's last line, and stop in the header; the header with start, restart and stop is rebuilt only when the state changes, so a click is never lost to the refresh. Every screen change starts a new generation: an answer that arrives after the user moved to another screen is dropped. -- **Settings screens** (봇, 채널·호출, 채팅 채널, 대화 기억, 모델, 기능, 백그라운드 수집, 예약, 게임 모드): built from `settings_fields`; only +- **Settings screens** (봇, 채널·호출, 채팅 채널, 대화 기억, 모델, 기능, 백그라운드 수집, 예약, PC 제어, 게임 모드): built from `settings_fields`; only changed fields are sent; the server and voice channel are pickers (choosing another server clears the voice channel and lists only that server's channels); the chat channels are a table with their switches; the bot screen also changes the token; the 기능 screen has the feature diff --git a/app/src/lib.rs b/app/src/lib.rs index dcc1c32..42dda51 100644 --- a/app/src/lib.rs +++ b/app/src/lib.rs @@ -22,6 +22,7 @@ pub mod install; pub mod logs; pub mod playback; pub mod perf; +pub mod permissions; pub mod placement; pub mod policy; pub mod receive; diff --git a/app/src/permissions.rs b/app/src/permissions.rs new file mode 100644 index 0000000..16d946a --- /dev/null +++ b/app/src/permissions.rs @@ -0,0 +1,110 @@ +//! What Jarvis may do on this PC, and for whom (`app/src/admin.spec.md`, "PC control permissions"; +//! `docs/v2/proactive.md` 제안 3). The PC control module asks `decide` before every action. + +use crate::settings::{Level, PcControlSettings}; + +/// A kind of action on the PC. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Action { + /// See the screen, a monitor or a window, and list the windows. + View, + /// Press a button, a menu item or a point on the screen. + Click, + /// Put text or keys into a program. + Type, + /// Start a program. + Run, + /// Pay or buy anything. + Pay, + /// Read, type or change a password or another secret. + Password, + /// Delete files. + DeleteFiles, + /// Anything that needs administrator rights. + Admin, +} + +/// Why an action is refused (the PC control module tells the person). +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Refusal { + /// The person is not in `pcControl.allowedUsers`. + NotAllowed, + /// The action's level is "안 함". + TurnedOff, + /// Never done, whatever the settings say. + Never, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Decision { + Allow, + /// Allowed once the person agrees in their next message. + Ask, + Refuse(Refusal), +} + +/// Whether `user` may have Jarvis do `action`. Only registered people may ask for anything (screen +/// viewing too: the screen may show anything); payments, passwords, deleting files and +/// administrator rights are never done. +pub fn decide(s: &PcControlSettings, user: u64, action: Action) -> Decision { + if !s.allowed_users.contains(&user) { + return Decision::Refuse(Refusal::NotAllowed); + } + let level = match action { + Action::View => s.view, + Action::Click => s.click, + Action::Type => s.type_text, + Action::Run => s.run, + Action::Pay | Action::Password | Action::DeleteFiles | Action::Admin => return Decision::Refuse(Refusal::Never), + }; + match level { + Level::Auto => Decision::Allow, + Level::Ask => Decision::Ask, + Level::Never => Decision::Refuse(Refusal::TurnedOff), + } +} + +#[cfg(test)] +mod tests { + use super::*; + + const OWNER: u64 = 123456789012345678; + + fn settings() -> PcControlSettings { + PcControlSettings { allowed_users: vec![OWNER], ..crate::settings::Settings::default().pc_control } + } + + #[test] + fn by_default_viewing_is_automatic_and_operating_asks_first() { + let s = settings(); + assert_eq!(decide(&s, OWNER, Action::View), Decision::Allow); + for a in [Action::Click, Action::Type, Action::Run] { + assert_eq!(decide(&s, OWNER, a), Decision::Ask, "{a:?}"); + } + } + + #[test] + fn only_registered_people_may_ask_for_anything() { + let s = settings(); + for a in [Action::View, Action::Click, Action::Type, Action::Run, Action::Pay] { + assert_eq!(decide(&s, 42, a), Decision::Refuse(Refusal::NotAllowed), "{a:?}"); + } + // Nobody is registered by default. + let none = crate::settings::Settings::default().pc_control; + assert_eq!(decide(&none, OWNER, Action::View), Decision::Refuse(Refusal::NotAllowed)); + } + + #[test] + fn the_levels_follow_the_settings_but_some_actions_are_never_done() { + let s = PcControlSettings { view: Level::Never, click: Level::Auto, type_text: Level::Never, run: Level::Auto, + ..settings() }; + assert_eq!(decide(&s, OWNER, Action::View), Decision::Refuse(Refusal::TurnedOff)); + assert_eq!(decide(&s, OWNER, Action::Click), Decision::Allow); + assert_eq!(decide(&s, OWNER, Action::Type), Decision::Refuse(Refusal::TurnedOff)); + let all_auto = PcControlSettings { view: Level::Auto, click: Level::Auto, type_text: Level::Auto, run: Level::Auto, + ..settings() }; + for a in [Action::Pay, Action::Password, Action::DeleteFiles, Action::Admin] { + assert_eq!(decide(&all_auto, OWNER, a), Decision::Refuse(Refusal::Never), "{a:?}"); + } + } +} diff --git a/app/src/settings.rs b/app/src/settings.rs index cf96fd0..25d39da 100644 --- a/app/src/settings.rs +++ b/app/src/settings.rs @@ -146,6 +146,34 @@ pub struct CollectTarget { pub enabled: bool, } +/// How freely Jarvis may do one kind of action on the PC (`app/src/permissions.rs`). +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Level { + /// Done without asking. + Auto, + /// Done once the person agrees in their next message. + Ask, + /// Not done. + Never, +} + +/// PC control permissions (admin.spec.md, "PC control permissions"): who may ask, and the level of +/// each kind of action that can be changed. Payments, passwords, deleting files and administrator +/// rights are never done and have no setting. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct PcControlSettings { + /// Discord user IDs; nobody by default. + pub allowed_users: Vec, + /// Seeing the screen and listing windows (default automatic). + pub view: Level, + /// Pressing buttons and points (default ask). + pub click: Level, + /// Typing text and keys (default ask). + pub type_text: Level, + /// Starting programs (default ask). + pub run: Level, +} + /// An MCP server the brain starts (stdio). The values of `env` are in the secrets, never here. #[derive(Debug, Clone, PartialEq, Eq)] pub struct McpServerSettings { @@ -179,6 +207,7 @@ pub struct Settings { /// The registered chat channel a schedule asked by voice is posted in when its person is not in /// Jarvis's voice channel (admin.spec.md, "Schedules"); None: not delivered then. pub schedule_channel: Option, + pub pc_control: PcControlSettings, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -227,6 +256,8 @@ impl Default for Settings { collect: CollectSettings { keep_days: 30, targets: vec![] }, 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 }, } } } @@ -558,6 +589,27 @@ pub fn parse_settings(raw: &Value) -> Result { collect: parse_collect(raw, &d.collect)?, game: parse_game(raw, &d.game)?, schedule_channel, + pc_control: parse_pc_control(raw, &d.pc_control)?, + }) +} + +fn parse_pc_control(raw: &Map, d: &PcControlSettings) -> Result { + let p = section(raw, "pcControl")?; + let level = |key: &str, default: Level| -> Result { + match p.and_then(|m| m.get(key)) { + None => Ok(default), + Some(Value::String(v)) if v == "auto" => Ok(Level::Auto), + Some(Value::String(v)) if v == "ask" => Ok(Level::Ask), + Some(Value::String(v)) if v == "never" => Ok(Level::Never), + Some(_) => err(format!("pcControl.{key} must be auto, ask or never")), + } + }; + 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)?, }) } @@ -905,6 +957,17 @@ mod tests { env: vec!["BRAVE_API_KEY".into()], enabled: true }, McpServerSettings { name: "time-2".into(), command: "uvx".into(), args: vec![], env: vec![], enabled: false }, ]); + // PC control: nobody by default, viewing automatic and the rest asked first. + let pc = parse_settings(&json!({})).unwrap().pc_control; + 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)); + let pc = parse_settings(&json!({"pcControl": {"allowedUsers": ["123456789012345678"], "view": "never", + "click": "auto", "type": "never", "run": "auto"}})).unwrap().pc_control; + assert_eq!(pc.allowed_users, vec![123456789012345678]); + 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"]}})] { + assert!(parse_settings(&bad).unwrap_err().0.contains("pcControl."), "{bad}"); + } // A schedule channel must be a registered one that Jarvis may send in. let ch = json!([{"id": "123456789012345678", "send": true}, {"id": "123456789012345679", "send": false}]); let s = parse_settings(&json!({"chatChannels": ch, "schedule": {"chatChannel": "123456789012345678"}})).unwrap(); diff --git a/app/src/settings_edit.rs b/app/src/settings_edit.rs index 524f7d6..b38c83c 100644 --- a/app/src/settings_edit.rs +++ b/app/src/settings_edit.rs @@ -23,6 +23,7 @@ pub enum Screen { Collect, Game, Schedule, + PcControl, } #[derive(Debug, Clone, PartialEq, serde::Serialize)] @@ -66,6 +67,9 @@ fn f(path: &'static str, screen: Screen, kind: Kind, default: Value, label: &'st Field { path, screen, kind, default, label } } +/// The levels of a PC control action (`settings::Level`). +const LEVELS: &[&str] = &["auto", "ask", "never"]; + /// Every key the screens edit, in screen order. pub fn fields() -> Vec { use Kind::*; @@ -135,6 +139,12 @@ pub fn fields() -> Vec { // Schedules (admin.spec.md, "Schedules"). f("schedule.chatChannel", Schedule, Id, Value::Null, "음성으로 맡긴 알림을 그 사람이 음성 채널에 없을 때 보낼 채팅 채널(등록한 채널)"), + // PC control permissions (admin.spec.md, "PC control permissions"). + f("pcControl.allowedUsers", PcControl, IdList, json!([]), "PC 제어를 시킬 수 있는 사람(디스코드 사용자 ID)"), + f("pcControl.view", PcControl, Choice { values: LEVELS }, json!("auto"), "화면 보기, 창 목록"), + f("pcControl.click", PcControl, Choice { values: LEVELS }, json!("ask"), "누르기(버튼, 메뉴, 화면의 한 점)"), + f("pcControl.type", PcControl, Choice { values: LEVELS }, json!("ask"), "글자·키 입력"), + f("pcControl.run", PcControl, Choice { values: LEVELS }, json!("ask"), "프로그램 실행"), // 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)"), diff --git a/app/ui/app.js b/app/ui/app.js index 4f67217..4d0c74e 100644 --- a/app/ui/app.js +++ b/app/ui/app.js @@ -36,7 +36,9 @@ function toast(msg, bad = false) { const fail = (e) => toast(e.message || String(e), true); const gb = (b) => (b / 1e9).toFixed(0) + " GB"; +const LEVEL = { auto: "자동", ask: "먼저 묻기", never: "안 함" }; const CHOICE = { + "pcControl.view": LEVEL, "pcControl.click": LEVEL, "pcControl.type": LEVEL, "pcControl.run": LEVEL, "call.mode": { wakeWord: "호출어로 부를 때만", addressed: "자비스에게 하는 말로 보이면", everything: "모든 말" }, "response.policy": { first: "처음 대화만", inOrder: "순서대로", latest: "가장 최근 것", important: "중요한 것 먼저" }, }; @@ -332,6 +334,22 @@ async function scheduleList() { h("div", { class: "field" }, h("button", { class: "btn", onclick: load }, "새로 고침")), list); } +/** 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"); + const chats = view.chatChannels || []; + const yes = (b) => (b ? "허용" : "안 함"); + return h("div", { class: "card" }, h("h2", {}, "늘 안 하는 것"), + h("div", { class: "hint" }, "결제, 비밀번호, 파일 삭제, 관리자 권한이 필요한 일은 설정과 상관없이 하지 않습니다. " + + "\"먼저 묻기\"는 시킨 사람이 다음 말로 한 번 더 허락해야 합니다. 등록한 사람이 없으면 아무도 PC 제어를 시킬 수 없습니다."), + h("h2", {}, "채팅 채널 권한"), + chats.length ? h("table", {}, h("tbody", {}, chats.map((c) => h("tr", {}, + h("td", {}, c.name || c.id), h("td", { class: "small" }, "보내기: " + yes(c.send ?? true)), + h("td", { class: "small" }, "지우기: " + (c.delete ? "다음 말로 허락받고 허용" : "안 함")))))) + : h("div", { class: "muted" }, "등록한 채팅 채널이 없습니다."), + h("div", { class: "hint" }, "채팅 채널 권한은 \"채팅 채널\" 화면에서 바꿉니다.")); +} + async function settingsScreen(screen, title, extra) { const [all, view] = await Promise.all([fields(), api("settings_view")]); const list = all.filter((f) => f.screen === screen); @@ -650,11 +668,12 @@ async function show(name) { if (name === "logs") { const l = logsScreen(); screen.replaceChildren(l.view); ticker = setInterval(l.tick, 1000); return; } if (name === "update") { const u = updateScreen(); screen.replaceChildren(u.view); ticker = setInterval(u.tick, 1000); return; } const titles = { bot: "봇", channels: "채널·호출", chat: "채팅 채널", memory: "대화 기억", model: "모델", features: "기능", - collect: "백그라운드 수집", game: "게임 모드", schedule: "예약" }; + collect: "백그라운드 수집", game: "게임 모드", schedule: "예약", pcControl: "PC 제어" }; const extra = name === "bot" ? await tokenCard() : name === "features" ? await displayDriverCard() : null; 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 (my === gen) screen.replaceChildren(view); } catch (e) { fail(e); } } diff --git a/app/ui/index.html b/app/ui/index.html index c4bd1d2..2cb284d 100644 --- a/app/ui/index.html +++ b/app/ui/index.html @@ -20,6 +20,7 @@ + diff --git a/docs/v2/proactive.md b/docs/v2/proactive.md index f952a56..821bbd8 100644 --- a/docs/v2/proactive.md +++ b/docs/v2/proactive.md @@ -5,7 +5,7 @@ 진행 상황: - 1 예약 알림과 정기 작업: 구현(2026-11-14). 스펙은 [schedule.spec.md](../../src/jarvis/tools/builtin/schedule.spec.md)(두뇌 도구), [admin.spec.md](../../app/src/admin.spec.md) "Schedules"(저장·시각·전달·예약 화면), [voice_worker.spec.md](../../src/voice_worker/voice_worker.spec.md) "Schedules". 음성으로 맡긴 사람이 음성 채널에 없을 때 보낼 곳은 사람마다 고르지 않고 관리 앱에서 채팅 채널 하나를 정합니다. 정기 작업이 쓸 수 있는 도구에 "수집 결과 읽기"는 아직 없습니다(두뇌가 수집 결과를 읽는 도구가 없음, 제안 2 때 함께 봄). 평가 `evals/test_schedule_tool.py`를 이 서버의 qwen3:8b(실제 모델과 같은 계열)로 v2 설정(짧은 지시문, 의도 판단, 한국어 답)에서 세 번: "5분 타이머"(전에는 도구 없이 "설정했습니다"라고만 답함), "내일 7시 회의 알림", "예약 목록"은 9번 모두 통과했고 알림 문구도 한국어였습니다. "평일마다 아침 9시에 서울 날씨"는 3번 중 1번만 작업·평일로 맞게 예약했고, 나머지는 반복을 평일로 두지 않거나 지금 날씨를 바로 답했습니다. 실제 모델(Qwen3.6-35B-A3B, 게임PC)로는 사용자가 알려 주는 GPU 시간에 돌립니다. -- 3 행동별 세 단계 권한: M7 PC 제어와 함께 만듦. 시킬 수 있는 사람은 관리 앱에 아이디로 등록한 사람만. +- 3 행동별 세 단계 권한: 판단 규칙, 설정, 관리 앱 "PC 제어" 화면 구현(2026-11-14, `app/src/permissions.rs`, 스펙 [admin.spec.md](../../app/src/admin.spec.md) "PC control permissions"). 시킬 수 있는 사람은 관리 앱에 아이디로 등록한 사람만(기본은 아무도 없음). "먼저 묻기"의 다음 말 확인과 실제 동작은 M7 PC 제어 도구에서 이 규칙을 써서 만듦. - 5, 4, 2: 그다음 차례. ## dots가 하는 일 (공개 자료 기준)