Write one pending notice for every active managed session (RFC §11.2 rule 6: "pushed into the session as a notice before the agent's next tool call"). Notice writing is advisory: failures are logged and never change the daemon's own outcome.
(
sessions: &SessionStore,
root: &Path,
kind: WatchNoticeKind,
detail: &str,
remediation: &str,
)
| 433 | /// tool call"). Notice writing is advisory: failures are logged and never |
| 434 | /// change the daemon's own outcome. |
| 435 | fn notify_active_sessions( |
| 436 | sessions: &SessionStore, |
| 437 | root: &Path, |
| 438 | kind: WatchNoticeKind, |
| 439 | detail: &str, |
| 440 | remediation: &str, |
| 441 | ) { |
| 442 | let kind_code = match kind { |
| 443 | WatchNoticeKind::ExternalHeadChange => "external-head-change", |
| 444 | WatchNoticeKind::UnsafeState => "unsafe-state", |
| 445 | WatchNoticeKind::ExportSuppressed => "external-head-change", |
| 446 | }; |
| 447 | let active = match sessions.active_sessions() { |
| 448 | Ok(active) => active, |
| 449 | Err(error) => { |
| 450 | log::warn!("shim watch: cannot list active sessions for notices: {error}"); |
| 451 | return; |
| 452 | } |
| 453 | }; |
| 454 | if active.is_empty() { |
| 455 | print_warning(&format!( |
| 456 | "shim watch: {kind_code}: {detail} ({remediation})" |
| 457 | )); |
| 458 | return; |
| 459 | } |
| 460 | let delivered = active.len(); |
| 461 | for session in active { |
| 462 | if let Err(error) = |
| 463 | sessions.write_watch_notice(&session.session_id, kind_code, detail, remediation) |
| 464 | { |
| 465 | log::warn!( |
| 466 | "shim watch: could not write the watch notice for session {}: {error}", |
| 467 | session.session_id |
| 468 | ); |
| 469 | } |
| 470 | } |
| 471 | print_info(&format!( |
| 472 | "shim watch: {kind_code} notice delivered to {delivered} active session(s)" |
| 473 | )); |
| 474 | } |
| 475 | |
| 476 | /// The daemon entry point: consent, then the hint loop (or a single pass). |
| 477 | pub(crate) fn run_watch(root: &Path, once: bool, poll_ms: u64) -> CliResult<()> { |
no test coverage detected