feat: news notifications for the background collection and a collectedNews tool

Each collection target can announce new items at once or in a daily digest
(off by default) in collect.notifyChannel, as titles and links only, with no
LLM; each post is recorded in the activity log. The brain gets a read-only
collectedNews tool (every target's newest items by default, fenced as
untrusted web content), offered with the app's collection file and the
collection feature, and available to scheduled tasks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-14 17:22:54 +09:00
parent a5bd25b86f
commit 324fd2ea0a
21 changed files with 653 additions and 28 deletions

View File

@@ -136,6 +136,11 @@ impl GameSettings {
pub struct CollectSettings {
pub keep_days: u32,
pub targets: Vec<CollectTarget>,
/// The registered chat channel new items are announced in (admin.spec.md, "News
/// notifications"); None: nothing is announced.
pub notify_channel: Option<u64>,
/// The hour (0-23, local) the daily digest goes out (default 9).
pub digest_hour: u32,
}
/// One thing to collect: `kind` is `site`, `search` or `rss`; `value` its address or words.
@@ -146,6 +151,8 @@ pub struct CollectTarget {
pub value: String,
pub every_minutes: u32,
pub enabled: bool,
/// New items announced: `off` (default), `now` or `daily`.
pub notify: String,
}
/// How freely Jarvis may do one kind of action on the PC (`app/src/permissions.rs`).
@@ -255,7 +262,7 @@ impl Default for Settings {
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 },
mcp_servers: vec![],
collect: CollectSettings { keep_days: 30, targets: 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,
@@ -535,6 +542,10 @@ pub fn parse_settings(raw: &Value) -> Result<Settings, SettingsError> {
sync_discord: get_bool(Some(m), "syncDiscord", &path, true)?,
});
}
let collect = parse_collect(raw, &d.collect)?;
if collect.notify_channel.is_some_and(|c| !chat_channels.iter().any(|x| x.id == c && x.send)) {
return err("collect.notifyChannel must be a registered chat channel with sending on");
}
let schedule_channel = opt_snowflake(section(raw, "schedule")?, "chatChannel", "schedule", None, "a Discord channel ID")?;
if schedule_channel.is_some_and(|c| !chat_channels.iter().any(|x| x.id == c && x.send)) {
return err("schedule.chatChannel must be a registered chat channel with sending on");
@@ -589,7 +600,7 @@ pub fn parse_settings(raw: &Value) -> Result<Settings, SettingsError> {
}
},
mcp_servers: parse_mcp_servers(raw)?,
collect: parse_collect(raw, &d.collect)?,
collect,
game: parse_game(raw, &d.game)?,
schedule_channel,
pc_control: parse_pc_control(raw, &d.pc_control)?,
@@ -668,8 +679,10 @@ fn parse_game(raw: &Map<String, Value>, d: &GameSettings) -> Result<GameSettings
fn parse_collect(raw: &Map<String, Value>, d: &CollectSettings) -> Result<CollectSettings, SettingsError> {
let c = section(raw, "collect")?;
let keep_days = get_uint(c, "keepDays", "collect", d.keep_days, 1, 365)?;
let notify_channel = opt_snowflake(c, "notifyChannel", "collect", d.notify_channel, "a Discord channel ID")?;
let digest_hour = get_uint(c, "digestHour", "collect", d.digest_hour, 0, 23)?;
let list = match c.and_then(|m| m.get("targets")) {
None => return Ok(CollectSettings { keep_days, targets: vec![] }),
None => return Ok(CollectSettings { keep_days, targets: vec![], notify_channel, digest_hour }),
Some(Value::Array(a)) => a,
Some(_) => return err("collect.targets must be a list"),
};
@@ -701,9 +714,13 @@ fn parse_collect(raw: &Map<String, Value>, d: &CollectSettings) -> Result<Collec
value,
every_minutes: get_uint(Some(m), "everyMinutes", &path, 60, 15, 10080)?,
enabled: get_bool(Some(m), "enabled", &path, true)?,
notify: match get_str(Some(m), "notify", &path, "off")?.as_str() {
n @ ("off" | "now" | "daily") => n.to_owned(),
_ => return err(format!("{path}.notify must be off, now or daily")),
},
});
}
Ok(CollectSettings { keep_days, targets })
Ok(CollectSettings { keep_days, targets, notify_channel, digest_hour })
}
/// An MCP server name: 1-32 letters, digits, `-` or `_`, without `__` (the brain names a server's
@@ -999,17 +1016,27 @@ mod tests {
#[test]
fn collection_targets_are_read_and_checked() {
let s = parse_settings(&json!({})).unwrap();
assert_eq!(s.collect, CollectSettings { keep_days: 30, targets: vec![] });
let s = parse_settings(&json!({"features": {"collect": false}, "collect": {"keepDays": 7, "targets": [
{"name": "뉴스_1", "kind": "rss", "value": " https://feed.example/rss "},
// News notifications are off by default, with no channel, the digest at 9.
assert_eq!(s.collect, CollectSettings { keep_days: 30, targets: vec![], notify_channel: None, digest_hour: 9 });
let s = parse_settings(&json!({"features": {"collect": false},
"chatChannels": [{"id": "123456789012345678"}],
"collect": {"keepDays": 7, "notifyChannel": "123456789012345678", "digestHour": 21, "targets": [
{"name": "뉴스_1", "kind": "rss", "value": " https://feed.example/rss ", "notify": "daily"},
{"name": "rust", "kind": "search", "value": "rust release", "everyMinutes": 1440, "enabled": false}]}})).unwrap();
assert!(!s.features.collect);
assert_eq!(s.collect, CollectSettings { keep_days: 7, targets: vec![
assert_eq!(s.collect, CollectSettings { keep_days: 7, notify_channel: Some(123456789012345678), digest_hour: 21,
targets: vec![
CollectTarget { name: "뉴스_1".into(), kind: "rss".into(), value: "https://feed.example/rss".into(),
every_minutes: 60, enabled: true },
every_minutes: 60, enabled: true, notify: "daily".into() },
CollectTarget { name: "rust".into(), kind: "search".into(), value: "rust release".into(),
every_minutes: 1440, enabled: false },
every_minutes: 1440, enabled: false, notify: "off".into() },
]});
// The channel must be a registered one Jarvis may send in.
for raw in [json!({"collect": {"notifyChannel": "123456789012345678"}}),
json!({"chatChannels": [{"id": "123456789012345678", "send": false}],
"collect": {"notifyChannel": "123456789012345678"}})] {
assert!(parse_settings(&raw).unwrap_err().0.contains("collect.notifyChannel"), "{raw}");
}
let t = |extra: Value| {
let mut m = json!({"name": "a", "kind": "site", "value": "https://a.example"});
m.as_object_mut().unwrap().extend(extra.as_object().unwrap().clone());
@@ -1029,6 +1056,8 @@ mod tests {
(t(json!({"kind": "search", "value": " "})), "collect.targets[0].value"),
(t(json!({"everyMinutes": 14})), "collect.targets[0].everyMinutes"),
(t(json!({"everyMinutes": 10081})), "collect.targets[0].everyMinutes"),
(t(json!({"notify": "hourly"})), "collect.targets[0].notify"),
(json!({"collect": {"digestHour": 24}}), "collect.digestHour"),
(json!({"collect": {"targets": [{"name": "a", "kind": "rss", "value": "https://a"},
{"name": "a", "kind": "rss", "value": "https://b"}]}}), "collect.targets[1].name"),
(json!({"collect": {"targets": [{"name": "News", "kind": "rss", "value": "https://a"},