fix(app): collection connects only to the addresses it checked, within 15 s, logging no address
- the fetcher resolves once, requires every address to be public and connects only to those (TLS still checks the name), so DNS rebinding cannot reach the local network; redirects too - 15 s for the whole fetch also against servers that send slowly; no URL in any log line - a site whose title alone changed is kept again - target names that differ only in case are refused (one Windows folder) - the worker always gets the collection file, so results older than the keep days go also with no targets or the feature off - the results screen lists every target with results, not only those in the newest 100 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -88,13 +88,13 @@ sites, search words and RSS feeds on a schedule; there are **no targets by defau
|
||||
- `collect` (new section): `keepDays` (1-365, default 30) and `targets` (default empty), each
|
||||
`{name, kind, value, everyMinutes, enabled}`. `name` is 1-32 letters, digits, `-` or `_` (any
|
||||
script; it names the target's folder, so not a Windows device name like `con` or `nul`), not
|
||||
listed twice; `kind` is `site`, `search` or `rss`; `value` is an http(s) address for `site` and
|
||||
listed twice, also not in another case (`News` and `news` would share one Windows folder); `kind` is `site`, `search` or `rss`; `value` is an http(s) address for `site` and
|
||||
`rss` (at most 2,000 characters) and the words for `search` (1-200 characters);
|
||||
`everyMinutes` 15-10080 (default 60); `enabled` on by default.
|
||||
- On start, with `features.collect` on and at least one enabled target, the app writes
|
||||
`config/collect.json` (the folder `collect/`, `keepDays` and the enabled targets) and passes it to
|
||||
the worker as `JARVIS_COLLECT_PATH`; otherwise it removes that file and passes nothing. The worker
|
||||
collects while the services run (`voice_worker.spec.md`, "Background collection"); results stay
|
||||
- On every start the app writes `config/collect.json` (the folder `collect/`, `keepDays` and the
|
||||
enabled targets, none with `features.collect` off) and passes it to the worker as
|
||||
`JARVIS_COLLECT_PATH`. Without targets the worker collects nothing but still deletes results
|
||||
older than `keepDays`. The worker collects while the services run (`voice_worker.spec.md`, "Background collection"); results stay
|
||||
in `collect/<name>/<YYYY-MM-DD>.jsonl` in the data folder only.
|
||||
- `results(data, target, limit)` reads them newest first (the newest day file first, its last line
|
||||
first), each item with its `target`; a name that is not a valid target name is refused, so no
|
||||
@@ -305,7 +305,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; `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) |
|
||||
| `collect_results` `{target, limit}` | collected items newest first (`target` null: every target; `limit` 1-500, default 100) |
|
||||
| `collect_results` `{target, limit}` | `{targets, items}`: every target folder with results, and the collected items newest first (`target` null: every target; `limit` 1-500, default 100) |
|
||||
| `mcp_env_status` / `mcp_env_set` `{server, name, value}` | which MCP environment values are stored (`{server: {NAME: bool}}`, never the values) / store one (an empty value removes it); only for a saved server and name |
|
||||
| `install_status` / `install_start` / `install_cancel` | the install steps and their state, bytes and last line / run what is not done in the background / stop it |
|
||||
| `logs_query` `{tab, level, find, after, limit}` / `logs_error_report` / `logs_export` `{from, to}` | the log hub; the zip goes to `logs/` and its path comes back |
|
||||
@@ -339,7 +339,7 @@ Plain HTML, CSS and an ES module, no build step, dark theme after `DESIGN.md`. A
|
||||
one per line, on/off, delete), and for a saved server a password box per environment variable
|
||||
that stores its value on its own. The 백그라운드 수집 screen has the targets (a table: name, kind,
|
||||
address or words, interval in minutes, on/off, delete), the keep days, and the results (the
|
||||
newest 100, filtered by target, each with its time, title, link and the start of its text shown
|
||||
newest 100, filtered by any target that has results, each with its time, title, link and the start of its text shown
|
||||
as plain text).
|
||||
- **Logs**: tab, level and text filters, pause, live follow (lines after the last seen), "최근 오류
|
||||
복사" (to the clipboard; over 2,000 characters it suggests the zip), and the zip export by days.
|
||||
|
||||
@@ -284,7 +284,9 @@ impl AdminApi {
|
||||
"collect_results" => {
|
||||
let target = args.get("target").and_then(Value::as_str).filter(|t| !t.is_empty());
|
||||
let limit = args.get("limit").and_then(Value::as_u64).unwrap_or(100).clamp(1, 500) as usize;
|
||||
Ok(json!(crate::collect::results(self.dir()?.path(), target, limit)?))
|
||||
let dir = self.dir()?;
|
||||
Ok(json!({"targets": crate::collect::result_targets(dir.path()),
|
||||
"items": crate::collect::results(dir.path(), target, limit)?}))
|
||||
}
|
||||
"channel_sync_status" => Ok(Value::Object(self.syncer()?.status().into_iter()
|
||||
.map(|(id, s)| (id.to_string(), json!(s))).collect())),
|
||||
@@ -409,7 +411,7 @@ mod tests {
|
||||
std::fs::create_dir_all(&day).unwrap();
|
||||
std::fs::write(day.join("2026-11-13.jsonl"), "{\"at\": \"2026-11-13T09:00:00+09:00\", \"title\": \"t\"}\n").unwrap();
|
||||
let r = a.call("collect_results", json!({"target": null})).await.unwrap();
|
||||
assert_eq!(r, json!([{"at": "2026-11-13T09:00:00+09:00", "title": "t", "target": "뉴스"}]));
|
||||
assert_eq!(r, json!({"targets": ["뉴스"], "items": [{"at": "2026-11-13T09:00:00+09:00", "title": "t", "target": "뉴스"}]}));
|
||||
assert!(a.call("collect_results", json!({"target": "../config"})).await.is_err());
|
||||
}
|
||||
|
||||
|
||||
@@ -10,25 +10,19 @@ use crate::settings::{valid_collect_name, Settings};
|
||||
/// The worker's environment variable with the collection file (`voice_worker/collect.py`).
|
||||
pub const COLLECT_ENV_VAR: &str = "JARVIS_COLLECT_PATH";
|
||||
|
||||
/// Write `config/collect.json` with the enabled targets and return it; with the feature off or no
|
||||
/// enabled target, remove it and return None (the worker then collects nothing).
|
||||
pub fn write_config(data: &Path, settings: &Settings) -> std::io::Result<Option<PathBuf>> {
|
||||
/// Write `config/collect.json` and return it. With the feature off it lists no targets: the worker
|
||||
/// then collects nothing but still deletes day files older than the keep days.
|
||||
pub fn write_config(data: &Path, settings: &Settings) -> std::io::Result<PathBuf> {
|
||||
let file = data.join("config").join("collect.json");
|
||||
let targets: Vec<Value> = settings.collect.targets.iter().filter(|t| t.enabled)
|
||||
let targets: Vec<Value> = settings.collect.targets.iter().filter(|t| t.enabled && settings.features.collect)
|
||||
.map(|t| json!({"name": t.name, "kind": t.kind, "value": t.value, "everyMinutes": t.every_minutes}))
|
||||
.collect();
|
||||
if !settings.features.collect || targets.is_empty() {
|
||||
match std::fs::remove_file(&file) {
|
||||
Err(e) if e.kind() != std::io::ErrorKind::NotFound => return Err(e),
|
||||
_ => return Ok(None),
|
||||
}
|
||||
}
|
||||
let cfg = json!({"dir": data.join("collect").to_string_lossy(), "keepDays": settings.collect.keep_days,
|
||||
"targets": targets});
|
||||
let mut text = serde_json::to_string_pretty(&cfg).unwrap();
|
||||
text.push('\n');
|
||||
crate::datadir::write_atomic(&file, text.as_bytes())?;
|
||||
Ok(Some(file))
|
||||
Ok(file)
|
||||
}
|
||||
|
||||
/// The day files of one target folder, newest first.
|
||||
@@ -41,17 +35,25 @@ fn day_files(folder: &Path) -> Vec<PathBuf> {
|
||||
files
|
||||
}
|
||||
|
||||
/// The target folders that hold results, sorted.
|
||||
pub fn result_targets(data: &Path) -> Vec<String> {
|
||||
let root = data.join("collect");
|
||||
let mut names: Vec<String> = std::fs::read_dir(&root).into_iter().flatten().flatten()
|
||||
.filter(|e| e.path().is_dir())
|
||||
.filter_map(|e| e.file_name().to_str().map(str::to_owned))
|
||||
.filter(|n| valid_collect_name(n) && !day_files(&root.join(n)).is_empty())
|
||||
.collect();
|
||||
names.sort();
|
||||
names
|
||||
}
|
||||
|
||||
/// Collected items newest first, each with its `target`; `target` None reads every target folder.
|
||||
pub fn results(data: &Path, target: Option<&str>, limit: usize) -> Result<Vec<Value>, String> {
|
||||
let root = data.join("collect");
|
||||
let names: Vec<String> = match target {
|
||||
Some(t) if !valid_collect_name(t) => return Err(format!("not a collection target name: {t}")),
|
||||
Some(t) => vec![t.to_owned()],
|
||||
None => std::fs::read_dir(&root).into_iter().flatten().flatten()
|
||||
.filter(|e| e.path().is_dir())
|
||||
.filter_map(|e| e.file_name().to_str().map(str::to_owned))
|
||||
.filter(|n| valid_collect_name(n))
|
||||
.collect(),
|
||||
None => result_targets(data),
|
||||
};
|
||||
let mut out: Vec<Value> = Vec::new();
|
||||
for name in names {
|
||||
@@ -87,23 +89,21 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_worker_gets_only_enabled_targets_and_nothing_without_them() {
|
||||
fn the_worker_gets_only_enabled_targets_and_the_keep_days_also_without_targets() {
|
||||
let data = temp_dir("collect-cfg");
|
||||
let s = settings(json!({"collect": {"keepDays": 3, "targets": [
|
||||
{"name": "a", "kind": "rss", "value": "https://a.example/rss", "everyMinutes": 30},
|
||||
{"name": "b", "kind": "site", "value": "https://b.example", "enabled": false}]}}));
|
||||
let file = write_config(&data, &s).unwrap().unwrap();
|
||||
let cfg: Value = serde_json::from_str(&std::fs::read_to_string(&file).unwrap()).unwrap();
|
||||
assert_eq!(cfg, json!({"dir": data.join("collect").to_string_lossy(), "keepDays": 3,
|
||||
let read = |f: &Path| serde_json::from_str::<Value>(&std::fs::read_to_string(f).unwrap()).unwrap();
|
||||
let dir = data.join("collect").to_string_lossy().into_owned();
|
||||
let file = write_config(&data, &s).unwrap();
|
||||
assert_eq!(read(&file), json!({"dir": dir, "keepDays": 3,
|
||||
"targets": [{"name": "a", "kind": "rss", "value": "https://a.example/rss", "everyMinutes": 30}]}));
|
||||
|
||||
// Feature off or no targets: nothing to collect, but old results still go after keepDays.
|
||||
let mut off = s.clone();
|
||||
off.features.collect = false;
|
||||
assert_eq!(write_config(&data, &off).unwrap(), None);
|
||||
assert!(!file.exists());
|
||||
write_config(&data, &s).unwrap();
|
||||
assert_eq!(write_config(&data, &settings(json!({}))).unwrap(), None);
|
||||
assert!(!file.exists());
|
||||
assert_eq!(read(&write_config(&data, &off).unwrap()), json!({"dir": dir, "keepDays": 3, "targets": []}));
|
||||
assert_eq!(read(&write_config(&data, &settings(json!({}))).unwrap()), json!({"dir": dir, "keepDays": 30, "targets": []}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -125,6 +125,9 @@ mod tests {
|
||||
assert_eq!(titles(results(&data, Some("뉴스"), 2).unwrap()), ["뉴스:n2", "뉴스:n1"]);
|
||||
assert_eq!(titles(results(&data, None, 2).unwrap()), ["뉴스:n2", "site:s1"]);
|
||||
assert!(results(&data, Some("missing"), 10).unwrap().is_empty());
|
||||
// Every target with results is listed, also one whose items are all older than the newest.
|
||||
std::fs::create_dir_all(data.join("collect").join("empty")).unwrap();
|
||||
assert_eq!(result_targets(&data), ["site", "뉴스"]);
|
||||
assert!(results(&data, Some(".."), 10).is_err());
|
||||
assert!(results(&data, Some("../config"), 10).is_err());
|
||||
}
|
||||
|
||||
@@ -70,10 +70,9 @@ pub async fn start_services(data_dir: &Path, llm: Arc<Llm>) -> Result<Services,
|
||||
}
|
||||
wopts.env.insert("JARVIS_CONFIG_PATH".into(), brain_config.to_string_lossy().into_owned());
|
||||
wopts.env.insert(crate::features::MCP_ENV_VAR.into(), mcp_env.to_string());
|
||||
// Background collection: only with the feature on and enabled targets (admin.spec.md).
|
||||
// Background collection (admin.spec.md): the enabled targets, and the keep days in any case.
|
||||
match crate::collect::write_config(data_dir, &settings) {
|
||||
Ok(Some(f)) => { wopts.env.insert(crate::collect::COLLECT_ENV_VAR.into(), f.to_string_lossy().into_owned()); }
|
||||
Ok(None) => {}
|
||||
Ok(f) => { wopts.env.insert(crate::collect::COLLECT_ENV_VAR.into(), f.to_string_lossy().into_owned()); }
|
||||
Err(e) => return Err(after_llm_stop(&llm, format!("could not write the collection settings: {e}")).await.into()),
|
||||
}
|
||||
let worker_process = match WorkerProcess::new(wopts) {
|
||||
|
||||
@@ -550,8 +550,9 @@ fn parse_collect(raw: &Map<String, Value>, d: &CollectSettings) -> Result<Collec
|
||||
if !valid_collect_name(&name) {
|
||||
return err(format!("{path}.name must be 1-32 letters, digits, - or _ (not a device name like con)"));
|
||||
}
|
||||
if targets.iter().any(|t| t.name == name) {
|
||||
return err(format!("{path}.name is listed twice"));
|
||||
// Windows folder names ignore case: `News` and `news` would share one folder and state.
|
||||
if targets.iter().any(|t| t.name.to_lowercase() == name.to_lowercase()) {
|
||||
return err(format!("{path}.name is listed twice (names that differ only in case count as the same)"));
|
||||
}
|
||||
let kind = get_str(Some(m), "kind", &path, "")?;
|
||||
let value = get_str(Some(m), "value", &path, "")?.trim().to_owned();
|
||||
@@ -867,6 +868,8 @@ mod tests {
|
||||
(t(json!({"everyMinutes": 10081})), "collect.targets[0].everyMinutes"),
|
||||
(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"},
|
||||
{"name": "news", "kind": "rss", "value": "https://b"}]}}), "collect.targets[1].name"),
|
||||
];
|
||||
for (raw, key) in cases {
|
||||
let e = parse_settings(&raw).unwrap_err();
|
||||
|
||||
Reference in New Issue
Block a user