feat: full pattern matrix — M1 complete, M2 LLM chat, 30+ pattern files #10
2 changed files with 24 additions and 16 deletions
|
|
@ -51,11 +51,12 @@ pub fn run() {
|
||||||
.map(|pf| pf.log_paths.clone())
|
.map(|pf| pf.log_paths.clone())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let mut rx = watcher::spawn(log_paths);
|
let rx = watcher::spawn(log_paths);
|
||||||
let pf = Arc::new(pattern_file);
|
let pf = Arc::new(pattern_file);
|
||||||
let app_handle = app.handle().clone();
|
let app_handle = app.handle().clone();
|
||||||
|
|
||||||
tauri::async_runtime::spawn(async move {
|
tauri::async_runtime::spawn(async move {
|
||||||
|
let mut rx = rx;
|
||||||
while let Some(event) = rx.recv().await {
|
while let Some(event) = rx.recv().await {
|
||||||
if let Some(ref pf) = *pf {
|
if let Some(ref pf) = *pf {
|
||||||
if let Some(matched) = patterns::classify(&event, pf) {
|
if let Some(matched) = patterns::classify(&event, pf) {
|
||||||
|
|
|
||||||
|
|
@ -50,23 +50,30 @@ pub fn load(source_os: &str, distro_family: &str) -> Result<PatternFile> {
|
||||||
format!("/usr/share/robin/patterns/{filename}"),
|
format!("/usr/share/robin/patterns/{filename}"),
|
||||||
];
|
];
|
||||||
for path in &candidates {
|
for path in &candidates {
|
||||||
if let Ok(content) = std::fs::read_to_string(path) {
|
let content = match std::fs::read_to_string(path) {
|
||||||
let pf: PatternFile =
|
Ok(c) => c,
|
||||||
toml::from_str(&content).with_context(|| format!("failed to parse {path}"))?;
|
Err(_) => continue,
|
||||||
for p in &pf.patterns {
|
};
|
||||||
anyhow::ensure!(
|
let pf: PatternFile = match toml::from_str(&content) {
|
||||||
!p.match_text.is_empty(),
|
Ok(p) => p,
|
||||||
"pattern '{}' has empty match_text in {path}",
|
Err(e) => {
|
||||||
p.id
|
log::warn!("patterns: failed to parse {path}: {e}");
|
||||||
);
|
continue;
|
||||||
anyhow::ensure!(
|
|
||||||
!p.sources.is_empty(),
|
|
||||||
"pattern '{}' has empty sources list in {path}",
|
|
||||||
p.id
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return Ok(pf);
|
};
|
||||||
|
for p in &pf.patterns {
|
||||||
|
anyhow::ensure!(
|
||||||
|
!p.match_text.is_empty(),
|
||||||
|
"pattern '{}' has empty match_text in {path}",
|
||||||
|
p.id
|
||||||
|
);
|
||||||
|
anyhow::ensure!(
|
||||||
|
!p.sources.is_empty(),
|
||||||
|
"pattern '{}' has empty sources list in {path}",
|
||||||
|
p.id
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
return Ok(pf);
|
||||||
}
|
}
|
||||||
anyhow::bail!("pattern file not found: {filename}")
|
anyhow::bail!("pattern file not found: {filename}")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue