feat(app): PC control permissions (three levels, registered people only)

permissions::decide gives allow, ask or refuse for an action on the PC: only
people in pcControl.allowedUsers may ask (nobody by default), viewing is
automatic and clicking, typing and running ask first by default, and
payments, passwords, deleting files and administrator rights are never done.
A PC 제어 screen edits the levels and shows the chat channels' send and
delete switches beside them. The PC control tool (M7) will use it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-14 16:44:37 +09:00
parent f952b72ed9
commit e8db417752
8 changed files with 225 additions and 3 deletions

View File

@@ -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

View File

@@ -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;

110
app/src/permissions.rs Normal file
View File

@@ -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:?}");
}
}
}

View File

@@ -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<u64>,
/// 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<u64>,
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<Settings, SettingsError> {
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<String, Value>, d: &PcControlSettings) -> Result<PcControlSettings, SettingsError> {
let p = section(raw, "pcControl")?;
let level = |key: &str, default: Level| -> Result<Level, SettingsError> {
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();

View File

@@ -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<Field> {
use Kind::*;
@@ -135,6 +139,12 @@ pub fn fields() -> Vec<Field> {
// 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)"),