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

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