Skip to main content

onetaskgraph_plugin_api/
source.rs

1//! The two traits a plugin implements, and the secret lookup it is handed.
2
3use std::cmp::Ordering;
4use std::collections::BTreeMap;
5
6use schemars::{JsonSchema, Schema};
7use secrecy::SecretString;
8use serde::{Deserialize, Serialize};
9use serde_json::Value;
10
11use crate::{
12    Asset, AssetName, AssetWrite, AssetsWritten, Capabilities, Comment, CommentBody, CommentCopy,
13    DependencyEdge, Direction, Document, DocumentQuery, DocumentVersionCoverage, IssueHolding,
14    IssueRef, ItemKind, ItemWrite, Label, MetadataKey, MetadataRecord, Metering, NativeId,
15    NewComment, Page, PageRequest, Priority, Project, ProjectQuery, ProjectVersionCoverage,
16    SharedClock, SourceError, SourceName, Status, StatusCategory, StatusContradiction, Task,
17    TaskDetailRead, TaskQuery, TaskRef, TaskUpdate, TaskUpdateOutcome, VersionCoverage, Visibility,
18    WriteJournal, WriteSupport, WriteTarget, assetless, commentless, documentless, unwritable,
19    unwritable_field, unwritable_metadata,
20};
21
22/// Whether a source is answering right now.
23///
24/// # Placement is an open contract question
25///
26/// This type lives here because [`TaskSource::health`] returns it and the trait
27/// lives here: placing it in `onetaskgraph-core` would make this crate depend on
28/// the engine and invert the one direction the crate split exists to establish.
29/// The approved contract enumerates this crate's contents exhaustively and does
30/// not name `Health`, so the enumeration and the trait as written cannot both
31/// stand. Compiling forces the placement below; the resolution — add it to the
32/// enumeration, or redesign `health` so no such type crosses the boundary —
33/// belongs to the contract's owner, not to this crate. See `AGENTS.md`.
34#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
35// llmlint: ignore[invalid_states_unrepresentable] SECOND PERMITTED REASON — this restates at a new site the justification already recorded at `Capabilities.max_page_size` (capability.rs) and `PageRequest.limit` (query.rs), and a third time in this type's own doc comment above and in AGENTS.md's "Open contract question — `Health`": `Health`'s shape is approved contract text that `TaskSource::health` returns, so an enum here would change the serialized form and the trait six undispatched nodes implement. That is the contract owner's call, not this crate's.
36pub struct Health {
37    /// Whether the source answered.
38    ///
39    /// A bare `bool` beside an untyped `detail` cannot say that an unreachable source
40    /// must explain itself, or keep "reachable with a warning" apart from "reachable";
41    /// an enum carrying the detail in its unreachable variant would.
42    // llmlint: ignore[invalid_states_unrepresentable] SECOND PERMITTED REASON — this
43    // restates at this field the justification already recorded at
44    // `Capabilities.max_page_size` (capability.rs), `PageRequest.limit` (query.rs), this
45    // type's own doc comment above, and AGENTS.md's "Open contract question — `Health`":
46    // `Health`'s shape is approved contract text that `TaskSource::health` returns, so an
47    // enum here would change the serialized form and the trait six undispatched nodes
48    // implement. That is the contract owner's call, not this crate's.
49    // llmlint: ignore[boundary_inputs_validated] making "unreachable with no reason given" unrepresentable means an enum here, which changes the serialized form and the trait six undispatched nodes implement. Deferred to the contract's owner — AGENTS.md, "Open contract question — `Health`".
50    pub reachable: bool,
51    /// What the source said, when it said anything useful.
52    pub detail: Option<String>,
53}
54
55/// The task query whose [`TaskQuery::origin_matches`] is the one statement of what "copied
56/// from `origin`" means, so the by-origin defaults read a project's and a document's entry
57/// exactly as a task's is read.
58fn origin_query(origin: &str) -> TaskQuery {
59    TaskQuery {
60        origin: Some(origin.to_owned()),
61        ..TaskQuery::default()
62    }
63}
64
65/// Refuse a page of the listing a by-origin default walks that holds more rows than it was
66/// asked for, in the words the engine refuses one in: a source may return fewer and never
67/// more, and a default that narrowed such a page would hide the defect behind it.
68fn overran(returned: usize, asked_for: u32) -> Result<(), SourceError> {
69    if returned as u64 <= u64::from(asked_for) {
70        return Ok(());
71    }
72    Err(SourceError::Malformed {
73        message: format!(
74            "the source returned {returned} rows for a page of at most {asked_for}; a source \
75             may return fewer than it was asked for and never more"
76        ),
77    })
78}
79
80/// What a by-origin default answers when the listing it walks hands back a cursor it has
81/// already handed out, which would walk forever.
82fn repeated_cursor() -> SourceError {
83    SourceError::Malformed {
84        message: "the source returned a cursor it had already handed out while its listing \
85                  was walked for one origin, so the walk would never end"
86            .to_owned(),
87    }
88}
89
90/// The page `page` asks for of `matched`, every item a by-origin default kept: the cursor
91/// it hands out is the position of the next match, so a walk of its pages neither repeats
92/// nor drops one while the listing under it holds still.
93fn page_of_matches<T>(matched: Vec<T>, page: &PageRequest) -> Result<Page<T>, SourceError> {
94    let start = match &page.cursor {
95        None => 0,
96        Some(cursor) => cursor
97            .0
98            .strip_prefix(MATCHED_PAGE_CURSOR)
99            .and_then(|position| position.parse::<usize>().ok())
100            .filter(|position| *position <= matched.len())
101            .ok_or_else(|| SourceError::Refused {
102                message: format!(
103                    "cursor {:?} was not handed out by this by-origin listing; start the walk \
104                     again without one",
105                    cursor.0
106                ),
107            })?,
108    };
109    let end = start.saturating_add(page.limit as usize).min(matched.len());
110    let next = (end < matched.len()).then(|| crate::Cursor(format!("{MATCHED_PAGE_CURSOR}{end}")));
111    Ok(Page {
112        items: matched.into_iter().skip(start).take(end - start).collect(),
113        next,
114    })
115}
116
117const MATCHED_PAGE_CURSOR: &str = "origin:";
118
119/// One configured source, as the engine drives it.
120///
121/// Dyn-compatible through `async_trait` because the engine holds
122/// `Vec<Box<dyn TaskSource>>` over heterogeneous plugins.
123///
124/// Three rules bind every implementation, and the engine's compensation is only
125/// correct while all three hold:
126///
127/// 1. **Apply** every predicate you declare [`Support::Native`](crate::Support::Native).
128/// 2. **Ignore** every [`Support`](crate::Support)-typed predicate you declare
129///    `Unsupported` — return the *wider* result set, never a narrower one.
130///    Silently dropping rows for a predicate you did not declare is the one
131///    failure no test above the plugin can catch.
132/// 3. Never return a silently empty dependency read. Rule 2 reaches the
133///    `Support`-typed *predicates* alone; a dependency read is always real, and so is a
134///    document read — [`Capabilities::documents`] says whether this source has documents
135///    at all, and a source that says it has none is never asked for one rather than
136///    answering an empty page.
137#[async_trait::async_trait]
138pub trait TaskSource: Send + Sync {
139    /// The plugin kind that built this source, for display and for plan output.
140    fn kind(&self) -> &'static str;
141
142    /// What this source applies itself. Read once per query by the engine.
143    fn capabilities(&self) -> Capabilities;
144
145    /// How `a`, a [`Task::version`] this source gave one of its tasks, stands to `b`, another
146    /// it gave the same task: `Greater` when `a` is the later, `Less` when it is the earlier,
147    /// `Equal` when nothing the token covers changed between them, and `None` when the two
148    /// cannot be put in order — a value this source cannot read, or two versions its token
149    /// says differ without saying which came first.
150    ///
151    /// A token's format and its order are the one source's that spells it, so the engine asks
152    /// the source that gave both rather than reading inside either.
153    ///
154    /// Defaulted to equality alone: two identical tokens are one version, and any two others
155    /// are unordered, which a reader takes as *changed, read it again* and never as
156    /// unchanged. A source whose token says which of two versions is the later overrides it.
157    fn order_versions(&self, a: &str, b: &str) -> Option<Ordering> {
158        (a == b).then_some(Ordering::Equal)
159    }
160
161    /// Which parts of a task this source's [`Task::version`] vouches for, which is what the
162    /// store's local cache may serve a task's parts from.
163    ///
164    /// Defaulted to no part, which keeps the cache from ever serving what a token was never
165    /// promised to cover: a source overrides it only for the parts its token covers, as
166    /// `docs/plugin-protocol.md` §4.13d states them.
167    fn version_coverage(&self) -> VersionCoverage {
168        VersionCoverage::none(format!(
169            "the {} plugin does not declare that its change token covers a task",
170            self.kind()
171        ))
172    }
173
174    /// Which parts of a task a copy may take this source's unchanged [`Task::version`] as
175    /// vouching for, when it decides to skip a task its destination already holds as written:
176    /// the task's fields, its comments when the copy carries them, and its forward edges. A copy
177    /// skips only a task whose source covers every one of those it writes.
178    ///
179    /// Defaulted to [`version_coverage`](Self::version_coverage). A source overrides it only to
180    /// state, with its measured bound, a claim about a copy's skip that is not one the cache may
181    /// serve from — as `docs/plugin-protocol.md` §4.13d does for the one plugin that does.
182    fn copy_version_coverage(&self) -> VersionCoverage {
183        self.version_coverage()
184    }
185
186    /// Which parts of a project this source's [`Project::version`] vouches for, on the terms
187    /// of [`version_coverage`](Self::version_coverage).
188    ///
189    /// Defaulted to no part, for the same reason.
190    fn project_version_coverage(&self) -> ProjectVersionCoverage {
191        ProjectVersionCoverage::none(format!(
192            "the {} plugin does not declare that its change token covers a project",
193            self.kind()
194        ))
195    }
196
197    /// Which parts of a document this source's [`Document::version`] vouches for, on the terms
198    /// of [`version_coverage`](Self::version_coverage).
199    ///
200    /// Defaulted to no part, for the same reason.
201    fn document_version_coverage(&self) -> DocumentVersionCoverage {
202        DocumentVersionCoverage::none(format!(
203            "the {} plugin does not declare that its change token covers a document",
204            self.kind()
205        ))
206    }
207
208    /// Tell this source the store's local cache now stands in front of it.
209    ///
210    /// Called exactly once, by the cache as it wraps the source, before any read and before
211    /// any coverage is read — so a source whose token needs a part only a wider selection
212    /// carries can widen its reads here, and declare the coverage that widening buys. Never
213    /// carried over the plugin protocol, as [`version_coverage`](Self::version_coverage) is
214    /// not.
215    ///
216    /// Defaulted to doing nothing: a source not overriding it reads exactly as it did.
217    fn attach_cache(&self) {}
218
219    /// The change token the response that answered this source's last
220    /// [`Direction::DependsOn`] read of task `id` in this process spelled, or `None` when it
221    /// spelled none.
222    ///
223    /// What lets the store's cache keep a task's forward edges by the version they were read
224    /// at when nothing else in the command read the task: those edges are served only to a pin
225    /// that version is at or after, and never vouch for the task's own fields. Synchronous, and
226    /// never carried over the plugin protocol, as [`version_coverage`](Self::version_coverage)
227    /// is not.
228    ///
229    /// Defaulted to `None`: a source whose dependency read spells no token keeps its edges
230    /// remote unless a read of the task itself vouched for them.
231    fn forward_edges_version(&self, id: &NativeId) -> Option<String> {
232        let _ = id;
233        None
234    }
235
236    /// The change token the response that answered this source's last dependency read of the
237    /// `kind` item `id` in `direction`, from its first page, spelled — or `None` when it spelled
238    /// none — on the terms of [`forward_edges_version`](Self::forward_edges_version), which is
239    /// what it answers for a task's [`Direction::DependsOn`].
240    ///
241    /// What lets the store's cache keep a project's forward edges, and either kind's reverse
242    /// ones, by the version they were read at: a project's forward edges are served only where
243    /// [`project_version_coverage`](Self::project_version_coverage) covers them, reverse ones only
244    /// where [`reverse_edges_coverage`](Self::reverse_edges_coverage) covers that kind's, and each
245    /// only to a pin that version is at or after. Synchronous, and never
246    /// carried over the plugin protocol.
247    ///
248    /// Defaulted to [`forward_edges_version`](Self::forward_edges_version) for a task's forward
249    /// edges and to `None` for every other read, which keeps those remote.
250    fn edges_version(&self, kind: ItemKind, id: &NativeId, direction: Direction) -> Option<String> {
251        match (kind, direction) {
252            (ItemKind::Task, Direction::DependsOn) => self.forward_edges_version(id),
253            _ => None,
254        }
255    }
256
257    /// Whether this source's token for a `kind` item — [`Task::version`] or
258    /// [`Project::version`] — vouches for its reverse edges, what a [`Direction::DependedOnBy`]
259    /// read answers, so the store's cache may serve them.
260    ///
261    /// A reverse edge is recorded on another item, so a token vouches for one only where it
262    /// carries a part that moves whenever one is added to or removed from that other item —
263    /// which no part of an item's own fields does. Never carried over the plugin protocol.
264    ///
265    /// Defaulted to not covering them, with that reason.
266    fn reverse_edges_coverage(&self, kind: ItemKind) -> crate::Coverage {
267        crate::Coverage::Uncovered {
268            reason: format!(
269                "the {} plugin does not declare that its change token covers a {}'s reverse \
270                 edges, which are recorded on the items that depend on it",
271                self.kind(),
272                match kind {
273                    ItemKind::Task => "task",
274                    ItemKind::Project => "project",
275                }
276            ),
277        }
278    }
279
280    /// What this source holds about task `id` — the item it read last in this process — that
281    /// a later write expecting that version of it could take instead of reading it again, or
282    /// `None` when it holds nothing of the kind.
283    ///
284    /// Opaque to the engine, which keeps it beside the cached task and hands it back through
285    /// [`prime_write`](Self::prime_write). Defaulted to `None`: a source whose writes read
286    /// nothing first has nothing to keep.
287    fn write_context(&self, id: &NativeId) -> Option<serde_json::Value> {
288        let _ = id;
289        None
290    }
291
292    /// What this source holds about the container every task of it shares — a board's field
293    /// and option ids — that a write could take instead of reading it, or `None`.
294    ///
295    /// Defaulted to `None`, on the terms of [`write_context`](Self::write_context).
296    fn board_context(&self) -> Option<serde_json::Value> {
297        None
298    }
299
300    /// Hold `context`, which [`write_context`](Self::write_context) gave for task `id` at a
301    /// version the caller expects it still at, and `board`, which
302    /// [`board_context`](Self::board_context) gave, so the next write of `id` takes them
303    /// instead of reading — answering whether it took them.
304    ///
305    /// A context this source cannot read is not taken, and the write then reads as it always
306    /// does. Defaulted to taking nothing.
307    fn prime_write(
308        &self,
309        id: &NativeId,
310        context: &serde_json::Value,
311        board: Option<&serde_json::Value>,
312    ) -> bool {
313        let _ = (id, context, board);
314        false
315    }
316
317    /// Drop whatever [`prime_write`](Self::prime_write) took for `id`, and the board context
318    /// with it, so the next write of it reads afresh.
319    fn unprime(&self, id: &NativeId) {
320        let _ = id;
321    }
322
323    /// Start recording every request this source sends, for [`end_journal`](Self::end_journal).
324    ///
325    /// The engine opens one journal around one write at a time. Defaulted to recording
326    /// nothing.
327    fn begin_journal(&self) {}
328
329    /// Stop recording, answering with every request sent since
330    /// [`begin_journal`](Self::begin_journal) — or `None` for a source that records none.
331    fn end_journal(&self) -> Option<WriteJournal> {
332        None
333    }
334
335    /// Whether the source is answering right now.
336    ///
337    /// # Errors
338    ///
339    /// Returns a [`SourceError`] when the check itself could not be made.
340    async fn health(&self) -> Result<Health, SourceError>;
341
342    /// Fetch one task by its native id, or `None` when there is no such task.
343    ///
344    /// # Errors
345    ///
346    /// Returns a [`SourceError`] when the source could not answer.
347    async fn get_task(&self, id: &NativeId) -> Result<Option<Task>, SourceError>;
348
349    /// Fetch several tasks by their native ids, each with the first page of its comments
350    /// when `comments` names the page to read — one answer per id, in the order they were
351    /// given.
352    ///
353    /// Each answer is what [`get_task`](Self::get_task) answers for that id, so a task that
354    /// is not there is `Ok(None)` and a read that failed fails that id alone. Its
355    /// [`TaskDetailRead::comments`] is what [`task_comments`](Self::task_comments) answers
356    /// for `comments`. The engine passes `comments` only to a source declaring
357    /// [`Capabilities::comments`](crate::Capabilities::comments) native.
358    ///
359    /// Defaulted to exactly those calls, item by item, so a source that implements nothing
360    /// here answers as it always did. A source that can read many items — or an item and its
361    /// comments — in fewer requests than that overrides it, which is the whole reason it
362    /// exists: a caller holding twenty ids pays for one batch rather than forty reads.
363    async fn get_task_details(
364        &self,
365        ids: &[NativeId],
366        comments: Option<&PageRequest>,
367    ) -> Vec<Result<Option<TaskDetailRead>, SourceError>> {
368        let mut read = Vec::with_capacity(ids.len());
369        for id in ids {
370            read.push(match self.get_task(id).await {
371                Ok(Some(task)) => {
372                    let comments = match comments {
373                        Some(page) => Some(self.task_comments(id, page).await),
374                        None => None,
375                    };
376                    Ok(Some(TaskDetailRead { task, comments }))
377                }
378                Ok(None) => Ok(None),
379                Err(error) => Err(error),
380            });
381        }
382        read
383    }
384
385    /// Fetch one project by its native id, or `None` when there is no such project.
386    ///
387    /// # Errors
388    ///
389    /// Returns a [`SourceError`] when the source could not answer.
390    async fn get_project(&self, id: &NativeId) -> Result<Option<Project>, SourceError>;
391
392    /// One page of the tasks matching `query`.
393    ///
394    /// # Errors
395    ///
396    /// Returns a [`SourceError`] when the source could not answer.
397    async fn query_tasks(
398        &self,
399        query: &TaskQuery,
400        page: &PageRequest,
401    ) -> Result<Page<Task>, SourceError>;
402
403    /// One page of the projects matching `query`.
404    ///
405    /// # Errors
406    ///
407    /// Returns a [`SourceError`] when the source could not answer.
408    async fn query_projects(
409        &self,
410        query: &ProjectQuery,
411        page: &PageRequest,
412    ) -> Result<Page<Project>, SourceError>;
413
414    /// One page of the projects whose [`TaskQuery::ORIGIN_KEY`] entry is a string equal to
415    /// `origin`, exactly — the projects copied from that qualified id, and none other.
416    ///
417    /// `origin` is compared byte for byte, on the terms [`TaskQuery::origin`] states, and is
418    /// never constructed or interpreted here. Zero, one or several projects may match; which
419    /// of several a caller wants is the caller's question.
420    ///
421    /// Defaulted to [`query_projects`](Self::query_projects) unfiltered, walked to its end on
422    /// every call and narrowed here, so a source that implements nothing answers exactly what
423    /// its own listing holds; the default's cursor is a position among the matches. A source
424    /// that can ask its store for one origin overrides it, which is the whole reason it
425    /// exists: a caller looking for the copies of one plan pays for those copies rather than
426    /// for every project the store holds.
427    ///
428    /// # Errors
429    ///
430    /// Returns a [`SourceError`] when the source could not answer, and
431    /// [`SourceError::Refused`] for a cursor the default did not hand out.
432    async fn query_projects_by_origin(
433        &self,
434        origin: &str,
435        page: &PageRequest,
436    ) -> Result<Page<Project>, SourceError> {
437        let wanted = origin_query(origin);
438        let mut matched = Vec::new();
439        let mut cursor: Option<crate::Cursor> = None;
440        // Every cursor the listing handed out, so one cycling through several is caught as
441        // one repeating the last is.
442        let mut visited: Vec<String> = Vec::new();
443        loop {
444            let listed = self
445                .query_projects(
446                    &ProjectQuery::default(),
447                    &PageRequest {
448                        cursor: cursor.clone(),
449                        limit: page.limit,
450                    },
451                )
452                .await?;
453            overran(listed.items.len(), page.limit)?;
454            matched.extend(
455                listed
456                    .items
457                    .into_iter()
458                    .filter(|project| wanted.origin_matches(&project.metadata)),
459            );
460            cursor = match listed.next {
461                None => break,
462                Some(next) if visited.contains(&next.0) => return Err(repeated_cursor()),
463                Some(next) => {
464                    visited.push(next.0.clone());
465                    Some(next)
466                }
467            };
468        }
469        page_of_matches(matched, page)
470    }
471
472    /// One page of every label this source knows.
473    ///
474    /// # Errors
475    ///
476    /// Returns a [`SourceError`] when the source could not answer.
477    async fn labels(&self, page: &PageRequest) -> Result<Page<Label>, SourceError>;
478
479    /// One page of the task dependency edges at `id`, in `direction`.
480    ///
481    /// # Errors
482    ///
483    /// Returns a [`SourceError`] when the source could not answer.
484    async fn task_dependencies(
485        &self,
486        id: &NativeId,
487        direction: Direction,
488        page: &PageRequest,
489    ) -> Result<Page<DependencyEdge>, SourceError>;
490
491    /// One page of the project dependency edges at `id`, in `direction`.
492    ///
493    /// # Errors
494    ///
495    /// Returns a [`SourceError`] when the source could not answer.
496    async fn project_dependencies(
497        &self,
498        id: &NativeId,
499        direction: Direction,
500        page: &PageRequest,
501    ) -> Result<Page<DependencyEdge>, SourceError>;
502
503    /// Whether this source can be written through at all.
504    ///
505    /// Defaulted to [`WriteSupport::Unsupported`], which is what keeps this a read
506    /// interface for every source that has nothing to write into: one that cannot be
507    /// written needs no edit and keeps working. Read before a write is attempted, so a
508    /// copy naming such a source as its destination is refused before anything is read.
509    fn writes(&self) -> WriteSupport {
510        WriteSupport::Unsupported
511    }
512
513    /// Create or update one task, answering with the native id the destination holds it
514    /// under.
515    ///
516    /// A source declaring [`WriteSupport::Supported`] owes three things here. It refuses,
517    /// naming the field, anything it cannot represent rather than dropping it — including
518    /// a metadata key it cannot carry, which it names. It writes every other field it was
519    /// given. And it never creates when [`ItemWrite::target`] names an item it does not
520    /// hold.
521    ///
522    /// # Errors
523    ///
524    /// Returns [`SourceError::Refused`] when this source has no write side, when a field
525    /// or a metadata key cannot be represented, or when `target` names nothing here; and
526    /// whatever else the source could not do the write for.
527    async fn write_task(&self, write: &ItemWrite<Task>) -> Result<NativeId, SourceError> {
528        let _ = write;
529        Err(unwritable(self.kind()))
530    }
531
532    /// Create or update one project, on exactly the terms of
533    /// [`write_task`](Self::write_task).
534    ///
535    /// # Errors
536    ///
537    /// As [`write_task`](Self::write_task).
538    async fn write_project(&self, write: &ItemWrite<Project>) -> Result<NativeId, SourceError> {
539        let _ = write;
540        Err(unwritable(self.kind()))
541    }
542
543    /// Whether this source can represent every field of `write` — its status, its content, the
544    /// tasks it delivers and every other field a [`write_task`](Self::write_task) of it would
545    /// refuse as "cannot represent the field …" — asked before anything is written and changing
546    /// nothing.
547    ///
548    /// A task copy asks it of every task it plans before its first write, and leaves out each
549    /// task this refuses — answered `failed`, with this refusal as its reason — writing the rest
550    /// as one copy. It answers what the write itself would refuse in the same words; and it is a
551    /// promise only about representability, so a write may still fail for any other reason.
552    ///
553    /// Defaulted to `Ok(())`: a source that does not answer it in advance still refuses such a
554    /// write in its write, which a copy then takes back whole, exactly as before.
555    ///
556    /// # Errors
557    ///
558    /// Returns [`SourceError::Refused`] naming the field this source cannot represent; and
559    /// whatever else kept it from finding out.
560    async fn check_task_write(&self, write: &ItemWrite<Task>) -> Result<(), SourceError> {
561        let _ = write;
562        Ok(())
563    }
564
565    /// Whether a write of an item of `kind` at `category` — over the item `target` names, or
566    /// creating one when it is `None` — would have a status to write, asked before the write
567    /// and changing nothing.
568    ///
569    /// A caller that has to put an item back when a later write of it fails — a copy, whose
570    /// journal records what an item held before overwriting it — asks this first, so a status
571    /// this source has no name for is refused while nothing has been recorded or written, and
572    /// nothing has to be put back. It answers what the write itself would refuse a status
573    /// with, in the same words, and sends no request a write of that status would not have
574    /// sent anyway: what it reads to answer, it holds for the write that follows.
575    ///
576    /// Defaulted to `Ok(())`: a source that does not answer it in advance still refuses the
577    /// status in its write, exactly as before.
578    ///
579    /// # Errors
580    ///
581    /// Returns [`SourceError::Refused`] naming the kind, the category and what is missing
582    /// when this source has no name for that status; and whatever else kept it from finding
583    /// out.
584    async fn check_status_write(
585        &self,
586        kind: ItemKind,
587        category: StatusCategory,
588        target: Option<&NativeId>,
589    ) -> Result<(), SourceError> {
590        let _ = (kind, category, target);
591        Ok(())
592    }
593
594    /// Set the status of one task this source holds, and change nothing else about it,
595    /// answering with the status as this source now reads it — or `None` when this source
596    /// holds no such task.
597    ///
598    /// The category lands where this source's own mapping sends it, exactly as a
599    /// [`write_task`](Self::write_task) of a task in that category would: a category this
600    /// source has disabled is refused in the words a write of it is refused with. Title,
601    /// content, labels, metadata, dependencies, [`Task::delivers`], [`Task::delivered_by`],
602    /// project and comments are left exactly as they are.
603    ///
604    /// Defaulted to [`unwritable_field`], which is what keeps this an addition rather than a
605    /// break: a source that cannot write a status on its own needs no edit and refuses by
606    /// saying so. A source declaring [`WriteSupport::Unsupported`] is never asked.
607    ///
608    /// [`Task::delivers`]: crate::Task::delivers
609    /// [`Task::delivered_by`]: crate::Task::delivered_by
610    ///
611    /// # Errors
612    ///
613    /// Returns [`SourceError::Refused`] when this source cannot write a status, or cannot
614    /// write this one; and whatever else the source could not do the write for.
615    async fn set_task_status(
616        &self,
617        id: &NativeId,
618        category: StatusCategory,
619    ) -> Result<Option<Status>, SourceError> {
620        let _ = (id, category);
621        Err(unwritable_field(self.kind(), "status"))
622    }
623
624    /// Set the status of one project this source holds, and change nothing else about it,
625    /// answering with the status as this source now reads it — or `None` when this source
626    /// holds no such project.
627    ///
628    /// The category lands where this source's own mapping sends it for a project, exactly as a
629    /// [`write_project`](Self::write_project) of a project in that category would: a category
630    /// this source has disabled is refused in the words a write of it is refused with. Title,
631    /// content, labels, metadata, repositories, dependencies and the project's tasks are left
632    /// exactly as they are. A project delivers no task, so nothing is kept in step after it.
633    ///
634    /// Defaulted to the refusal [`set_task_status`](Self::set_task_status) defaults to,
635    /// [`unwritable_field`] naming `status`, which is what keeps this an addition rather than a
636    /// break: a source that does not implement it needs no edit. A source declaring
637    /// [`WriteSupport::Unsupported`] is never asked.
638    ///
639    /// # Errors
640    ///
641    /// Returns [`SourceError::Refused`] when this source cannot write a project's status, or
642    /// cannot write this one; and whatever else the source could not do the write for.
643    async fn set_project_status(
644        &self,
645        id: &NativeId,
646        category: StatusCategory,
647    ) -> Result<Option<Status>, SourceError> {
648        let _ = (id, category);
649        Err(unwritable_field(self.kind(), "status"))
650    }
651
652    /// Set the status of one task this source holds, as [`set_task_status`](Self::set_task_status)
653    /// does, and answer with the whole task as this source now reads it — its
654    /// [`Task::delivers`] among what a caller keeping delivered tasks in step needs — or `None`
655    /// when this source holds no such task.
656    ///
657    /// Defaulted to exactly the two calls a caller would otherwise make: [`get_task`] first,
658    /// answering `None` with nothing written when it does, then `set_task_status`, the status
659    /// it answers put on the task read. A source whose status write answers the whole task in
660    /// the same round trip overrides it to save the read.
661    ///
662    /// [`Task::delivers`]: crate::Task::delivers
663    /// [`get_task`]: Self::get_task
664    ///
665    /// # Errors
666    ///
667    /// As [`get_task`](Self::get_task) and [`set_task_status`](Self::set_task_status).
668    async fn set_task_status_reading(
669        &self,
670        id: &NativeId,
671        category: StatusCategory,
672    ) -> Result<Option<Task>, SourceError> {
673        let Some(mut task) = self.get_task(id).await? else {
674            return Ok(None);
675        };
676        let Some(status) = self.set_task_status(id, category).await? else {
677            return Ok(None);
678        };
679        task.status = status;
680        Ok(Some(task))
681    }
682
683    /// Every task this source holds whose card contradicts its issue's closure, each with the
684    /// status that brings it in line — what `task status reconcile` writes, through
685    /// [`set_task_status`](Self::set_task_status), one task at a time.
686    ///
687    /// A task needs it when its issue is closed with a reason that reads `done` or
688    /// `cancelled` and its card does not sit at the option this source's mapping gives that
689    /// category. An open task, a closure that reads `unknown` and a card already in line are
690    /// never answered. Changes nothing.
691    ///
692    /// Asked only of a source declaring
693    /// [`Capabilities::reconcile_status`](crate::Capabilities::reconcile_status); defaulted to a
694    /// refusal saying so, which no caller holding to that declaration ever receives.
695    ///
696    /// # Errors
697    ///
698    /// Returns [`SourceError::Refused`] when this source answers no such question; and whatever
699    /// kept it from reading its items.
700    async fn status_contradictions(&self) -> Result<Vec<StatusContradiction>, SourceError> {
701        Err(SourceError::Refused {
702            message: format!(
703                "a {} source's status is its closure, so nothing needs reconciling",
704                self.kind()
705            ),
706        })
707    }
708
709    /// For each issue in `issues`, in order and once each, the task this source holds for it
710    /// and what moving it to `done` comes to — what `task status complete` writes, through
711    /// [`set_task_status`](Self::set_task_status), for each one answered
712    /// [`Completion::Due`](crate::Completion::Due).
713    ///
714    /// The read is proportional to `issues` and never to the size of what this source holds,
715    /// and an empty `issues` reads nothing. Changes nothing.
716    ///
717    /// Asked only of a source declaring
718    /// [`Capabilities::complete_by_issue`](crate::Capabilities::complete_by_issue); defaulted
719    /// to a refusal saying so, which no caller holding to that declaration ever receives.
720    ///
721    /// # Errors
722    ///
723    /// Returns [`SourceError::Refused`] when this source answers no such question; and whatever
724    /// kept it from reading the issues.
725    async fn issue_holdings(&self, issues: &[IssueRef]) -> Result<Vec<IssueHolding>, SourceError> {
726        let _ = issues;
727        Err(SourceError::Refused {
728            message: format!("a {} source holds no items by issue reference", self.kind()),
729        })
730    }
731
732    /// Set the priority of one task this source holds, and change nothing else about it,
733    /// answering with the priority as this source now reads it — or `None` when this source
734    /// holds no such task.
735    ///
736    /// [`Priority::None`] clears the priority. Title, content, status, labels, metadata,
737    /// repositories, dependencies and comments are left exactly as they are. Nothing about
738    /// the task's status moves, so the engine re-evaluates no delivered task after it.
739    ///
740    /// Defaulted to [`unwritable_field`], which is what keeps this an addition rather than a
741    /// break. A source declaring [`WriteSupport::Unsupported`], or declaring
742    /// [`Capabilities::priority`] unsupported, is never asked.
743    ///
744    /// # Errors
745    ///
746    /// Returns [`SourceError::Refused`] when this source cannot write a priority, or cannot
747    /// write this one — a board with no option for it, naming the option; and whatever else
748    /// the source could not do the write for.
749    async fn set_task_priority(
750        &self,
751        id: &NativeId,
752        priority: Priority,
753    ) -> Result<Option<Priority>, SourceError> {
754        let _ = (id, priority);
755        Err(unwritable_field(self.kind(), "priority"))
756    }
757
758    /// Replace the content of one task this source holds with `content`, byte for byte, and
759    /// change nothing else about it — or answer `None` when this source holds no such task.
760    ///
761    /// The content is [`Task::content`] exactly as this source reports it: what a later read
762    /// answers there is `content`. Where the source keeps something else inside the same
763    /// backend field — a metadata block in an issue body — that is kept as it was, and so is
764    /// every other member: title, status, priority, labels, metadata, repositories,
765    /// dependencies, project and comments. Nothing about the task's status moves, so the
766    /// engine re-evaluates no delivered task after it.
767    ///
768    /// Defaulted to [`unwritable_field`] on exactly the terms of
769    /// [`set_task_status`](Self::set_task_status). A source declaring
770    /// [`WriteSupport::Unsupported`] is never asked.
771    ///
772    /// # Errors
773    ///
774    /// Returns [`SourceError::Refused`] when this source cannot write a task's content on its
775    /// own, or cannot represent this one; and whatever else the source could not do the write
776    /// for.
777    async fn set_task_content(
778        &self,
779        id: &NativeId,
780        content: &str,
781    ) -> Result<Option<()>, SourceError> {
782        let _ = (id, content);
783        Err(unwritable_field(self.kind(), "content"))
784    }
785
786    /// Replace the [`Task::delivered_by`] of one task this source holds, and change nothing
787    /// else about it — or answer `None` when this source holds no such task.
788    ///
789    /// Every entry is a qualified id, and the list is the whole of it: what the task held
790    /// there before is replaced, not merged. It is the store's to keep in step — the engine
791    /// calls this whenever it writes a task's [`Task::delivers`] — and nothing a person types
792    /// reaches it directly.
793    ///
794    /// Defaulted to [`unwritable_field`] on exactly the terms of
795    /// [`set_task_status`](Self::set_task_status).
796    ///
797    /// [`Task::delivers`]: crate::Task::delivers
798    /// [`Task::delivered_by`]: crate::Task::delivered_by
799    ///
800    /// # Errors
801    ///
802    /// Returns [`SourceError::Refused`] when this source cannot hold the list, and whatever
803    /// else it could not do the write for.
804    async fn set_delivered_by(
805        &self,
806        id: &NativeId,
807        delivered_by: &[TaskRef],
808    ) -> Result<Option<()>, SourceError> {
809        let _ = (id, delivered_by);
810        Err(unwritable_field(self.kind(), "delivered_by"))
811    }
812
813    /// Set one key of the metadata of one task this source holds, and change nothing else
814    /// about it, answering with the task as this source reads it back after the write — or
815    /// `None` when this source holds no such task.
816    ///
817    /// The key is added when the task does not hold it and replaced when it does; every other
818    /// metadata key, and every other field of the task, is left exactly as it was. A `value`
819    /// the task already holds under `key` is a write that changes nothing, and a source owes
820    /// it no write at all. The answer is a read, not an echo: what the engine reports as the
821    /// value is what the returned task holds under `key`.
822    ///
823    /// Nothing about the task's status or its [`Task::delivers`] moves, so the engine
824    /// re-evaluates no delivered task after this write.
825    ///
826    /// Defaulted to [`unwritable_metadata`] on exactly the terms of
827    /// [`set_task_status`](Self::set_task_status): a source that cannot write one key on its
828    /// own needs no edit and refuses by saying so. A source declaring
829    /// [`WriteSupport::Unsupported`] is never asked.
830    ///
831    /// [`Task::delivers`]: crate::Task::delivers
832    ///
833    /// # Errors
834    ///
835    /// Returns [`SourceError::Refused`] when this source cannot write one key of a task's
836    /// metadata on its own, or cannot write this one without changing something else; and
837    /// whatever else the source could not do the write for.
838    async fn set_task_metadata(
839        &self,
840        id: &NativeId,
841        key: &MetadataKey,
842        value: &Value,
843    ) -> Result<Option<Task>, SourceError> {
844        let _ = (id, key, value);
845        Err(unwritable_metadata(self.kind(), MetadataRecord::Task))
846    }
847
848    /// Apply a targeted update to one task this source holds — every field `update` names, and
849    /// nothing else — answering with a [`TaskUpdateOutcome`], or `None` when this source holds
850    /// no such task.
851    ///
852    /// The outcome is everything the engine reports about the call, so it reads nothing of its
853    /// own: the task as this source reads it once the update landed — from the one read it made
854    /// and what it then wrote, where its backend answers a write with what it holds — the
855    /// fields it actually wrote, and the `delivers` the task held before.
856    ///
857    /// A field already holding the requested value is sent no write, and an update in which
858    /// nothing differs sends no write at all. Every field `update` leaves unnamed — labels,
859    /// repositories, project, [`Task::delivered_by`] and comments always among them — is left
860    /// exactly as it is. An update naming one metadata key both to set and to remove is refused
861    /// before anything is written, in the words of [`TaskUpdate::consistent`].
862    ///
863    /// Defaulted to [`TaskUpdate::rewrite`]: read the task, apply the update, and — only when
864    /// anything differs — [`write_task`](Self::write_task) it with its `target` set. That keeps
865    /// this an addition rather than a break, and a source that predates it behaves correctly and
866    /// is merely not minimal; one whose backend can take a field on its own owes an override
867    /// that sends only what differs. A source declaring [`WriteSupport::Unsupported`] is never
868    /// asked.
869    ///
870    /// [`Task::delivered_by`]: crate::Task::delivered_by
871    ///
872    /// # Errors
873    ///
874    /// Returns [`SourceError::Refused`] when the update contradicts itself, when a field it
875    /// names cannot be represented here — a category this source has disabled included — and
876    /// whatever else the source could not do the write for.
877    async fn update_task(
878        &self,
879        id: &NativeId,
880        update: &TaskUpdate,
881    ) -> Result<Option<TaskUpdateOutcome>, SourceError> {
882        update.rewrite(self, id).await
883    }
884
885    /// Set one key of the metadata of one project this source holds, on exactly the terms of
886    /// [`set_task_metadata`](Self::set_task_metadata).
887    ///
888    /// # Errors
889    ///
890    /// As [`set_task_metadata`](Self::set_task_metadata).
891    async fn set_project_metadata(
892        &self,
893        id: &NativeId,
894        key: &MetadataKey,
895        value: &Value,
896    ) -> Result<Option<Project>, SourceError> {
897        let _ = (id, key, value);
898        Err(unwritable_metadata(self.kind(), MetadataRecord::Project))
899    }
900
901    /// Set one key of the metadata of one document this source holds, on exactly the terms of
902    /// [`set_task_metadata`](Self::set_task_metadata).
903    ///
904    /// A source declaring [`Capabilities::documents`] unsupported is never asked, exactly as
905    /// it is never asked for a document read.
906    ///
907    /// # Errors
908    ///
909    /// As [`set_task_metadata`](Self::set_task_metadata).
910    async fn set_document_metadata(
911        &self,
912        id: &NativeId,
913        key: &MetadataKey,
914        value: &Value,
915    ) -> Result<Option<Document>, SourceError> {
916        let _ = (id, key, value);
917        Err(unwritable_metadata(self.kind(), MetadataRecord::Document))
918    }
919
920    /// Remove one task this destination holds, so a copy that could not finish can put
921    /// the destination back the way it found it.
922    ///
923    /// This is not a verb of the product: nothing a user types deletes anything, and a
924    /// copy never deletes an item it did not itself create in the run that is failing.
925    /// It exists because a copy is either complete or it never happened — a half-written
926    /// project has to be run again, and the re-run is the mutation burst that trips a
927    /// hosted destination's rate limiter. Undoing this run's own creates is what removes
928    /// that retry at source.
929    ///
930    /// A source declaring [`WriteSupport::Supported`] owes a real implementation, for the
931    /// reason it owes [`write_task`](Self::write_task) one: the engine will create items
932    /// there, so it has to be able to remove the ones it created. An `id` naming nothing
933    /// is **not** an error — the item is already gone, which is the state this asks for.
934    ///
935    /// # Errors
936    ///
937    /// Returns [`SourceError::Refused`] when this source has no write side, and whatever
938    /// else the source could not remove the item for.
939    async fn delete_task(&self, id: &NativeId) -> Result<(), SourceError> {
940        let _ = id;
941        Err(unwritable(self.kind()))
942    }
943
944    /// Remove one project this destination holds, on exactly the terms of
945    /// [`delete_task`](Self::delete_task).
946    ///
947    /// # Errors
948    ///
949    /// As [`delete_task`](Self::delete_task).
950    async fn delete_project(&self, id: &NativeId) -> Result<(), SourceError> {
951        let _ = id;
952        Err(unwritable(self.kind()))
953    }
954
955    /// Fetch one document by its native id, or `None` when there is no such document.
956    ///
957    /// Defaulted to [`documentless`], which is what keeps documents an addition rather
958    /// than a break: a source with none needs no edit, keeps working, and says so in the
959    /// same words every other document-free source does. A source that has documents
960    /// declares [`Support::Native`](crate::Support::Native) for
961    /// [`Capabilities::documents`] and owes a real implementation here, because that
962    /// declaration is what makes the engine ask.
963    ///
964    /// # Errors
965    ///
966    /// Returns [`SourceError::Refused`] when this source has no documents, and whatever
967    /// else the source could not answer for.
968    async fn get_document(&self, id: &NativeId) -> Result<Option<Document>, SourceError> {
969        let _ = id;
970        Err(documentless(self.kind()))
971    }
972
973    /// One page of the documents matching `query`.
974    ///
975    /// Defaulted on exactly the terms of [`get_document`](Self::get_document). A source
976    /// with no documents refuses rather than answering an empty page: an empty page reads
977    /// as a source that has documents and holds none matching, which is the one wrong
978    /// answer this method can give.
979    ///
980    /// # Errors
981    ///
982    /// As [`get_document`](Self::get_document).
983    async fn query_documents(
984        &self,
985        query: &DocumentQuery,
986        page: &PageRequest,
987    ) -> Result<Page<Document>, SourceError> {
988        let _ = (query, page);
989        Err(documentless(self.kind()))
990    }
991
992    /// One page of the documents whose [`TaskQuery::ORIGIN_KEY`] entry is a string equal to
993    /// `origin`, exactly, on the terms of
994    /// [`query_projects_by_origin`](Self::query_projects_by_origin).
995    ///
996    /// Defaulted to [`query_documents`](Self::query_documents) unfiltered, walked and narrowed
997    /// as that default is — so a source with no documents refuses exactly as its
998    /// `query_documents` does.
999    ///
1000    /// # Errors
1001    ///
1002    /// As [`query_documents`](Self::query_documents), and [`SourceError::Refused`] for a
1003    /// cursor the default did not hand out.
1004    async fn query_documents_by_origin(
1005        &self,
1006        origin: &str,
1007        page: &PageRequest,
1008    ) -> Result<Page<Document>, SourceError> {
1009        let wanted = origin_query(origin);
1010        let mut matched = Vec::new();
1011        let mut cursor: Option<crate::Cursor> = None;
1012        // Every cursor the listing handed out, so one cycling through several is caught as
1013        // one repeating the last is.
1014        let mut visited: Vec<String> = Vec::new();
1015        loop {
1016            let listed = self
1017                .query_documents(
1018                    &DocumentQuery::default(),
1019                    &PageRequest {
1020                        cursor: cursor.clone(),
1021                        limit: page.limit,
1022                    },
1023                )
1024                .await?;
1025            overran(listed.items.len(), page.limit)?;
1026            matched.extend(
1027                listed
1028                    .items
1029                    .into_iter()
1030                    .filter(|document| wanted.origin_matches(&document.metadata)),
1031            );
1032            cursor = match listed.next {
1033                None => break,
1034                Some(next) if visited.contains(&next.0) => return Err(repeated_cursor()),
1035                Some(next) => {
1036                    visited.push(next.0.clone());
1037                    Some(next)
1038                }
1039            };
1040        }
1041        page_of_matches(matched, page)
1042    }
1043
1044    /// Create or update one document, on exactly the terms of
1045    /// [`write_task`](Self::write_task).
1046    ///
1047    /// # Errors
1048    ///
1049    /// As [`write_task`](Self::write_task).
1050    async fn write_document(&self, write: &ItemWrite<Document>) -> Result<NativeId, SourceError> {
1051        let _ = write;
1052        Err(unwritable(self.kind()))
1053    }
1054
1055    /// Remove one document this destination holds, on exactly the terms of
1056    /// [`delete_task`](Self::delete_task).
1057    ///
1058    /// # Errors
1059    ///
1060    /// As [`delete_task`](Self::delete_task).
1061    async fn delete_document(&self, id: &NativeId) -> Result<(), SourceError> {
1062        let _ = id;
1063        Err(unwritable(self.kind()))
1064    }
1065
1066    /// One page of the comments on `task`, oldest first, or `None` when this source holds
1067    /// no such task.
1068    ///
1069    /// Defaulted to [`commentless`], which is what keeps comments an addition rather than a
1070    /// break: a source with none needs no edit and keeps working. A source whose tasks have
1071    /// comments declares [`Support::Native`](crate::Support::Native) for
1072    /// [`Capabilities::comments`] and owes a real implementation of all four comment methods,
1073    /// because that declaration is what makes the engine ask.
1074    ///
1075    /// "No such task" is `None` rather than an error, exactly as it is for
1076    /// [`get_task`](Self::get_task); a task that exists and has no comments is an empty page.
1077    ///
1078    /// # Errors
1079    ///
1080    /// Returns [`SourceError::Refused`] when this source has no comments, and whatever else
1081    /// the source could not answer for.
1082    async fn task_comments(
1083        &self,
1084        task: &NativeId,
1085        page: &PageRequest,
1086    ) -> Result<Option<Page<Comment>>, SourceError> {
1087        let _ = (task, page);
1088        Err(commentless(self.kind()))
1089    }
1090
1091    /// [`get_task_details`](Self::get_task_details) as a copy reads the tasks it carries: each
1092    /// with the first page of its comments `comments` names — and, where the same request can
1093    /// carry them, what this source needs to answer [`task_dependencies`](Self::task_dependencies)
1094    /// for it without another, since a copy reads every task's edges next.
1095    ///
1096    /// Defaulted to `get_task_details(ids, Some(comments))`, which is exactly what it answers.
1097    /// A source whose detail read is priced by what it selects overrides it with a read that
1098    /// also carries the edges, so a copy of a changed task costs its detail read and nothing
1099    /// more; one whose reads are free has no reason to.
1100    async fn get_task_details_for_copy(
1101        &self,
1102        ids: &[NativeId],
1103        comments: &PageRequest,
1104    ) -> Vec<Result<Option<TaskDetailRead>, SourceError>> {
1105        self.get_task_details(ids, Some(comments)).await
1106    }
1107
1108    /// Read the items `ids` names — tasks, projects and documents alike, whatever kind each
1109    /// is — together, as a copy reads the counterparts it is about to write, and hold each for
1110    /// this command so that the next [`get_task`](Self::get_task),
1111    /// [`get_project`](Self::get_project) or [`get_document`](Self::get_document) of it is
1112    /// answered from that read, once, instead of being sent on its own.
1113    ///
1114    /// What is held is exactly what that read by id would have answered — the item's fields,
1115    /// its edges, its asset manifest and its change token — and only until the next read of
1116    /// it, a write naming it, or [`end_command`](Self::end_command), whichever comes first, so
1117    /// a read answered from it is never staler than the read-before-write it stands in for.
1118    ///
1119    /// Defaulted to doing nothing, so every read is sent as it always was: a source whose
1120    /// reads are free has no reason to override it, and one priced per request overrides it
1121    /// with a batched read. An id the batched read finds nothing at is either held as absent —
1122    /// its next read answers `None`, exactly as that read would have — or not held, and its own
1123    /// read answers as it always does.
1124    ///
1125    /// # Errors
1126    ///
1127    /// Returns a [`SourceError`] when the batched read could not be made. Nothing is then
1128    /// held, and each item's own read answers as it would have.
1129    async fn read_ahead_for_copy(&self, ids: &[NativeId]) -> Result<(), SourceError> {
1130        let _ = ids;
1131        Ok(())
1132    }
1133
1134    /// Add one comment to `task`, answering with the comment as the source now holds it, or
1135    /// `None` when this source holds no such task.
1136    ///
1137    /// The body is stored byte for byte. A source that records the author itself refuses a
1138    /// [`NewComment::author`] rather than dropping it, naming why; a source that cannot
1139    /// represent the body refuses it, naming why, rather than escaping it into something
1140    /// else.
1141    ///
1142    /// # Errors
1143    ///
1144    /// Returns [`SourceError::Refused`] when this source has no comments or cannot be
1145    /// written, when it cannot record what it was given, and whatever else it could not do
1146    /// the write for.
1147    async fn add_comment(
1148        &self,
1149        task: &NativeId,
1150        comment: &NewComment,
1151    ) -> Result<Option<Comment>, SourceError> {
1152        let _ = (task, comment);
1153        Err(commentless(self.kind()))
1154    }
1155
1156    /// Replace the body of the comment `comment` on `task`, answering with the comment as the
1157    /// source now holds it, or `None` when this source holds no such task or that task has no
1158    /// such comment.
1159    ///
1160    /// Only the body and the time it last changed move: the id, the author and the time it
1161    /// was written are the comment's own.
1162    ///
1163    /// # Errors
1164    ///
1165    /// As [`add_comment`](Self::add_comment).
1166    async fn edit_comment(
1167        &self,
1168        task: &NativeId,
1169        comment: &NativeId,
1170        body: &CommentBody,
1171    ) -> Result<Option<Comment>, SourceError> {
1172        let _ = (task, comment, body);
1173        Err(commentless(self.kind()))
1174    }
1175
1176    /// Remove the comment `comment` from `task`, answering with the id it removed, or `None`
1177    /// when this source holds no such task or that task has no such comment.
1178    ///
1179    /// Unlike [`delete_task`](Self::delete_task), this *is* a verb of the product — a person
1180    /// removes a comment they posted — so a comment that is not there is reported as `None`
1181    /// for the engine to refuse by name, rather than treated as already gone.
1182    ///
1183    /// # Errors
1184    ///
1185    /// As [`add_comment`](Self::add_comment).
1186    async fn delete_comment(
1187        &self,
1188        task: &NativeId,
1189        comment: &NativeId,
1190    ) -> Result<Option<NativeId>, SourceError> {
1191        let _ = (task, comment);
1192        Err(commentless(self.kind()))
1193    }
1194
1195    /// Write one comment a copy carries onto `task`: a new one when `existing` is `None`, and
1196    /// otherwise the comment `existing`, which a copy wrote before, made to say `copy` — or
1197    /// `None` when this source holds no such task or no such comment.
1198    ///
1199    /// The answer reports [`Comment::origin`] as `copy.origin`, however the source keeps it.
1200    ///
1201    /// **Defaulted to the hidden marker**, which is right for every source that records a
1202    /// comment's author and times itself: the body is written through
1203    /// [`add_comment`](Self::add_comment) or [`edit_comment`](Self::edit_comment) with
1204    /// [`CommentOrigin::mark`](crate::CommentOrigin::mark) appended, and read back
1205    /// [`unmarked`](Comment::unmarked). A source that can store the origin natively — and so
1206    /// takes the origin's own id, author and times for the copy — overrides this.
1207    ///
1208    /// # Errors
1209    ///
1210    /// As [`add_comment`](Self::add_comment).
1211    async fn write_comment_copy(
1212        &self,
1213        task: &NativeId,
1214        existing: Option<&NativeId>,
1215        copy: &CommentCopy,
1216    ) -> Result<Option<Comment>, SourceError> {
1217        let body = CommentBody::new(copy.origin.qualified()?.mark(copy.body.as_str()))?;
1218        let written = match existing {
1219            Some(comment) => self.edit_comment(task, comment, &body).await?,
1220            None => {
1221                self.add_comment(task, &NewComment { body, author: None })
1222                    .await?
1223            }
1224        };
1225        Ok(written.map(Comment::unmarked))
1226    }
1227
1228    /// Whether this source keeps template answers beside its items at all.
1229    ///
1230    /// What lets a regenerate tell an item whose answers went missing — a block deleted by
1231    /// hand, which the regenerate writes back — from an item of a source that never keeps any,
1232    /// where a missing answer is no difference. Defaulted to `false`, as
1233    /// [`task_template_answers`](Self::task_template_answers) is defaulted to `None`; a source
1234    /// that keeps answers answers `true` here.
1235    fn keeps_template_answers(&self) -> bool {
1236        false
1237    }
1238
1239    /// The template answers the task `id` was last rendered from, as this source keeps them
1240    /// beside the task — or `None` when it keeps none for it, or holds no such task.
1241    ///
1242    /// Keeping answers is a source's own choice, never an obligation: a source whose items
1243    /// are one record in a hosted system has no room beside the item that is not the item, and
1244    /// answers written into its content or its metadata would duplicate what the content
1245    /// already says. Defaulted to `None`, which is what keeps this an addition rather than a
1246    /// break. A source that keeps them owes three things: they are in neither
1247    /// [`Task::content`] nor [`Task::metadata`], they are written only by
1248    /// [`write_task_rendered`](Self::write_task_rendered) and
1249    /// [`set_task_rendering`](Self::set_task_rendering), and they come back here exactly as
1250    /// they were written, JSON types intact.
1251    ///
1252    /// # Errors
1253    ///
1254    /// Returns a [`SourceError`] when the source could not answer, a record whose answers it
1255    /// cannot read included.
1256    async fn task_template_answers(
1257        &self,
1258        id: &NativeId,
1259    ) -> Result<Option<BTreeMap<String, Value>>, SourceError> {
1260        let _ = id;
1261        Ok(None)
1262    }
1263
1264    /// The template answers the document `id` was last rendered from, on exactly the terms of
1265    /// [`task_template_answers`](Self::task_template_answers).
1266    ///
1267    /// # Errors
1268    ///
1269    /// As [`task_template_answers`](Self::task_template_answers).
1270    async fn document_template_answers(
1271        &self,
1272        id: &NativeId,
1273    ) -> Result<Option<BTreeMap<String, Value>>, SourceError> {
1274        let _ = id;
1275        Ok(None)
1276    }
1277
1278    /// The template answers the project `id` was last rendered from, on exactly the terms of
1279    /// [`task_template_answers`](Self::task_template_answers).
1280    ///
1281    /// # Errors
1282    ///
1283    /// As [`task_template_answers`](Self::task_template_answers).
1284    async fn project_template_answers(
1285        &self,
1286        id: &NativeId,
1287    ) -> Result<Option<BTreeMap<String, Value>>, SourceError> {
1288        let _ = id;
1289        Ok(None)
1290    }
1291
1292    /// Create or update one task exactly as [`write_task`](Self::write_task) does, keeping
1293    /// `answers` — the answers its content was rendered from — beside it in the same write
1294    /// where this source keeps answers at all.
1295    ///
1296    /// The task arrives carrying its provenance under [`MetadataKey::TEMPLATE_KEY`] like any
1297    /// other metadata entry. Defaulted to [`write_task`](Self::write_task) alone: a source that
1298    /// keeps no answers writes the task and nothing beside it, which is the whole of what it
1299    /// owes. A source that keeps them writes the task and the answers together, so a reader
1300    /// never finds one without the other.
1301    ///
1302    /// # Errors
1303    ///
1304    /// As [`write_task`](Self::write_task).
1305    async fn write_task_rendered(
1306        &self,
1307        write: &ItemWrite<Task>,
1308        answers: &BTreeMap<String, Value>,
1309    ) -> Result<NativeId, SourceError> {
1310        let _ = answers;
1311        self.write_task(write).await
1312    }
1313
1314    /// Create or update one document, on exactly the terms of
1315    /// [`write_task_rendered`](Self::write_task_rendered).
1316    ///
1317    /// # Errors
1318    ///
1319    /// As [`write_document`](Self::write_document).
1320    async fn write_document_rendered(
1321        &self,
1322        write: &ItemWrite<Document>,
1323        answers: &BTreeMap<String, Value>,
1324    ) -> Result<NativeId, SourceError> {
1325        let _ = answers;
1326        self.write_document(write).await
1327    }
1328
1329    /// Create or update one project, on exactly the terms of
1330    /// [`write_task_rendered`](Self::write_task_rendered).
1331    ///
1332    /// # Errors
1333    ///
1334    /// As [`write_project`](Self::write_project).
1335    async fn write_project_rendered(
1336        &self,
1337        write: &ItemWrite<Project>,
1338        answers: &BTreeMap<String, Value>,
1339    ) -> Result<NativeId, SourceError> {
1340        let _ = answers;
1341        self.write_project(write).await
1342    }
1343
1344    /// Replace one task's rendering — its content, byte for byte, its
1345    /// [`MetadataKey::TEMPLATE_KEY`] entry, set to `provenance`, and the answers it keeps
1346    /// beside the task where it keeps any — in one write, and change nothing else about it;
1347    /// or answer `None` when this source holds no such task.
1348    ///
1349    /// The content is [`Task::content`] exactly as a later read reports it, on the terms of
1350    /// [`set_task_content`](Self::set_task_content). Title, status, priority, labels, every
1351    /// other metadata entry, repositories, dependencies, [`Task::delivers`],
1352    /// [`Task::delivered_by`], project and comments are left exactly as they are. The write is
1353    /// one write: a reader sees the task as it was or as it is now, never a new content beside
1354    /// the old provenance or the old answers.
1355    ///
1356    /// Defaulted to [`unwritable_field`] on exactly the terms of
1357    /// [`set_task_status`](Self::set_task_status). A source declaring
1358    /// [`WriteSupport::Unsupported`] is never asked.
1359    ///
1360    /// [`Task::delivers`]: crate::Task::delivers
1361    /// [`Task::delivered_by`]: crate::Task::delivered_by
1362    ///
1363    /// # Errors
1364    ///
1365    /// Returns [`SourceError::Refused`] when this source cannot replace a task's rendering on
1366    /// its own, or cannot represent this one; and whatever else the source could not do the
1367    /// write for.
1368    async fn set_task_rendering(
1369        &self,
1370        id: &NativeId,
1371        content: &str,
1372        provenance: &Value,
1373        answers: &BTreeMap<String, Value>,
1374    ) -> Result<Option<()>, SourceError> {
1375        let _ = (id, content, provenance, answers);
1376        Err(unwritable_field(self.kind(), "rendering"))
1377    }
1378
1379    /// Replace one document's rendering, on exactly the terms of
1380    /// [`set_task_rendering`](Self::set_task_rendering). A source declaring
1381    /// [`Capabilities::documents`] unsupported is never asked.
1382    ///
1383    /// # Errors
1384    ///
1385    /// As [`set_task_rendering`](Self::set_task_rendering).
1386    async fn set_document_rendering(
1387        &self,
1388        id: &NativeId,
1389        content: &str,
1390        provenance: &Value,
1391        answers: &BTreeMap<String, Value>,
1392    ) -> Result<Option<()>, SourceError> {
1393        let _ = (id, content, provenance, answers);
1394        Err(SourceError::Refused {
1395            message: format!(
1396                "the {} plugin cannot write a document's rendering on its own",
1397                self.kind()
1398            ),
1399        })
1400    }
1401
1402    /// Replace one project's rendering, on exactly the terms of
1403    /// [`set_task_rendering`](Self::set_task_rendering): its content, its
1404    /// [`MetadataKey::TEMPLATE_KEY`] entry and the answers kept beside it change, and its
1405    /// title, status, labels, every other metadata entry, repositories and dependencies are
1406    /// left exactly as they are.
1407    ///
1408    /// # Errors
1409    ///
1410    /// As [`set_task_rendering`](Self::set_task_rendering).
1411    async fn set_project_rendering(
1412        &self,
1413        id: &NativeId,
1414        content: &str,
1415        provenance: &Value,
1416        answers: &BTreeMap<String, Value>,
1417    ) -> Result<Option<()>, SourceError> {
1418        let _ = (id, content, provenance, answers);
1419        Err(SourceError::Refused {
1420            message: format!(
1421                "the {} plugin cannot write a project's rendering on its own",
1422                self.kind()
1423            ),
1424        })
1425    }
1426
1427    /// The image assets the task `id` holds, or none when it holds none or this source holds
1428    /// no such task.
1429    ///
1430    /// Defaulted to none, which is what keeps assets an addition rather than a break: a source
1431    /// that keeps no assets needs no edit and reports every record as holding none. A source
1432    /// declaring [`Capabilities::assets`] native answers what it holds for the record, in any
1433    /// order — the engine orders them by the content's first reference.
1434    ///
1435    /// # Errors
1436    ///
1437    /// Returns a [`SourceError`] when the source could not answer.
1438    async fn task_assets(&self, id: &NativeId) -> Result<Vec<Asset>, SourceError> {
1439        let _ = id;
1440        Ok(Vec::new())
1441    }
1442
1443    /// The image assets the document `id` holds, on exactly the terms of
1444    /// [`task_assets`](Self::task_assets).
1445    ///
1446    /// # Errors
1447    ///
1448    /// As [`task_assets`](Self::task_assets).
1449    async fn document_assets(&self, id: &NativeId) -> Result<Vec<Asset>, SourceError> {
1450        let _ = id;
1451        Ok(Vec::new())
1452    }
1453
1454    /// The bytes of the asset `name` the task `id` holds, or `None` when it holds no such asset
1455    /// or this source holds no such task.
1456    ///
1457    /// Defaulted to `None`, on the terms of [`task_assets`](Self::task_assets).
1458    ///
1459    /// # Errors
1460    ///
1461    /// Returns a [`SourceError`] when the source could not answer.
1462    async fn task_asset(
1463        &self,
1464        id: &NativeId,
1465        name: &AssetName,
1466    ) -> Result<Option<Vec<u8>>, SourceError> {
1467        let _ = (id, name);
1468        Ok(None)
1469    }
1470
1471    /// The bytes of the asset `name` the document `id` holds, on exactly the terms of
1472    /// [`task_asset`](Self::task_asset).
1473    ///
1474    /// # Errors
1475    ///
1476    /// As [`task_asset`](Self::task_asset).
1477    async fn document_asset(
1478        &self,
1479        id: &NativeId,
1480        name: &AssetName,
1481    ) -> Result<Option<Vec<u8>>, SourceError> {
1482        let _ = (id, name);
1483        Ok(None)
1484    }
1485
1486    /// Create or update one task carrying image assets, in one write: the task as
1487    /// [`write_task`](Self::write_task) writes it — or, with `answers`, as
1488    /// [`write_task_rendered`](Self::write_task_rendered) does — and `assets` as the record's
1489    /// whole asset set, answering with where it landed and the content as stored.
1490    ///
1491    /// Only a source declaring [`Capabilities::assets`] native is asked, and the engine has
1492    /// already checked that every reference in the content names one of `assets` and every one
1493    /// of `assets` is referenced. A source that keeps the bytes beside the record stores each
1494    /// payload under its name, removes every asset the record held that `assets` does not
1495    /// name, and answers the content unchanged. A source that serves them at a URL uploads each
1496    /// payload that carries bytes, reuses the URL [`AssetWrite::recorded_assets`] records for
1497    /// each that does not, and writes the record through
1498    /// [`serve_asset_references`](crate::serve_asset_references) — so its references point at
1499    /// those URLs, its [`MetadataKey::ASSETS_KEY`] records each `{sha256, url}`, and a
1500    /// rendering's `body_digest` stays true of what landed — answering the content it wrote.
1501    ///
1502    /// Defaulted to [`assetless`], which is what a source with no assets answers.
1503    ///
1504    /// # Errors
1505    ///
1506    /// As [`write_task`](Self::write_task), and [`SourceError::Refused`] from a source that
1507    /// keeps no assets.
1508    async fn write_task_with_assets(
1509        &self,
1510        write: &ItemWrite<Task>,
1511        answers: Option<&BTreeMap<String, Value>>,
1512        assets: &AssetWrite,
1513    ) -> Result<AssetsWritten, SourceError> {
1514        let _ = (write, answers, assets);
1515        Err(assetless(self.kind()))
1516    }
1517
1518    /// Create or update one document carrying image assets, on exactly the terms of
1519    /// [`write_task_with_assets`](Self::write_task_with_assets).
1520    ///
1521    /// # Errors
1522    ///
1523    /// As [`write_task_with_assets`](Self::write_task_with_assets).
1524    async fn write_document_with_assets(
1525        &self,
1526        write: &ItemWrite<Document>,
1527        answers: Option<&BTreeMap<String, Value>>,
1528        assets: &AssetWrite,
1529    ) -> Result<AssetsWritten, SourceError> {
1530        let _ = (write, answers, assets);
1531        Err(assetless(self.kind()))
1532    }
1533
1534    /// Replace one task's rendering as [`set_task_rendering`](Self::set_task_rendering) does,
1535    /// and its asset set as [`write_task_with_assets`](Self::write_task_with_assets) does, in
1536    /// one write; or answer `None` when this source holds no such task.
1537    ///
1538    /// Defaulted to [`assetless`].
1539    ///
1540    /// # Errors
1541    ///
1542    /// As [`set_task_rendering`](Self::set_task_rendering), and [`SourceError::Refused`] from a
1543    /// source that keeps no assets.
1544    async fn set_task_rendering_with_assets(
1545        &self,
1546        id: &NativeId,
1547        content: &str,
1548        provenance: &Value,
1549        answers: &BTreeMap<String, Value>,
1550        assets: &AssetWrite,
1551    ) -> Result<Option<AssetsWritten>, SourceError> {
1552        let _ = (id, content, provenance, answers, assets);
1553        Err(assetless(self.kind()))
1554    }
1555
1556    /// Replace one document's rendering and its asset set, on exactly the terms of
1557    /// [`set_task_rendering_with_assets`](Self::set_task_rendering_with_assets).
1558    ///
1559    /// # Errors
1560    ///
1561    /// As [`set_task_rendering_with_assets`](Self::set_task_rendering_with_assets).
1562    async fn set_document_rendering_with_assets(
1563        &self,
1564        id: &NativeId,
1565        content: &str,
1566        provenance: &Value,
1567        answers: &BTreeMap<String, Value>,
1568        assets: &AssetWrite,
1569    ) -> Result<Option<AssetsWritten>, SourceError> {
1570        let _ = (id, content, provenance, answers, assets);
1571        Err(assetless(self.kind()))
1572    }
1573
1574    /// What this source has sent to its backend since it was built and what that spent, or
1575    /// `None` when it does not meter its own requests.
1576    ///
1577    /// Defaulted to `None`, which is what keeps metering an addition rather than a break: a
1578    /// source that does not count its requests needs no edit, and is reported as not
1579    /// metering rather than as having spent nothing. A source that answers owes a running
1580    /// total — see [`Metering`] — because what one command spent is read as the difference
1581    /// between two readings.
1582    ///
1583    /// # Errors
1584    ///
1585    /// Returns a [`SourceError`] when the reading itself could not be taken. A caller
1586    /// reports such a source as not metering; what a command cost is never a reason for the
1587    /// command to fail.
1588    async fn metering(&self) -> Result<Option<Metering>, SourceError> {
1589        Ok(None)
1590    }
1591
1592    /// End one command: drop everything held that a person can change.
1593    ///
1594    /// A command is one unit of work — one invocation of the binary, or whatever a caller
1595    /// holding one engine for many units of work calls between them. Within a command a
1596    /// source may hold what it read and reuse it; across this call it may not. After it
1597    /// returns, a source answers no read and bases no write on item content, statuses, board
1598    /// contents or search results it held before the call. It may keep only identifiers and
1599    /// vocabulary that stay valid in normal use — a repository's node id, a team's workflow
1600    /// states — and only where a lookup that misses one re-reads rather than refusing.
1601    ///
1602    /// Defaulted to doing nothing, which is right for a source that holds nothing between
1603    /// calls or holds only what the rule above lets it keep. A source that holds more owes
1604    /// an override. Never called by the engine on its own: the binary's one command is its
1605    /// whole process, so only a caller that outlives a command calls it.
1606    ///
1607    /// # Errors
1608    ///
1609    /// Returns a [`SourceError`] when the source could not be sure it dropped what it held —
1610    /// ordinarily a hosted plugin that did not answer. A caller should not go on to the next
1611    /// command on that source's earlier reads.
1612    async fn end_command(&self) -> Result<(), SourceError> {
1613        Ok(())
1614    }
1615
1616    /// Who can read where `target` lands, read live from the backend.
1617    ///
1618    /// This is the destination's reality, which the engine holds a declaration against
1619    /// before it lets a write through: a source a configuration declares private receives an
1620    /// item that may only be written somewhere private only while this answers
1621    /// [`Visibility::Private`]. The engine asks immediately before the write it is about, so
1622    /// a source must not answer from anything it read for an earlier write unless its
1623    /// backend's visibility cannot change in between.
1624    ///
1625    /// Defaulted to [`Visibility::Unknown`], which is the answer of a source that cannot say
1626    /// and is never treated as private. A source on this machine answers `Private` — what it
1627    /// writes stays on the host — and a hosted source reads its backend.
1628    ///
1629    /// # Errors
1630    ///
1631    /// Returns a [`SourceError`] when the backend could not be asked or would not answer —
1632    /// a credential lacking the scope the read needs among them. An unreadable visibility is
1633    /// never guessed: the engine refuses the write.
1634    async fn visibility(&self, target: &WriteTarget<'_>) -> Result<Visibility, SourceError> {
1635        let _ = target;
1636        Ok(Visibility::Unknown)
1637    }
1638}
1639
1640/// The factory that turns one configuration block into a live [`TaskSource`].
1641///
1642/// Having the compile-time registry and the subprocess seam be the same shape is
1643/// the whole reason this is a trait rather than a free function.
1644pub trait SourcePlugin: Send + Sync + 'static {
1645    /// The name a configuration document's `plugin:` field names.
1646    fn kind(&self) -> &'static str;
1647
1648    /// The JSON Schema for this plugin's own `config:` block.
1649    fn config_schema(&self) -> Schema;
1650
1651    /// Build a live source from one configuration block.
1652    ///
1653    /// `name` is the configured source's name, for error messages only — a
1654    /// plugin never learns it for any other purpose.
1655    ///
1656    /// # Errors
1657    ///
1658    /// Returns [`SourceError::Config`] when `config` is not valid for this
1659    /// plugin, or [`SourceError::Auth`] when a named credential is absent.
1660    fn build(
1661        &self,
1662        name: &SourceName,
1663        config: &serde_json::Value,
1664        secrets: &dyn SecretResolver,
1665    ) -> Result<Box<dyn TaskSource>, SourceError>;
1666
1667    /// Build a live source from one configuration block, handing it the clock it paces and
1668    /// backs off on.
1669    ///
1670    /// The binary builds every in-process source through this, with the process's one
1671    /// [`SharedClock`] — [`system_clock`](crate::system_clock) unless a test asked for
1672    /// simulated time. Defaulted to [`build`](Self::build), which ignores the clock: a plugin
1673    /// that never waits needs no edit, and one that does overrides this and routes its waits
1674    /// through `clock`.
1675    ///
1676    /// # Errors
1677    ///
1678    /// As [`build`](Self::build).
1679    fn build_with_clock(
1680        &self,
1681        name: &SourceName,
1682        config: &serde_json::Value,
1683        secrets: &dyn SecretResolver,
1684        clock: SharedClock,
1685    ) -> Result<Box<dyn TaskSource>, SourceError> {
1686        let _ = clock;
1687        self.build(name, config, secrets)
1688    }
1689
1690    /// The fields of this plugin's `config:` block that name a filesystem path, as dotted
1691    /// paths into that block.
1692    ///
1693    /// A relative value at one of these, **supplied by a configuration document**, is
1694    /// resolved against the directory holding that document before [`Self::build`] sees it;
1695    /// supplied through the environment or a flag it keeps resolving against the process
1696    /// working directory, because there is no document to rebase it on. A plugin is handed
1697    /// values and no origins, so this declaration is the only way it can say which of its
1698    /// own fields that rule reaches.
1699    ///
1700    /// Defaulted to none, which is what keeps this an addition rather than a break: a
1701    /// plugin whose block holds no path needs no edit, and a caller asks every plugin
1702    /// rather than keeping a table of which ones answer.
1703    // llmlint: ignore[invalid_states_unrepresentable] The identity of a configuration field
1704    // is a name, and no type can make a wrong one unrepresentable here: every string is a
1705    // syntactically valid dotted path, so a newtype would validate nothing and would only
1706    // move where a name that is not a field of *this* plugin is accepted. What decides that
1707    // is whether the name is a property of the schema `config_schema` publishes — a
1708    // per-plugin fact no shared type can hold — so the gate is per plugin and executable:
1709    // `document_relative_fields_are_fields_this_plugin_declares` in
1710    // `onetaskgraph-local-md/tests/plugin.rs`, which a plugin adding a declaration owes its
1711    // own copy of.
1712    fn document_relative_paths(&self) -> &'static [&'static str] {
1713        &[]
1714    }
1715
1716    /// What names the remote store a source built from `config` reads — a board's owner and
1717    /// number, a Linear endpoint and team — or `None` for a source with no remote.
1718    ///
1719    /// The store's local cache of a remote source lives under a digest of this, so every
1720    /// process configuring the same remote shares one cache and no two remotes share one.
1721    /// Defaulted to `None`, which is what a source keeping its work on this machine — a
1722    /// folder of Markdown — answers: it has nothing to cache, and its cache setting is
1723    /// ignored. A `config` this plugin would refuse answers `None` too.
1724    fn remote_identity(&self, config: &serde_json::Value) -> Option<String> {
1725        let _ = config;
1726        None
1727    }
1728}
1729
1730/// How a plugin reads the credential its configuration names.
1731///
1732/// A configuration document never carries a credential value, only the name of
1733/// the environment variable holding it.
1734pub trait SecretResolver: Send + Sync {
1735    /// The value of `var`, or `None` when nothing defines it.
1736    ///
1737    /// The returned value is never logged and never appears in `Debug` output.
1738    fn get(&self, var: &str) -> Option<SecretString>;
1739}