aidaemon_core/approval.rs
1//! Typed call effects and owner approvals.
2//!
3//! A tool declares what one call does and to which target
4//! ([`Tool::effects`](crate::Tool::effects)), so policies judge effects
5//! rather than tool names. A hook that wants the owner to decide returns
6//! [`InterruptKind::OwnerApproval`]; when the resolver denies it, the kernel
7//! remembers the request's effects in [`crate::RunState::declined`] for the
8//! rest of the run.
9
10use serde::{Deserialize, Serialize};
11
12/// Prefix of the reason recorded when the owner declines an approval.
13pub const OWNER_DECLINED: &str = "[OWNER DECLINED]";
14
15/// Prefix of the reason for a call whose owner card got no answer (it
16/// expired, could not be delivered, or the turn was cancelled). Not a
17/// refusal: nothing is remembered as declined.
18pub const OWNER_UNANSWERED: &str = "[NO ANSWER]";
19
20/// Prefix of the reason an outbound secret scan (the
21/// [`crate::Safeguard::Egress`] hook) gives when it refuses a call.
22pub const EGRESS_BLOCKED: &str = "[EGRESS BLOCKED]";
23
24/// Prefix of the reason the [`crate::AuthorityHook`] gives when a call is
25/// outside what the run may do.
26pub const AUTHORITY_BLOCKED: &str = "[AUTHORITY BLOCKED]";
27
28/// Prefix of the refusal a rejected egress call returns to the model after
29/// the run read untrusted content.
30pub const UNTRUSTED_BLOCKED: &str = "[UNTRUSTED BLOCKED]";
31
32/// What kind of thing a call does.
33#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
34#[serde(rename_all = "snake_case")]
35#[non_exhaustive]
36pub enum EffectClass {
37 /// Sends data or acts on a host outside the owner's machine.
38 Egress,
39 /// Deletes a path.
40 Delete,
41 /// Creates or modifies a path.
42 Write,
43 /// Changes configuration stored at a path.
44 Configuration,
45 /// Uses a stored credential.
46 Credential,
47 /// Starts a program.
48 Process,
49 /// One exact call, named by its approval subject. Recorded when the
50 /// owner declines a request that declared no effects, so the identical
51 /// request is not put to the owner again.
52 Call,
53}
54
55impl std::fmt::Display for EffectClass {
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 f.write_str(match self {
58 Self::Egress => "egress",
59 Self::Delete => "delete",
60 Self::Write => "write",
61 Self::Configuration => "configuration",
62 Self::Credential => "credential",
63 Self::Process => "process",
64 Self::Call => "call",
65 })
66 }
67}
68
69impl EffectClass {
70 /// Whether targets of this class are paths, so a target covers the
71 /// paths below it.
72 fn is_path(self) -> bool {
73 matches!(self, Self::Delete | Self::Write | Self::Configuration)
74 }
75}
76
77/// One effect of a call on one target.
78///
79/// The producer normalizes `target`: lowercase `host:port` for
80/// [`EffectClass::Egress`]; an absolute, normalized path for
81/// [`EffectClass::Delete`], [`EffectClass::Write`] and
82/// [`EffectClass::Configuration`]; the profile name for
83/// [`EffectClass::Credential`]; the program name for [`EffectClass::Process`].
84/// Build keys with [`EffectKey::path`], [`EffectKey::egress`] and
85/// [`EffectKey::named`] so every producer uses the same convention.
86#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
87pub struct EffectKey {
88 pub class: EffectClass,
89 pub target: String,
90}
91
92impl EffectKey {
93 /// A path effect (`Delete`, `Write`, `Configuration`) on an absolute
94 /// path, normalized lexically: empty and `.` components dropped, `..`
95 /// resolved, no trailing slash. `None` for a relative path or one that
96 /// climbs above `/`. The filesystem is not consulted (symlinks are not
97 /// resolved). A Windows path with a drive (`C:\Users\x`, `c:/Users/x`)
98 /// is absolute too, written `C:/Users/x`: `\` and `/` both separate its
99 /// components, and the drive letter is uppercase.
100 pub fn path(class: EffectClass, raw: &str) -> Option<EffectKey> {
101 let (root, rest, separators): (String, &str, &[char]) = match raw.as_bytes() {
102 [b'/', ..] => (String::new(), raw, &['/']),
103 [drive, b':', b'\\' | b'/', ..] if drive.is_ascii_alphabetic() => (
104 format!("{}:", (*drive as char).to_ascii_uppercase()),
105 &raw[2..],
106 &['/', '\\'],
107 ),
108 _ => return None,
109 };
110 let mut parts: Vec<&str> = Vec::new();
111 for part in rest.split(separators) {
112 match part {
113 "" | "." => {}
114 ".." => {
115 parts.pop()?;
116 }
117 part => parts.push(part),
118 }
119 }
120 Some(EffectKey {
121 class,
122 target: format!("{root}/{}", parts.join("/")),
123 })
124 }
125
126 /// An egress effect on `host`, with target `host:port`: the host
127 /// lowercased and without a trailing dot (`h.example.` is `h.example`),
128 /// and the port given or else the scheme's default (http
129 /// 80, https 443, ssh 22; 0 for an unknown scheme).
130 pub fn egress(scheme: &str, host: &str, port: Option<u16>) -> EffectKey {
131 let port = port.unwrap_or_else(|| match scheme.to_ascii_lowercase().as_str() {
132 "http" => 80,
133 "https" => 443,
134 "ssh" => 22,
135 _ => 0,
136 });
137 EffectKey {
138 class: EffectClass::Egress,
139 target: format!("{}:{port}", host.to_ascii_lowercase().trim_end_matches('.')),
140 }
141 }
142
143 /// An effect named by an identifier rather than a path or host: the
144 /// profile name for [`EffectClass::Credential`], the program name for
145 /// [`EffectClass::Process`].
146 pub fn named(class: EffectClass, name: &str) -> EffectKey {
147 EffectKey {
148 class,
149 target: name.to_string(),
150 }
151 }
152
153 /// Same class, and the same target or, for path classes, one target is
154 /// the other or below it. Targets are compared as given, so both keys
155 /// must be normalized (built with [`EffectKey::path`],
156 /// [`EffectKey::egress`] or [`EffectKey::named`]): `h.example.invalid`
157 /// does not overlap `h.example.invalid:443`, and `/a/../b` does not
158 /// overlap `/b`.
159 pub fn overlaps(&self, other: &EffectKey) -> bool {
160 if self.class != other.class {
161 return false;
162 }
163 if self.target == other.target {
164 return true;
165 }
166 self.class.is_path()
167 && (path_covers(&self.target, &other.target)
168 || path_covers(&other.target, &self.target))
169 }
170}
171
172/// Whether `inner` is `outer` or a path below it, compared by component.
173fn path_covers(outer: &str, inner: &str) -> bool {
174 let outer = outer.trim_end_matches('/');
175 let inner = inner.trim_end_matches('/');
176 if outer == inner {
177 return true;
178 }
179 // After trimming, the root is empty and covers every absolute path.
180 inner
181 .strip_prefix(outer)
182 .is_some_and(|rest| rest.starts_with('/'))
183}
184
185/// The effects of one call, declared by its tool from the arguments.
186#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
187pub struct CallEffects {
188 pub keys: Vec<EffectKey>,
189 /// `keys` lists everything the call does. `false` means the tool could
190 /// not tell (an opaque script), so policies must not read the list as
191 /// exhaustive.
192 pub complete: bool,
193 /// Every part of the call was read and `keys` name what it changes,
194 /// though the tool does not vouch for the list as `complete` (a shell
195 /// command made only of programs it models: a copy into the work area,
196 /// a listing, `date`). After the owner declines a step, such a call that
197 /// deletes nothing and reaches nothing outside is not taken for the
198 /// declined action by another route.
199 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
200 pub understood: bool,
201}
202
203impl CallEffects {
204 /// Effects not declared: the call may do anything.
205 pub fn unknown() -> Self {
206 Self {
207 keys: Vec::new(),
208 complete: false,
209 understood: false,
210 }
211 }
212
213 /// The call has no effects (a read).
214 pub fn none() -> Self {
215 Self {
216 keys: Vec::new(),
217 complete: true,
218 understood: true,
219 }
220 }
221
222 /// The effects a call's declared access implies, for a tool that
223 /// declares [`crate::Tool::access`] but not [`crate::Tool::effects`]:
224 /// every written path ([`EffectKey::path`]) a [`EffectClass::Write`]
225 /// (and a [`EffectClass::Delete`] too for a destructive tool), every
226 /// host contacted an [`EffectClass::Egress`] (`host:port`, the port
227 /// from the declaration, else the scheme's, https for a bare host), every command a
228 /// [`EffectClass::Process`] named by its program. A read-only tool
229 /// changes nothing, so only its hosts count. Never `complete`: the tool
230 /// declared what it touches, not that the list is all it does. A
231 /// relative path names no key (declare absolute paths, as
232 /// `Workspace::declare` gives). [`CallEffects::unknown`] for an empty
233 /// manifest.
234 ///
235 /// With these keys an owner's denial binds the rest of the run: a later
236 /// call that writes the same path, by any tool, is refused.
237 pub fn from_access(
238 access: &crate::AccessManifest,
239 annotations: crate::ToolAnnotations,
240 ) -> Self {
241 let mut keys: Vec<EffectKey> = Vec::new();
242 let mut push = |key: EffectKey| {
243 if !keys.contains(&key) {
244 keys.push(key);
245 }
246 };
247 if !annotations.read_only {
248 for path in &access.writes {
249 if let Some(key) = EffectKey::path(EffectClass::Write, path) {
250 if annotations.destructive {
251 push(EffectKey {
252 class: EffectClass::Delete,
253 target: key.target.clone(),
254 });
255 }
256 push(key);
257 }
258 }
259 for command in &access.commands {
260 if let Some(program) = program_name(command) {
261 push(EffectKey::named(EffectClass::Process, program));
262 }
263 }
264 }
265 for host in &access.hosts {
266 if let Some(key) = host_effect(host) {
267 push(key);
268 }
269 }
270 Self {
271 keys,
272 complete: false,
273 understood: false,
274 }
275 }
276
277 /// The tool vouches that the call changes no file: the list is
278 /// `complete` and names no path. For a call that may change things
279 /// (whose default effects are [`CallEffects::unknown`]), scope and
280 /// approval policies take an empty [`crate::AccessManifest`] as "changes
281 /// no path", not "paths not declared". A delegation, a ticket or an
282 /// order lookup declares this with [`CallEffects::none`] or its own
283 /// non-path keys. Effects never describe reads.
284 pub fn touches_no_paths(&self) -> bool {
285 self.complete && !self.keys.iter().any(|key| key.class.is_path())
286 }
287}
288
289/// The program a declared command runs: its first word, without its
290/// directory.
291fn program_name(command: &str) -> Option<&str> {
292 let first = command.split_whitespace().next()?;
293 let program = first.rsplit('/').next().unwrap_or(first);
294 (!program.is_empty()).then_some(program)
295}
296
297/// The egress effect of a declared host: `host`, `host:port`, or a URL
298/// (`scheme://user@host:port/path`).
299fn host_effect(declared: &str) -> Option<EffectKey> {
300 let declared = declared.trim();
301 let (scheme, rest) = match declared.split_once("://") {
302 Some((scheme, rest)) => (scheme, rest),
303 None => ("https", declared),
304 };
305 let authority = rest.split(['/', '?', '#']).next().unwrap_or(rest);
306 let authority = authority.rsplit('@').next().unwrap_or(authority);
307 let (host, port) = if let Some(bracketed) = authority.strip_prefix('[') {
308 // An IPv6 literal: `[::1]` or `[::1]:8080`.
309 let (host, after) = bracketed.split_once(']')?;
310 (host, after.strip_prefix(':').and_then(|p| p.parse().ok()))
311 } else {
312 match authority.rsplit_once(':') {
313 Some((host, port)) if !port.is_empty() && port.bytes().all(|b| b.is_ascii_digit()) => {
314 (host, port.parse().ok())
315 }
316 _ => (authority, None),
317 }
318 };
319 if host.is_empty() {
320 return None;
321 }
322 Some(EffectKey::egress(scheme, host, port))
323}
324
325/// How much is at stake in an approval request.
326#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
327#[serde(rename_all = "snake_case")]
328#[non_exhaustive]
329pub enum ApprovalRisk {
330 /// A call new to the owner with nothing known to be at stake.
331 Low,
332 Medium,
333 High,
334 Critical,
335}
336
337/// What the owner is asked to approve.
338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
339pub struct OwnerApprovalRequest {
340 /// The effects the call would have. A denial records them in
341 /// [`crate::RunState::declined`].
342 pub effects: Vec<EffectKey>,
343 /// What the owner sees.
344 pub summary: String,
345 /// The exact action string that stored grants are matched against (for
346 /// example a command line, or `METHOD url`).
347 pub subject: String,
348 pub risk: ApprovalRisk,
349 #[serde(default, skip_serializing_if = "Vec::is_empty")]
350 pub warnings: Vec<String>,
351 /// What the card says, as typed facts each channel renders. Plain
352 /// words only, never authority: grants match `subject`. `None` shows
353 /// `summary` and `warnings` as they are.
354 #[serde(default, skip_serializing_if = "Option::is_none")]
355 pub card: Option<Box<ApprovalCard>>,
356}
357
358impl OwnerApprovalRequest {
359 /// The request to ask the owner about `call`, the way
360 /// `aidaemon_policies::ApprovalPolicy` asks: the call's declared effects
361 /// (from `info`), its tool and arguments as the subject grants match,
362 /// [`ApprovalRisk::Critical`] for a destructive tool and
363 /// [`ApprovalRisk::High`] otherwise, and a card naming the action (a
364 /// command line collapsed under its title, else the tool with its
365 /// arguments collapsed). `why` ends the summary when it is not empty.
366 ///
367 /// A hook asks with it through [`crate::ToolDecision::ask`]:
368 ///
369 /// ```
370 /// use aidaemon_core::{OwnerApprovalRequest, ToolCall, ToolDecision, ToolInfo};
371 ///
372 /// fn decide(call: &ToolCall, info: &ToolInfo) -> ToolDecision {
373 /// ToolDecision::ask(OwnerApprovalRequest::for_call(call, info, "it spends money"))
374 /// }
375 /// ```
376 pub fn for_call(call: &crate::ToolCall, info: &crate::ToolInfo, why: &str) -> Self {
377 Self::for_tool(&call.name, &call.arguments, info, why)
378 }
379
380 /// [`OwnerApprovalRequest::for_call`] from a tool name and arguments
381 /// (`Value::Null` when there are none).
382 pub fn for_tool(
383 tool: &str,
384 arguments: &serde_json::Value,
385 info: &crate::ToolInfo,
386 why: &str,
387 ) -> Self {
388 let subject = if arguments.is_null() {
389 tool.to_string()
390 } else {
391 format!("{tool} {arguments}")
392 };
393 let why = why.trim();
394 Self {
395 card: Some(Box::new(call_card(tool, arguments, info))),
396 effects: info.effects.keys.clone(),
397 summary: if why.is_empty() {
398 format!("Run {subject}")
399 } else {
400 format!("Run {subject}: {why}")
401 },
402 subject,
403 risk: if info.annotations.destructive {
404 ApprovalRisk::Critical
405 } else {
406 ApprovalRisk::High
407 },
408 warnings: Vec::new(),
409 }
410 }
411}
412
413/// The card for a call asked about, from the call's own fields and its
414/// annotations: a command line (with its own title) shown collapsed under a
415/// plain sentence, else the tool's name with its arguments collapsed. Never
416/// the raw JSON as the headline.
417fn call_card(tool: &str, arguments: &serde_json::Value, info: &crate::ToolInfo) -> ApprovalCard {
418 let text = |key: &str| arguments.get(key).and_then(serde_json::Value::as_str);
419 let action = match text("command").or_else(|| text("script")) {
420 Some(line) => CardAction::Command {
421 line: line.to_string(),
422 title: text("description")
423 .map(|title| title.split_whitespace().collect::<Vec<_>>().join(" "))
424 .filter(|title| !title.is_empty()),
425 looks_inside: Vec::new(),
426 },
427 None => CardAction::Use {
428 what: format!("use {}", tool.replace('_', " ")),
429 detail: (!arguments.is_null()).then(|| arguments.to_string()),
430 },
431 };
432 ApprovalCard {
433 impact: info.annotations.destructive.then(|| HighImpact::Deletes {
434 targets: Vec::new(),
435 }),
436 ..ApprovalCard::new(action)
437 }
438}
439
440/// An approval card's content as facts, so every channel says the same
441/// thing in its own formatting: who asks, what will happen, why the owner
442/// is asked, and the one high-impact effect worth a warning.
443#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
444pub struct ApprovalCard {
445 /// The helper asking ("Drupal install"); `None` for the assistant
446 /// itself.
447 #[serde(default, skip_serializing_if = "Option::is_none")]
448 pub asked_by: Option<String>,
449 /// The helper run asking, when a coding agent a run launched asks: the
450 /// key a client finds that agent by.
451 #[serde(default, skip_serializing_if = "Option::is_none")]
452 pub run: Option<String>,
453 pub action: CardAction,
454 #[serde(default, skip_serializing_if = "Option::is_none")]
455 pub reason: Option<AskReason>,
456 /// The effect that earns a warning. `None` for ordinary work, which
457 /// gets no warning however the request's risk is rated.
458 #[serde(default, skip_serializing_if = "Option::is_none")]
459 pub impact: Option<HighImpact>,
460}
461
462impl ApprovalCard {
463 pub fn new(action: CardAction) -> Self {
464 Self {
465 asked_by: None,
466 run: None,
467 action,
468 reason: None,
469 impact: None,
470 }
471 }
472}
473
474/// What allowing the call does.
475#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
476#[serde(rename_all = "snake_case", tag = "kind")]
477#[non_exhaustive]
478pub enum CardAction {
479 /// Run a command on the owner's computer.
480 Command {
481 /// The exact line that runs (secrets hidden); shown collapsed,
482 /// never as the headline.
483 line: String,
484 /// The few plain words the call gave for itself (`description`).
485 #[serde(default, skip_serializing_if = "Option::is_none")]
486 title: Option<String>,
487 /// The folders a read-only command only looks inside, by name.
488 #[serde(default, skip_serializing_if = "Vec::is_empty")]
489 looks_inside: Vec<String>,
490 },
491 /// Let the browser open a site on this computer.
492 OpenLocalSite {
493 site: String,
494 /// How long a one-time allowance lasts.
495 once_minutes: u64,
496 },
497 /// Click a button on a web site in the browser (one whose effect the
498 /// page's script decides). Allow Once covers only this click; allowing
499 /// it for the session covers buttons on `site` (an origin) until the
500 /// browser session ends. Forms, passwords and payment fields still ask
501 /// every time.
502 ClickOnSite {
503 site: String,
504 /// The selector the click targets, shown collapsed.
505 #[serde(default, skip_serializing_if = "Option::is_none")]
506 target: Option<String>,
507 },
508 /// Use a tool; `what` completes "wants to …".
509 Use {
510 what: String,
511 /// The call's arguments as they would run, shown collapsed.
512 #[serde(default, skip_serializing_if = "Option::is_none")]
513 detail: Option<String>,
514 },
515 /// The agent asks the owner to do something themselves on a live
516 /// surface (sign in, enter a code), then press Done. `what` is the
517 /// agent's few words; `site` the host only.
518 TakeOver {
519 surface_id: String,
520 what: String,
521 #[serde(default, skip_serializing_if = "Option::is_none")]
522 site: Option<String>,
523 /// Whether a sign-in made there is kept for later tasks.
524 #[serde(default, skip_serializing_if = "Option::is_none")]
525 keeps_sign_in: Option<bool>,
526 /// Where the owner's app opens the live view, when the daemon has an
527 /// address a phone can reach. The id in it grants nothing alone.
528 #[serde(default, skip_serializing_if = "Option::is_none")]
529 open_url: Option<String>,
530 },
531}
532
533/// Why the owner is asked.
534#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
535#[serde(rename_all = "snake_case", tag = "kind")]
536#[non_exhaustive]
537pub enum AskReason {
538 /// The work read content from outside, and the clean check could not
539 /// confirm this step fits the request.
540 ReadOutsideContent {
541 /// The check's one sentence, addressed to the owner.
542 #[serde(default, skip_serializing_if = "Option::is_none")]
543 check_says: Option<String>,
544 },
545 /// The owner said no to a step earlier in this run, and what this call
546 /// does cannot be fully told, so it is not run unasked.
547 AfterADecline {
548 /// What the owner said no to, in a few plain words (the declined
549 /// step's own title, or what it would have changed).
550 #[serde(default, skip_serializing_if = "Option::is_none")]
551 declined: Option<String>,
552 },
553}
554
555/// An effect that deserves a warning on the card.
556#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
557#[serde(rename_all = "snake_case", tag = "kind")]
558#[non_exhaustive]
559pub enum HighImpact {
560 /// Deletes files: the targets when they can be read.
561 Deletes {
562 #[serde(default, skip_serializing_if = "Vec::is_empty")]
563 targets: Vec<String>,
564 },
565 /// Sends or posts something to another service.
566 Sends,
567 /// Spends money.
568 Spends,
569 /// Writes outside the work area.
570 WritesOutsideWorkArea,
571}
572
573/// Who an interruption is waiting for.
574#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
575#[serde(rename_all = "snake_case")]
576#[non_exhaustive]
577pub enum InterruptKind {
578 /// A check of a call made after the run read untrusted content (and,
579 /// for interruptions saved before kinds existed, any interruption).
580 #[default]
581 Untrusted,
582 /// The owner must approve the call.
583 OwnerApproval(OwnerApprovalRequest),
584}
585
586/// Owner declines shared by a family of runs: a run and the child runs it
587/// starts (and their children). A decline recorded in any of them reaches
588/// every other one before its next call, so a parent is refused an effect
589/// the owner declined inside its child, and a running child is refused one
590/// the owner declined in its parent after the child started.
591///
592/// Attach it with [`crate::RunState::share_declines`]. The kernel exchanges
593/// it with the run's own [`crate::RunState::declined`] when a turn starts,
594/// before each call is judged, when the owner declines, and when the run
595/// ends; the run's own list stays the serialized source of truth (so a
596/// parent whose child was declined something never ends `Succeeded`). The
597/// handle itself is not serialized: a run resumed from saved state keeps
598/// its own declines and shares them again once the application reattaches
599/// a set.
600///
601/// It only grows. Clones share one set.
602#[derive(Clone, Default)]
603pub struct SharedDeclines(std::sync::Arc<std::sync::Mutex<Vec<EffectKey>>>);
604
605impl SharedDeclines {
606 pub fn new() -> Self {
607 Self::default()
608 }
609
610 fn lock(&self) -> std::sync::MutexGuard<'_, Vec<EffectKey>> {
611 self.0.lock().unwrap_or_else(|e| e.into_inner())
612 }
613
614 /// Add effects (duplicates are ignored).
615 pub fn record(&self, effects: &[EffectKey]) {
616 let mut shared = self.lock();
617 for effect in effects {
618 if !shared.contains(effect) {
619 shared.push(effect.clone());
620 }
621 }
622 }
623
624 /// Every effect declined so far, in the order first recorded.
625 pub fn snapshot(&self) -> Vec<EffectKey> {
626 self.lock().clone()
627 }
628
629 /// Publish `local`'s effects and take in the others'. Returns whether
630 /// `local` grew.
631 pub(crate) fn exchange(&self, local: &mut Vec<EffectKey>) -> bool {
632 let mut shared = self.lock();
633 for effect in local.iter() {
634 if !shared.contains(effect) {
635 shared.push(effect.clone());
636 }
637 }
638 let before = local.len();
639 for effect in shared.iter() {
640 if !local.contains(effect) {
641 local.push(effect.clone());
642 }
643 }
644 local.len() > before
645 }
646
647 /// Both handles share one set.
648 pub fn same_set(&self, other: &SharedDeclines) -> bool {
649 std::sync::Arc::ptr_eq(&self.0, &other.0)
650 }
651}
652
653/// Two handles are equal when they share one set.
654impl PartialEq for SharedDeclines {
655 fn eq(&self, other: &Self) -> bool {
656 self.same_set(other)
657 }
658}
659
660impl std::fmt::Debug for SharedDeclines {
661 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
662 f.debug_tuple("SharedDeclines")
663 .field(&self.snapshot())
664 .finish()
665 }
666}