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, ItemKind, ItemWrite, Label, MetadataKey,
14    MetadataRecord, Metering, NativeId, NewComment, Page, PageRequest, Priority, Project,
15    ProjectQuery, SharedClock, SourceError, SourceName, Status, StatusCategory, Task,
16    TaskDetailRead, TaskQuery, TaskRef, TaskUpdate, TaskUpdateOutcome, Visibility, WriteSupport,
17    WriteTarget, assetless, commentless, documentless, unwritable, unwritable_field,
18    unwritable_metadata,
19};
20
21/// Whether a source is answering right now.
22///
23/// # Placement is an open contract question
24///
25/// This type lives here because [`TaskSource::health`] returns it and the trait
26/// lives here: placing it in `onetaskgraph-core` would make this crate depend on
27/// the engine and invert the one direction the crate split exists to establish.
28/// The approved contract enumerates this crate's contents exhaustively and does
29/// not name `Health`, so the enumeration and the trait as written cannot both
30/// stand. Compiling forces the placement below; the resolution — add it to the
31/// enumeration, or redesign `health` so no such type crosses the boundary —
32/// belongs to the contract's owner, not to this crate. See `AGENTS.md`.
33#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
34// 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.
35pub struct Health {
36    /// Whether the source answered.
37    ///
38    /// A bare `bool` beside an untyped `detail` cannot say that an unreachable source
39    /// must explain itself, or keep "reachable with a warning" apart from "reachable";
40    /// an enum carrying the detail in its unreachable variant would.
41    // llmlint: ignore[invalid_states_unrepresentable] SECOND PERMITTED REASON — this
42    // restates at this field the justification already recorded at
43    // `Capabilities.max_page_size` (capability.rs), `PageRequest.limit` (query.rs), this
44    // type's own doc comment above, and AGENTS.md's "Open contract question — `Health`":
45    // `Health`'s shape is approved contract text that `TaskSource::health` returns, so an
46    // enum here would change the serialized form and the trait six undispatched nodes
47    // implement. That is the contract owner's call, not this crate's.
48    // 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`".
49    pub reachable: bool,
50    /// What the source said, when it said anything useful.
51    pub detail: Option<String>,
52}
53
54/// One configured source, as the engine drives it.
55///
56/// Dyn-compatible through `async_trait` because the engine holds
57/// `Vec<Box<dyn TaskSource>>` over heterogeneous plugins.
58///
59/// Three rules bind every implementation, and the engine's compensation is only
60/// correct while all three hold:
61///
62/// 1. **Apply** every predicate you declare [`Support::Native`](crate::Support::Native).
63/// 2. **Ignore** every [`Support`](crate::Support)-typed predicate you declare
64///    `Unsupported` — return the *wider* result set, never a narrower one.
65///    Silently dropping rows for a predicate you did not declare is the one
66///    failure no test above the plugin can catch.
67/// 3. Never return a silently empty dependency read. Rule 2 reaches the
68///    `Support`-typed *predicates* alone; a dependency read is always real, and so is a
69///    document read — [`Capabilities::documents`] says whether this source has documents
70///    at all, and a source that says it has none is never asked for one rather than
71///    answering an empty page.
72#[async_trait::async_trait]
73pub trait TaskSource: Send + Sync {
74    /// The plugin kind that built this source, for display and for plan output.
75    fn kind(&self) -> &'static str;
76
77    /// What this source applies itself. Read once per query by the engine.
78    fn capabilities(&self) -> Capabilities;
79
80    /// How `a`, a [`Task::version`] this source gave one of its tasks, stands to `b`, another
81    /// it gave the same task: `Greater` when `a` is the later, `Less` when it is the earlier,
82    /// `Equal` when nothing the token covers changed between them, and `None` when the two
83    /// cannot be put in order — a value this source cannot read, or two versions its token
84    /// says differ without saying which came first.
85    ///
86    /// A token's format and its order are the one source's that spells it, so the engine asks
87    /// the source that gave both rather than reading inside either.
88    ///
89    /// Defaulted to equality alone: two identical tokens are one version, and any two others
90    /// are unordered, which a reader takes as *changed, read it again* and never as
91    /// unchanged. A source whose token says which of two versions is the later overrides it.
92    fn order_versions(&self, a: &str, b: &str) -> Option<Ordering> {
93        (a == b).then_some(Ordering::Equal)
94    }
95
96    /// Whether the source is answering right now.
97    ///
98    /// # Errors
99    ///
100    /// Returns a [`SourceError`] when the check itself could not be made.
101    async fn health(&self) -> Result<Health, SourceError>;
102
103    /// Fetch one task by its native id, or `None` when there is no such task.
104    ///
105    /// # Errors
106    ///
107    /// Returns a [`SourceError`] when the source could not answer.
108    async fn get_task(&self, id: &NativeId) -> Result<Option<Task>, SourceError>;
109
110    /// Fetch several tasks by their native ids, each with the first page of its comments
111    /// when `comments` names the page to read — one answer per id, in the order they were
112    /// given.
113    ///
114    /// Each answer is what [`get_task`](Self::get_task) answers for that id, so a task that
115    /// is not there is `Ok(None)` and a read that failed fails that id alone. Its
116    /// [`TaskDetailRead::comments`] is what [`task_comments`](Self::task_comments) answers
117    /// for `comments`. The engine passes `comments` only to a source declaring
118    /// [`Capabilities::comments`](crate::Capabilities::comments) native.
119    ///
120    /// Defaulted to exactly those calls, item by item, so a source that implements nothing
121    /// here answers as it always did. A source that can read many items — or an item and its
122    /// comments — in fewer requests than that overrides it, which is the whole reason it
123    /// exists: a caller holding twenty ids pays for one batch rather than forty reads.
124    async fn get_task_details(
125        &self,
126        ids: &[NativeId],
127        comments: Option<&PageRequest>,
128    ) -> Vec<Result<Option<TaskDetailRead>, SourceError>> {
129        let mut read = Vec::with_capacity(ids.len());
130        for id in ids {
131            read.push(match self.get_task(id).await {
132                Ok(Some(task)) => {
133                    let comments = match comments {
134                        Some(page) => Some(self.task_comments(id, page).await),
135                        None => None,
136                    };
137                    Ok(Some(TaskDetailRead { task, comments }))
138                }
139                Ok(None) => Ok(None),
140                Err(error) => Err(error),
141            });
142        }
143        read
144    }
145
146    /// Fetch one project by its native id, or `None` when there is no such project.
147    ///
148    /// # Errors
149    ///
150    /// Returns a [`SourceError`] when the source could not answer.
151    async fn get_project(&self, id: &NativeId) -> Result<Option<Project>, SourceError>;
152
153    /// One page of the tasks matching `query`.
154    ///
155    /// # Errors
156    ///
157    /// Returns a [`SourceError`] when the source could not answer.
158    async fn query_tasks(
159        &self,
160        query: &TaskQuery,
161        page: &PageRequest,
162    ) -> Result<Page<Task>, SourceError>;
163
164    /// One page of the projects matching `query`.
165    ///
166    /// # Errors
167    ///
168    /// Returns a [`SourceError`] when the source could not answer.
169    async fn query_projects(
170        &self,
171        query: &ProjectQuery,
172        page: &PageRequest,
173    ) -> Result<Page<Project>, SourceError>;
174
175    /// One page of every label this source knows.
176    ///
177    /// # Errors
178    ///
179    /// Returns a [`SourceError`] when the source could not answer.
180    async fn labels(&self, page: &PageRequest) -> Result<Page<Label>, SourceError>;
181
182    /// One page of the task dependency edges at `id`, in `direction`.
183    ///
184    /// # Errors
185    ///
186    /// Returns a [`SourceError`] when the source could not answer.
187    async fn task_dependencies(
188        &self,
189        id: &NativeId,
190        direction: Direction,
191        page: &PageRequest,
192    ) -> Result<Page<DependencyEdge>, SourceError>;
193
194    /// One page of the project dependency edges at `id`, in `direction`.
195    ///
196    /// # Errors
197    ///
198    /// Returns a [`SourceError`] when the source could not answer.
199    async fn project_dependencies(
200        &self,
201        id: &NativeId,
202        direction: Direction,
203        page: &PageRequest,
204    ) -> Result<Page<DependencyEdge>, SourceError>;
205
206    /// Whether this source can be written through at all.
207    ///
208    /// Defaulted to [`WriteSupport::Unsupported`], which is what keeps this a read
209    /// interface for every source that has nothing to write into: one that cannot be
210    /// written needs no edit and keeps working. Read before a write is attempted, so a
211    /// copy naming such a source as its destination is refused before anything is read.
212    fn writes(&self) -> WriteSupport {
213        WriteSupport::Unsupported
214    }
215
216    /// Create or update one task, answering with the native id the destination holds it
217    /// under.
218    ///
219    /// A source declaring [`WriteSupport::Supported`] owes three things here. It refuses,
220    /// naming the field, anything it cannot represent rather than dropping it — including
221    /// a metadata key it cannot carry, which it names. It writes every other field it was
222    /// given. And it never creates when [`ItemWrite::target`] names an item it does not
223    /// hold.
224    ///
225    /// # Errors
226    ///
227    /// Returns [`SourceError::Refused`] when this source has no write side, when a field
228    /// or a metadata key cannot be represented, or when `target` names nothing here; and
229    /// whatever else the source could not do the write for.
230    async fn write_task(&self, write: &ItemWrite<Task>) -> Result<NativeId, SourceError> {
231        let _ = write;
232        Err(unwritable(self.kind()))
233    }
234
235    /// Create or update one project, on exactly the terms of
236    /// [`write_task`](Self::write_task).
237    ///
238    /// # Errors
239    ///
240    /// As [`write_task`](Self::write_task).
241    async fn write_project(&self, write: &ItemWrite<Project>) -> Result<NativeId, SourceError> {
242        let _ = write;
243        Err(unwritable(self.kind()))
244    }
245
246    /// Whether a write of an item of `kind` at `category` — over the item `target` names, or
247    /// creating one when it is `None` — would have a status to write, asked before the write
248    /// and changing nothing.
249    ///
250    /// A caller that has to put an item back when a later write of it fails — a copy, whose
251    /// journal records what an item held before overwriting it — asks this first, so a status
252    /// this source has no name for is refused while nothing has been recorded or written, and
253    /// nothing has to be put back. It answers what the write itself would refuse a status
254    /// with, in the same words, and sends no request a write of that status would not have
255    /// sent anyway: what it reads to answer, it holds for the write that follows.
256    ///
257    /// Defaulted to `Ok(())`: a source that does not answer it in advance still refuses the
258    /// status in its write, exactly as before.
259    ///
260    /// # Errors
261    ///
262    /// Returns [`SourceError::Refused`] naming the kind, the category and what is missing
263    /// when this source has no name for that status; and whatever else kept it from finding
264    /// out.
265    async fn check_status_write(
266        &self,
267        kind: ItemKind,
268        category: StatusCategory,
269        target: Option<&NativeId>,
270    ) -> Result<(), SourceError> {
271        let _ = (kind, category, target);
272        Ok(())
273    }
274
275    /// Set the status of one task this source holds, and change nothing else about it,
276    /// answering with the status as this source now reads it — or `None` when this source
277    /// holds no such task.
278    ///
279    /// The category lands where this source's own mapping sends it, exactly as a
280    /// [`write_task`](Self::write_task) of a task in that category would: a category this
281    /// source has disabled is refused in the words a write of it is refused with. Title,
282    /// content, labels, metadata, dependencies, [`Task::delivers`], [`Task::delivered_by`],
283    /// project and comments are left exactly as they are.
284    ///
285    /// Defaulted to [`unwritable_field`], which is what keeps this an addition rather than a
286    /// break: a source that cannot write a status on its own needs no edit and refuses by
287    /// saying so. A source declaring [`WriteSupport::Unsupported`] is never asked.
288    ///
289    /// [`Task::delivers`]: crate::Task::delivers
290    /// [`Task::delivered_by`]: crate::Task::delivered_by
291    ///
292    /// # Errors
293    ///
294    /// Returns [`SourceError::Refused`] when this source cannot write a status, or cannot
295    /// write this one; and whatever else the source could not do the write for.
296    async fn set_task_status(
297        &self,
298        id: &NativeId,
299        category: StatusCategory,
300    ) -> Result<Option<Status>, SourceError> {
301        let _ = (id, category);
302        Err(unwritable_field(self.kind(), "status"))
303    }
304
305    /// Set the status of one task this source holds, as [`set_task_status`](Self::set_task_status)
306    /// does, and answer with the whole task as this source now reads it — its
307    /// [`Task::delivers`] among what a caller keeping delivered tasks in step needs — or `None`
308    /// when this source holds no such task.
309    ///
310    /// Defaulted to exactly the two calls a caller would otherwise make: [`get_task`] first,
311    /// answering `None` with nothing written when it does, then `set_task_status`, the status
312    /// it answers put on the task read. A source whose status write answers the whole task in
313    /// the same round trip overrides it to save the read.
314    ///
315    /// [`Task::delivers`]: crate::Task::delivers
316    /// [`get_task`]: Self::get_task
317    ///
318    /// # Errors
319    ///
320    /// As [`get_task`](Self::get_task) and [`set_task_status`](Self::set_task_status).
321    async fn set_task_status_reading(
322        &self,
323        id: &NativeId,
324        category: StatusCategory,
325    ) -> Result<Option<Task>, SourceError> {
326        let Some(mut task) = self.get_task(id).await? else {
327            return Ok(None);
328        };
329        let Some(status) = self.set_task_status(id, category).await? else {
330            return Ok(None);
331        };
332        task.status = status;
333        Ok(Some(task))
334    }
335
336    /// Set the priority of one task this source holds, and change nothing else about it,
337    /// answering with the priority as this source now reads it — or `None` when this source
338    /// holds no such task.
339    ///
340    /// [`Priority::None`] clears the priority. Title, content, status, labels, metadata,
341    /// repositories, dependencies and comments are left exactly as they are. Nothing about
342    /// the task's status moves, so the engine re-evaluates no delivered task after it.
343    ///
344    /// Defaulted to [`unwritable_field`], which is what keeps this an addition rather than a
345    /// break. A source declaring [`WriteSupport::Unsupported`], or declaring
346    /// [`Capabilities::priority`] unsupported, is never asked.
347    ///
348    /// # Errors
349    ///
350    /// Returns [`SourceError::Refused`] when this source cannot write a priority, or cannot
351    /// write this one — a board with no option for it, naming the option; and whatever else
352    /// the source could not do the write for.
353    async fn set_task_priority(
354        &self,
355        id: &NativeId,
356        priority: Priority,
357    ) -> Result<Option<Priority>, SourceError> {
358        let _ = (id, priority);
359        Err(unwritable_field(self.kind(), "priority"))
360    }
361
362    /// Replace the content of one task this source holds with `content`, byte for byte, and
363    /// change nothing else about it — or answer `None` when this source holds no such task.
364    ///
365    /// The content is [`Task::content`] exactly as this source reports it: what a later read
366    /// answers there is `content`. Where the source keeps something else inside the same
367    /// backend field — a metadata block in an issue body — that is kept as it was, and so is
368    /// every other member: title, status, priority, labels, metadata, repositories,
369    /// dependencies, project and comments. Nothing about the task's status moves, so the
370    /// engine re-evaluates no delivered task after it.
371    ///
372    /// Defaulted to [`unwritable_field`] on exactly the terms of
373    /// [`set_task_status`](Self::set_task_status). A source declaring
374    /// [`WriteSupport::Unsupported`] is never asked.
375    ///
376    /// # Errors
377    ///
378    /// Returns [`SourceError::Refused`] when this source cannot write a task's content on its
379    /// own, or cannot represent this one; and whatever else the source could not do the write
380    /// for.
381    async fn set_task_content(
382        &self,
383        id: &NativeId,
384        content: &str,
385    ) -> Result<Option<()>, SourceError> {
386        let _ = (id, content);
387        Err(unwritable_field(self.kind(), "content"))
388    }
389
390    /// Replace the [`Task::delivered_by`] of one task this source holds, and change nothing
391    /// else about it — or answer `None` when this source holds no such task.
392    ///
393    /// Every entry is a qualified id, and the list is the whole of it: what the task held
394    /// there before is replaced, not merged. It is the store's to keep in step — the engine
395    /// calls this whenever it writes a task's [`Task::delivers`] — and nothing a person types
396    /// reaches it directly.
397    ///
398    /// Defaulted to [`unwritable_field`] on exactly the terms of
399    /// [`set_task_status`](Self::set_task_status).
400    ///
401    /// [`Task::delivers`]: crate::Task::delivers
402    /// [`Task::delivered_by`]: crate::Task::delivered_by
403    ///
404    /// # Errors
405    ///
406    /// Returns [`SourceError::Refused`] when this source cannot hold the list, and whatever
407    /// else it could not do the write for.
408    async fn set_delivered_by(
409        &self,
410        id: &NativeId,
411        delivered_by: &[TaskRef],
412    ) -> Result<Option<()>, SourceError> {
413        let _ = (id, delivered_by);
414        Err(unwritable_field(self.kind(), "delivered_by"))
415    }
416
417    /// Set one key of the metadata of one task this source holds, and change nothing else
418    /// about it, answering with the task as this source reads it back after the write — or
419    /// `None` when this source holds no such task.
420    ///
421    /// The key is added when the task does not hold it and replaced when it does; every other
422    /// metadata key, and every other field of the task, is left exactly as it was. A `value`
423    /// the task already holds under `key` is a write that changes nothing, and a source owes
424    /// it no write at all. The answer is a read, not an echo: what the engine reports as the
425    /// value is what the returned task holds under `key`.
426    ///
427    /// Nothing about the task's status or its [`Task::delivers`] moves, so the engine
428    /// re-evaluates no delivered task after this write.
429    ///
430    /// Defaulted to [`unwritable_metadata`] on exactly the terms of
431    /// [`set_task_status`](Self::set_task_status): a source that cannot write one key on its
432    /// own needs no edit and refuses by saying so. A source declaring
433    /// [`WriteSupport::Unsupported`] is never asked.
434    ///
435    /// [`Task::delivers`]: crate::Task::delivers
436    ///
437    /// # Errors
438    ///
439    /// Returns [`SourceError::Refused`] when this source cannot write one key of a task's
440    /// metadata on its own, or cannot write this one without changing something else; and
441    /// whatever else the source could not do the write for.
442    async fn set_task_metadata(
443        &self,
444        id: &NativeId,
445        key: &MetadataKey,
446        value: &Value,
447    ) -> Result<Option<Task>, SourceError> {
448        let _ = (id, key, value);
449        Err(unwritable_metadata(self.kind(), MetadataRecord::Task))
450    }
451
452    /// Apply a targeted update to one task this source holds — every field `update` names, and
453    /// nothing else — answering with a [`TaskUpdateOutcome`], or `None` when this source holds
454    /// no such task.
455    ///
456    /// The outcome is everything the engine reports about the call, so it reads nothing of its
457    /// own: the task as this source reads it once the update landed — from the one read it made
458    /// and what it then wrote, where its backend answers a write with what it holds — the
459    /// fields it actually wrote, and the `delivers` the task held before.
460    ///
461    /// A field already holding the requested value is sent no write, and an update in which
462    /// nothing differs sends no write at all. Every field `update` leaves unnamed — labels,
463    /// repositories, project, [`Task::delivered_by`] and comments always among them — is left
464    /// exactly as it is. An update naming one metadata key both to set and to remove is refused
465    /// before anything is written, in the words of [`TaskUpdate::consistent`].
466    ///
467    /// Defaulted to [`TaskUpdate::rewrite`]: read the task, apply the update, and — only when
468    /// anything differs — [`write_task`](Self::write_task) it with its `target` set. That keeps
469    /// this an addition rather than a break, and a source that predates it behaves correctly and
470    /// is merely not minimal; one whose backend can take a field on its own owes an override
471    /// that sends only what differs. A source declaring [`WriteSupport::Unsupported`] is never
472    /// asked.
473    ///
474    /// [`Task::delivered_by`]: crate::Task::delivered_by
475    ///
476    /// # Errors
477    ///
478    /// Returns [`SourceError::Refused`] when the update contradicts itself, when a field it
479    /// names cannot be represented here — a category this source has disabled included — and
480    /// whatever else the source could not do the write for.
481    async fn update_task(
482        &self,
483        id: &NativeId,
484        update: &TaskUpdate,
485    ) -> Result<Option<TaskUpdateOutcome>, SourceError> {
486        update.rewrite(self, id).await
487    }
488
489    /// Set one key of the metadata of one project this source holds, on exactly the terms of
490    /// [`set_task_metadata`](Self::set_task_metadata).
491    ///
492    /// # Errors
493    ///
494    /// As [`set_task_metadata`](Self::set_task_metadata).
495    async fn set_project_metadata(
496        &self,
497        id: &NativeId,
498        key: &MetadataKey,
499        value: &Value,
500    ) -> Result<Option<Project>, SourceError> {
501        let _ = (id, key, value);
502        Err(unwritable_metadata(self.kind(), MetadataRecord::Project))
503    }
504
505    /// Set one key of the metadata of one document this source holds, on exactly the terms of
506    /// [`set_task_metadata`](Self::set_task_metadata).
507    ///
508    /// A source declaring [`Capabilities::documents`] unsupported is never asked, exactly as
509    /// it is never asked for a document read.
510    ///
511    /// # Errors
512    ///
513    /// As [`set_task_metadata`](Self::set_task_metadata).
514    async fn set_document_metadata(
515        &self,
516        id: &NativeId,
517        key: &MetadataKey,
518        value: &Value,
519    ) -> Result<Option<Document>, SourceError> {
520        let _ = (id, key, value);
521        Err(unwritable_metadata(self.kind(), MetadataRecord::Document))
522    }
523
524    /// Remove one task this destination holds, so a copy that could not finish can put
525    /// the destination back the way it found it.
526    ///
527    /// This is not a verb of the product: nothing a user types deletes anything, and a
528    /// copy never deletes an item it did not itself create in the run that is failing.
529    /// It exists because a copy is either complete or it never happened — a half-written
530    /// project has to be run again, and the re-run is the mutation burst that trips a
531    /// hosted destination's rate limiter. Undoing this run's own creates is what removes
532    /// that retry at source.
533    ///
534    /// A source declaring [`WriteSupport::Supported`] owes a real implementation, for the
535    /// reason it owes [`write_task`](Self::write_task) one: the engine will create items
536    /// there, so it has to be able to remove the ones it created. An `id` naming nothing
537    /// is **not** an error — the item is already gone, which is the state this asks for.
538    ///
539    /// # Errors
540    ///
541    /// Returns [`SourceError::Refused`] when this source has no write side, and whatever
542    /// else the source could not remove the item for.
543    async fn delete_task(&self, id: &NativeId) -> Result<(), SourceError> {
544        let _ = id;
545        Err(unwritable(self.kind()))
546    }
547
548    /// Remove one project this destination holds, on exactly the terms of
549    /// [`delete_task`](Self::delete_task).
550    ///
551    /// # Errors
552    ///
553    /// As [`delete_task`](Self::delete_task).
554    async fn delete_project(&self, id: &NativeId) -> Result<(), SourceError> {
555        let _ = id;
556        Err(unwritable(self.kind()))
557    }
558
559    /// Fetch one document by its native id, or `None` when there is no such document.
560    ///
561    /// Defaulted to [`documentless`], which is what keeps documents an addition rather
562    /// than a break: a source with none needs no edit, keeps working, and says so in the
563    /// same words every other document-free source does. A source that has documents
564    /// declares [`Support::Native`](crate::Support::Native) for
565    /// [`Capabilities::documents`] and owes a real implementation here, because that
566    /// declaration is what makes the engine ask.
567    ///
568    /// # Errors
569    ///
570    /// Returns [`SourceError::Refused`] when this source has no documents, and whatever
571    /// else the source could not answer for.
572    async fn get_document(&self, id: &NativeId) -> Result<Option<Document>, SourceError> {
573        let _ = id;
574        Err(documentless(self.kind()))
575    }
576
577    /// One page of the documents matching `query`.
578    ///
579    /// Defaulted on exactly the terms of [`get_document`](Self::get_document). A source
580    /// with no documents refuses rather than answering an empty page: an empty page reads
581    /// as a source that has documents and holds none matching, which is the one wrong
582    /// answer this method can give.
583    ///
584    /// # Errors
585    ///
586    /// As [`get_document`](Self::get_document).
587    async fn query_documents(
588        &self,
589        query: &DocumentQuery,
590        page: &PageRequest,
591    ) -> Result<Page<Document>, SourceError> {
592        let _ = (query, page);
593        Err(documentless(self.kind()))
594    }
595
596    /// Create or update one document, on exactly the terms of
597    /// [`write_task`](Self::write_task).
598    ///
599    /// # Errors
600    ///
601    /// As [`write_task`](Self::write_task).
602    async fn write_document(&self, write: &ItemWrite<Document>) -> Result<NativeId, SourceError> {
603        let _ = write;
604        Err(unwritable(self.kind()))
605    }
606
607    /// Remove one document this destination holds, on exactly the terms of
608    /// [`delete_task`](Self::delete_task).
609    ///
610    /// # Errors
611    ///
612    /// As [`delete_task`](Self::delete_task).
613    async fn delete_document(&self, id: &NativeId) -> Result<(), SourceError> {
614        let _ = id;
615        Err(unwritable(self.kind()))
616    }
617
618    /// One page of the comments on `task`, oldest first, or `None` when this source holds
619    /// no such task.
620    ///
621    /// Defaulted to [`commentless`], which is what keeps comments an addition rather than a
622    /// break: a source with none needs no edit and keeps working. A source whose tasks have
623    /// comments declares [`Support::Native`](crate::Support::Native) for
624    /// [`Capabilities::comments`] and owes a real implementation of all four comment methods,
625    /// because that declaration is what makes the engine ask.
626    ///
627    /// "No such task" is `None` rather than an error, exactly as it is for
628    /// [`get_task`](Self::get_task); a task that exists and has no comments is an empty page.
629    ///
630    /// # Errors
631    ///
632    /// Returns [`SourceError::Refused`] when this source has no comments, and whatever else
633    /// the source could not answer for.
634    async fn task_comments(
635        &self,
636        task: &NativeId,
637        page: &PageRequest,
638    ) -> Result<Option<Page<Comment>>, SourceError> {
639        let _ = (task, page);
640        Err(commentless(self.kind()))
641    }
642
643    /// [`get_task_details`](Self::get_task_details) as a copy reads the tasks it carries: each
644    /// with the first page of its comments `comments` names — and, where the same request can
645    /// carry them, what this source needs to answer [`task_dependencies`](Self::task_dependencies)
646    /// for it without another, since a copy reads every task's edges next.
647    ///
648    /// Defaulted to `get_task_details(ids, Some(comments))`, which is exactly what it answers.
649    /// A source whose detail read is priced by what it selects overrides it with a read that
650    /// also carries the edges, so a copy of a changed task costs its detail read and nothing
651    /// more; one whose reads are free has no reason to.
652    async fn get_task_details_for_copy(
653        &self,
654        ids: &[NativeId],
655        comments: &PageRequest,
656    ) -> Vec<Result<Option<TaskDetailRead>, SourceError>> {
657        self.get_task_details(ids, Some(comments)).await
658    }
659
660    /// Add one comment to `task`, answering with the comment as the source now holds it, or
661    /// `None` when this source holds no such task.
662    ///
663    /// The body is stored byte for byte. A source that records the author itself refuses a
664    /// [`NewComment::author`] rather than dropping it, naming why; a source that cannot
665    /// represent the body refuses it, naming why, rather than escaping it into something
666    /// else.
667    ///
668    /// # Errors
669    ///
670    /// Returns [`SourceError::Refused`] when this source has no comments or cannot be
671    /// written, when it cannot record what it was given, and whatever else it could not do
672    /// the write for.
673    async fn add_comment(
674        &self,
675        task: &NativeId,
676        comment: &NewComment,
677    ) -> Result<Option<Comment>, SourceError> {
678        let _ = (task, comment);
679        Err(commentless(self.kind()))
680    }
681
682    /// Replace the body of the comment `comment` on `task`, answering with the comment as the
683    /// source now holds it, or `None` when this source holds no such task or that task has no
684    /// such comment.
685    ///
686    /// Only the body and the time it last changed move: the id, the author and the time it
687    /// was written are the comment's own.
688    ///
689    /// # Errors
690    ///
691    /// As [`add_comment`](Self::add_comment).
692    async fn edit_comment(
693        &self,
694        task: &NativeId,
695        comment: &NativeId,
696        body: &CommentBody,
697    ) -> Result<Option<Comment>, SourceError> {
698        let _ = (task, comment, body);
699        Err(commentless(self.kind()))
700    }
701
702    /// Remove the comment `comment` from `task`, answering with the id it removed, or `None`
703    /// when this source holds no such task or that task has no such comment.
704    ///
705    /// Unlike [`delete_task`](Self::delete_task), this *is* a verb of the product — a person
706    /// removes a comment they posted — so a comment that is not there is reported as `None`
707    /// for the engine to refuse by name, rather than treated as already gone.
708    ///
709    /// # Errors
710    ///
711    /// As [`add_comment`](Self::add_comment).
712    async fn delete_comment(
713        &self,
714        task: &NativeId,
715        comment: &NativeId,
716    ) -> Result<Option<NativeId>, SourceError> {
717        let _ = (task, comment);
718        Err(commentless(self.kind()))
719    }
720
721    /// Write one comment a copy carries onto `task`: a new one when `existing` is `None`, and
722    /// otherwise the comment `existing`, which a copy wrote before, made to say `copy` — or
723    /// `None` when this source holds no such task or no such comment.
724    ///
725    /// The answer reports [`Comment::origin`] as `copy.origin`, however the source keeps it.
726    ///
727    /// **Defaulted to the hidden marker**, which is right for every source that records a
728    /// comment's author and times itself: the body is written through
729    /// [`add_comment`](Self::add_comment) or [`edit_comment`](Self::edit_comment) with
730    /// [`CommentOrigin::mark`](crate::CommentOrigin::mark) appended, and read back
731    /// [`unmarked`](Comment::unmarked). A source that can store the origin natively — and so
732    /// takes the origin's own id, author and times for the copy — overrides this.
733    ///
734    /// # Errors
735    ///
736    /// As [`add_comment`](Self::add_comment).
737    async fn write_comment_copy(
738        &self,
739        task: &NativeId,
740        existing: Option<&NativeId>,
741        copy: &CommentCopy,
742    ) -> Result<Option<Comment>, SourceError> {
743        let body = CommentBody::new(copy.origin.qualified()?.mark(copy.body.as_str()))?;
744        let written = match existing {
745            Some(comment) => self.edit_comment(task, comment, &body).await?,
746            None => {
747                self.add_comment(task, &NewComment { body, author: None })
748                    .await?
749            }
750        };
751        Ok(written.map(Comment::unmarked))
752    }
753
754    /// Whether this source keeps template answers beside its items at all.
755    ///
756    /// What lets a regenerate tell an item whose answers went missing — a block deleted by
757    /// hand, which the regenerate writes back — from an item of a source that never keeps any,
758    /// where a missing answer is no difference. Defaulted to `false`, as
759    /// [`task_template_answers`](Self::task_template_answers) is defaulted to `None`; a source
760    /// that keeps answers answers `true` here.
761    fn keeps_template_answers(&self) -> bool {
762        false
763    }
764
765    /// The template answers the task `id` was last rendered from, as this source keeps them
766    /// beside the task — or `None` when it keeps none for it, or holds no such task.
767    ///
768    /// Keeping answers is a source's own choice, never an obligation: a source whose items
769    /// are one record in a hosted system has no room beside the item that is not the item, and
770    /// answers written into its content or its metadata would duplicate what the content
771    /// already says. Defaulted to `None`, which is what keeps this an addition rather than a
772    /// break. A source that keeps them owes three things: they are in neither
773    /// [`Task::content`] nor [`Task::metadata`], they are written only by
774    /// [`write_task_rendered`](Self::write_task_rendered) and
775    /// [`set_task_rendering`](Self::set_task_rendering), and they come back here exactly as
776    /// they were written, JSON types intact.
777    ///
778    /// # Errors
779    ///
780    /// Returns a [`SourceError`] when the source could not answer, a record whose answers it
781    /// cannot read included.
782    async fn task_template_answers(
783        &self,
784        id: &NativeId,
785    ) -> Result<Option<BTreeMap<String, Value>>, SourceError> {
786        let _ = id;
787        Ok(None)
788    }
789
790    /// The template answers the document `id` was last rendered from, on exactly the terms of
791    /// [`task_template_answers`](Self::task_template_answers).
792    ///
793    /// # Errors
794    ///
795    /// As [`task_template_answers`](Self::task_template_answers).
796    async fn document_template_answers(
797        &self,
798        id: &NativeId,
799    ) -> Result<Option<BTreeMap<String, Value>>, SourceError> {
800        let _ = id;
801        Ok(None)
802    }
803
804    /// The template answers the project `id` was last rendered from, on exactly the terms of
805    /// [`task_template_answers`](Self::task_template_answers).
806    ///
807    /// # Errors
808    ///
809    /// As [`task_template_answers`](Self::task_template_answers).
810    async fn project_template_answers(
811        &self,
812        id: &NativeId,
813    ) -> Result<Option<BTreeMap<String, Value>>, SourceError> {
814        let _ = id;
815        Ok(None)
816    }
817
818    /// Create or update one task exactly as [`write_task`](Self::write_task) does, keeping
819    /// `answers` — the answers its content was rendered from — beside it in the same write
820    /// where this source keeps answers at all.
821    ///
822    /// The task arrives carrying its provenance under [`MetadataKey::TEMPLATE_KEY`] like any
823    /// other metadata entry. Defaulted to [`write_task`](Self::write_task) alone: a source that
824    /// keeps no answers writes the task and nothing beside it, which is the whole of what it
825    /// owes. A source that keeps them writes the task and the answers together, so a reader
826    /// never finds one without the other.
827    ///
828    /// # Errors
829    ///
830    /// As [`write_task`](Self::write_task).
831    async fn write_task_rendered(
832        &self,
833        write: &ItemWrite<Task>,
834        answers: &BTreeMap<String, Value>,
835    ) -> Result<NativeId, SourceError> {
836        let _ = answers;
837        self.write_task(write).await
838    }
839
840    /// Create or update one document, on exactly the terms of
841    /// [`write_task_rendered`](Self::write_task_rendered).
842    ///
843    /// # Errors
844    ///
845    /// As [`write_document`](Self::write_document).
846    async fn write_document_rendered(
847        &self,
848        write: &ItemWrite<Document>,
849        answers: &BTreeMap<String, Value>,
850    ) -> Result<NativeId, SourceError> {
851        let _ = answers;
852        self.write_document(write).await
853    }
854
855    /// Create or update one project, on exactly the terms of
856    /// [`write_task_rendered`](Self::write_task_rendered).
857    ///
858    /// # Errors
859    ///
860    /// As [`write_project`](Self::write_project).
861    async fn write_project_rendered(
862        &self,
863        write: &ItemWrite<Project>,
864        answers: &BTreeMap<String, Value>,
865    ) -> Result<NativeId, SourceError> {
866        let _ = answers;
867        self.write_project(write).await
868    }
869
870    /// Replace one task's rendering — its content, byte for byte, its
871    /// [`MetadataKey::TEMPLATE_KEY`] entry, set to `provenance`, and the answers it keeps
872    /// beside the task where it keeps any — in one write, and change nothing else about it;
873    /// or answer `None` when this source holds no such task.
874    ///
875    /// The content is [`Task::content`] exactly as a later read reports it, on the terms of
876    /// [`set_task_content`](Self::set_task_content). Title, status, priority, labels, every
877    /// other metadata entry, repositories, dependencies, [`Task::delivers`],
878    /// [`Task::delivered_by`], project and comments are left exactly as they are. The write is
879    /// one write: a reader sees the task as it was or as it is now, never a new content beside
880    /// the old provenance or the old answers.
881    ///
882    /// Defaulted to [`unwritable_field`] on exactly the terms of
883    /// [`set_task_status`](Self::set_task_status). A source declaring
884    /// [`WriteSupport::Unsupported`] is never asked.
885    ///
886    /// [`Task::delivers`]: crate::Task::delivers
887    /// [`Task::delivered_by`]: crate::Task::delivered_by
888    ///
889    /// # Errors
890    ///
891    /// Returns [`SourceError::Refused`] when this source cannot replace a task's rendering on
892    /// its own, or cannot represent this one; and whatever else the source could not do the
893    /// write for.
894    async fn set_task_rendering(
895        &self,
896        id: &NativeId,
897        content: &str,
898        provenance: &Value,
899        answers: &BTreeMap<String, Value>,
900    ) -> Result<Option<()>, SourceError> {
901        let _ = (id, content, provenance, answers);
902        Err(unwritable_field(self.kind(), "rendering"))
903    }
904
905    /// Replace one document's rendering, on exactly the terms of
906    /// [`set_task_rendering`](Self::set_task_rendering). A source declaring
907    /// [`Capabilities::documents`] unsupported is never asked.
908    ///
909    /// # Errors
910    ///
911    /// As [`set_task_rendering`](Self::set_task_rendering).
912    async fn set_document_rendering(
913        &self,
914        id: &NativeId,
915        content: &str,
916        provenance: &Value,
917        answers: &BTreeMap<String, Value>,
918    ) -> Result<Option<()>, SourceError> {
919        let _ = (id, content, provenance, answers);
920        Err(SourceError::Refused {
921            message: format!(
922                "the {} plugin cannot write a document's rendering on its own",
923                self.kind()
924            ),
925        })
926    }
927
928    /// Replace one project's rendering, on exactly the terms of
929    /// [`set_task_rendering`](Self::set_task_rendering): its content, its
930    /// [`MetadataKey::TEMPLATE_KEY`] entry and the answers kept beside it change, and its
931    /// title, status, labels, every other metadata entry, repositories and dependencies are
932    /// left exactly as they are.
933    ///
934    /// # Errors
935    ///
936    /// As [`set_task_rendering`](Self::set_task_rendering).
937    async fn set_project_rendering(
938        &self,
939        id: &NativeId,
940        content: &str,
941        provenance: &Value,
942        answers: &BTreeMap<String, Value>,
943    ) -> Result<Option<()>, SourceError> {
944        let _ = (id, content, provenance, answers);
945        Err(SourceError::Refused {
946            message: format!(
947                "the {} plugin cannot write a project's rendering on its own",
948                self.kind()
949            ),
950        })
951    }
952
953    /// The image assets the task `id` holds, or none when it holds none or this source holds
954    /// no such task.
955    ///
956    /// Defaulted to none, which is what keeps assets an addition rather than a break: a source
957    /// that keeps no assets needs no edit and reports every record as holding none. A source
958    /// declaring [`Capabilities::assets`] native answers what it holds for the record, in any
959    /// order — the engine orders them by the content's first reference.
960    ///
961    /// # Errors
962    ///
963    /// Returns a [`SourceError`] when the source could not answer.
964    async fn task_assets(&self, id: &NativeId) -> Result<Vec<Asset>, SourceError> {
965        let _ = id;
966        Ok(Vec::new())
967    }
968
969    /// The image assets the document `id` holds, on exactly the terms of
970    /// [`task_assets`](Self::task_assets).
971    ///
972    /// # Errors
973    ///
974    /// As [`task_assets`](Self::task_assets).
975    async fn document_assets(&self, id: &NativeId) -> Result<Vec<Asset>, SourceError> {
976        let _ = id;
977        Ok(Vec::new())
978    }
979
980    /// The bytes of the asset `name` the task `id` holds, or `None` when it holds no such asset
981    /// or this source holds no such task.
982    ///
983    /// Defaulted to `None`, on the terms of [`task_assets`](Self::task_assets).
984    ///
985    /// # Errors
986    ///
987    /// Returns a [`SourceError`] when the source could not answer.
988    async fn task_asset(
989        &self,
990        id: &NativeId,
991        name: &AssetName,
992    ) -> Result<Option<Vec<u8>>, SourceError> {
993        let _ = (id, name);
994        Ok(None)
995    }
996
997    /// The bytes of the asset `name` the document `id` holds, on exactly the terms of
998    /// [`task_asset`](Self::task_asset).
999    ///
1000    /// # Errors
1001    ///
1002    /// As [`task_asset`](Self::task_asset).
1003    async fn document_asset(
1004        &self,
1005        id: &NativeId,
1006        name: &AssetName,
1007    ) -> Result<Option<Vec<u8>>, SourceError> {
1008        let _ = (id, name);
1009        Ok(None)
1010    }
1011
1012    /// Create or update one task carrying image assets, in one write: the task as
1013    /// [`write_task`](Self::write_task) writes it — or, with `answers`, as
1014    /// [`write_task_rendered`](Self::write_task_rendered) does — and `assets` as the record's
1015    /// whole asset set, answering with where it landed and the content as stored.
1016    ///
1017    /// Only a source declaring [`Capabilities::assets`] native is asked, and the engine has
1018    /// already checked that every reference in the content names one of `assets` and every one
1019    /// of `assets` is referenced. A source that keeps the bytes beside the record stores each
1020    /// payload under its name, removes every asset the record held that `assets` does not
1021    /// name, and answers the content unchanged. A source that serves them at a URL uploads each
1022    /// payload that carries bytes, reuses the URL [`AssetWrite::recorded_assets`] records for
1023    /// each that does not, and writes the record through
1024    /// [`serve_asset_references`](crate::serve_asset_references) — so its references point at
1025    /// those URLs, its [`MetadataKey::ASSETS_KEY`] records each `{sha256, url}`, and a
1026    /// rendering's `body_digest` stays true of what landed — answering the content it wrote.
1027    ///
1028    /// Defaulted to [`assetless`], which is what a source with no assets answers.
1029    ///
1030    /// # Errors
1031    ///
1032    /// As [`write_task`](Self::write_task), and [`SourceError::Refused`] from a source that
1033    /// keeps no assets.
1034    async fn write_task_with_assets(
1035        &self,
1036        write: &ItemWrite<Task>,
1037        answers: Option<&BTreeMap<String, Value>>,
1038        assets: &AssetWrite,
1039    ) -> Result<AssetsWritten, SourceError> {
1040        let _ = (write, answers, assets);
1041        Err(assetless(self.kind()))
1042    }
1043
1044    /// Create or update one document carrying image assets, on exactly the terms of
1045    /// [`write_task_with_assets`](Self::write_task_with_assets).
1046    ///
1047    /// # Errors
1048    ///
1049    /// As [`write_task_with_assets`](Self::write_task_with_assets).
1050    async fn write_document_with_assets(
1051        &self,
1052        write: &ItemWrite<Document>,
1053        answers: Option<&BTreeMap<String, Value>>,
1054        assets: &AssetWrite,
1055    ) -> Result<AssetsWritten, SourceError> {
1056        let _ = (write, answers, assets);
1057        Err(assetless(self.kind()))
1058    }
1059
1060    /// Replace one task's rendering as [`set_task_rendering`](Self::set_task_rendering) does,
1061    /// and its asset set as [`write_task_with_assets`](Self::write_task_with_assets) does, in
1062    /// one write; or answer `None` when this source holds no such task.
1063    ///
1064    /// Defaulted to [`assetless`].
1065    ///
1066    /// # Errors
1067    ///
1068    /// As [`set_task_rendering`](Self::set_task_rendering), and [`SourceError::Refused`] from a
1069    /// source that keeps no assets.
1070    async fn set_task_rendering_with_assets(
1071        &self,
1072        id: &NativeId,
1073        content: &str,
1074        provenance: &Value,
1075        answers: &BTreeMap<String, Value>,
1076        assets: &AssetWrite,
1077    ) -> Result<Option<AssetsWritten>, SourceError> {
1078        let _ = (id, content, provenance, answers, assets);
1079        Err(assetless(self.kind()))
1080    }
1081
1082    /// Replace one document's rendering and its asset set, on exactly the terms of
1083    /// [`set_task_rendering_with_assets`](Self::set_task_rendering_with_assets).
1084    ///
1085    /// # Errors
1086    ///
1087    /// As [`set_task_rendering_with_assets`](Self::set_task_rendering_with_assets).
1088    async fn set_document_rendering_with_assets(
1089        &self,
1090        id: &NativeId,
1091        content: &str,
1092        provenance: &Value,
1093        answers: &BTreeMap<String, Value>,
1094        assets: &AssetWrite,
1095    ) -> Result<Option<AssetsWritten>, SourceError> {
1096        let _ = (id, content, provenance, answers, assets);
1097        Err(assetless(self.kind()))
1098    }
1099
1100    /// What this source has sent to its backend since it was built and what that spent, or
1101    /// `None` when it does not meter its own requests.
1102    ///
1103    /// Defaulted to `None`, which is what keeps metering an addition rather than a break: a
1104    /// source that does not count its requests needs no edit, and is reported as not
1105    /// metering rather than as having spent nothing. A source that answers owes a running
1106    /// total — see [`Metering`] — because what one command spent is read as the difference
1107    /// between two readings.
1108    ///
1109    /// # Errors
1110    ///
1111    /// Returns a [`SourceError`] when the reading itself could not be taken. A caller
1112    /// reports such a source as not metering; what a command cost is never a reason for the
1113    /// command to fail.
1114    async fn metering(&self) -> Result<Option<Metering>, SourceError> {
1115        Ok(None)
1116    }
1117
1118    /// End one command: drop everything held that a person can change.
1119    ///
1120    /// A command is one unit of work — one invocation of the binary, or whatever a caller
1121    /// holding one engine for many units of work calls between them. Within a command a
1122    /// source may hold what it read and reuse it; across this call it may not. After it
1123    /// returns, a source answers no read and bases no write on item content, statuses, board
1124    /// contents or search results it held before the call. It may keep only identifiers and
1125    /// vocabulary that stay valid in normal use — a repository's node id, a team's workflow
1126    /// states — and only where a lookup that misses one re-reads rather than refusing.
1127    ///
1128    /// Defaulted to doing nothing, which is right for a source that holds nothing between
1129    /// calls or holds only what the rule above lets it keep. A source that holds more owes
1130    /// an override. Never called by the engine on its own: the binary's one command is its
1131    /// whole process, so only a caller that outlives a command calls it.
1132    ///
1133    /// # Errors
1134    ///
1135    /// Returns a [`SourceError`] when the source could not be sure it dropped what it held —
1136    /// ordinarily a hosted plugin that did not answer. A caller should not go on to the next
1137    /// command on that source's earlier reads.
1138    async fn end_command(&self) -> Result<(), SourceError> {
1139        Ok(())
1140    }
1141
1142    /// Who can read where `target` lands, read live from the backend.
1143    ///
1144    /// This is the destination's reality, which the engine holds a declaration against
1145    /// before it lets a write through: a source a configuration declares private receives an
1146    /// item that may only be written somewhere private only while this answers
1147    /// [`Visibility::Private`]. The engine asks immediately before the write it is about, so
1148    /// a source must not answer from anything it read for an earlier write unless its
1149    /// backend's visibility cannot change in between.
1150    ///
1151    /// Defaulted to [`Visibility::Unknown`], which is the answer of a source that cannot say
1152    /// and is never treated as private. A source on this machine answers `Private` — what it
1153    /// writes stays on the host — and a hosted source reads its backend.
1154    ///
1155    /// # Errors
1156    ///
1157    /// Returns a [`SourceError`] when the backend could not be asked or would not answer —
1158    /// a credential lacking the scope the read needs among them. An unreadable visibility is
1159    /// never guessed: the engine refuses the write.
1160    async fn visibility(&self, target: &WriteTarget<'_>) -> Result<Visibility, SourceError> {
1161        let _ = target;
1162        Ok(Visibility::Unknown)
1163    }
1164}
1165
1166/// The factory that turns one configuration block into a live [`TaskSource`].
1167///
1168/// Having the compile-time registry and the subprocess seam be the same shape is
1169/// the whole reason this is a trait rather than a free function.
1170pub trait SourcePlugin: Send + Sync + 'static {
1171    /// The name a configuration document's `plugin:` field names.
1172    fn kind(&self) -> &'static str;
1173
1174    /// The JSON Schema for this plugin's own `config:` block.
1175    fn config_schema(&self) -> Schema;
1176
1177    /// Build a live source from one configuration block.
1178    ///
1179    /// `name` is the configured source's name, for error messages only — a
1180    /// plugin never learns it for any other purpose.
1181    ///
1182    /// # Errors
1183    ///
1184    /// Returns [`SourceError::Config`] when `config` is not valid for this
1185    /// plugin, or [`SourceError::Auth`] when a named credential is absent.
1186    fn build(
1187        &self,
1188        name: &SourceName,
1189        config: &serde_json::Value,
1190        secrets: &dyn SecretResolver,
1191    ) -> Result<Box<dyn TaskSource>, SourceError>;
1192
1193    /// Build a live source from one configuration block, handing it the clock it paces and
1194    /// backs off on.
1195    ///
1196    /// The binary builds every in-process source through this, with the process's one
1197    /// [`SharedClock`] — [`system_clock`](crate::system_clock) unless a test asked for
1198    /// simulated time. Defaulted to [`build`](Self::build), which ignores the clock: a plugin
1199    /// that never waits needs no edit, and one that does overrides this and routes its waits
1200    /// through `clock`.
1201    ///
1202    /// # Errors
1203    ///
1204    /// As [`build`](Self::build).
1205    fn build_with_clock(
1206        &self,
1207        name: &SourceName,
1208        config: &serde_json::Value,
1209        secrets: &dyn SecretResolver,
1210        clock: SharedClock,
1211    ) -> Result<Box<dyn TaskSource>, SourceError> {
1212        let _ = clock;
1213        self.build(name, config, secrets)
1214    }
1215
1216    /// The fields of this plugin's `config:` block that name a filesystem path, as dotted
1217    /// paths into that block.
1218    ///
1219    /// A relative value at one of these, **supplied by a configuration document**, is
1220    /// resolved against the directory holding that document before [`Self::build`] sees it;
1221    /// supplied through the environment or a flag it keeps resolving against the process
1222    /// working directory, because there is no document to rebase it on. A plugin is handed
1223    /// values and no origins, so this declaration is the only way it can say which of its
1224    /// own fields that rule reaches.
1225    ///
1226    /// Defaulted to none, which is what keeps this an addition rather than a break: a
1227    /// plugin whose block holds no path needs no edit, and a caller asks every plugin
1228    /// rather than keeping a table of which ones answer.
1229    // llmlint: ignore[invalid_states_unrepresentable] The identity of a configuration field
1230    // is a name, and no type can make a wrong one unrepresentable here: every string is a
1231    // syntactically valid dotted path, so a newtype would validate nothing and would only
1232    // move where a name that is not a field of *this* plugin is accepted. What decides that
1233    // is whether the name is a property of the schema `config_schema` publishes — a
1234    // per-plugin fact no shared type can hold — so the gate is per plugin and executable:
1235    // `document_relative_fields_are_fields_this_plugin_declares` in
1236    // `onetaskgraph-local-md/tests/plugin.rs`, which a plugin adding a declaration owes its
1237    // own copy of.
1238    fn document_relative_paths(&self) -> &'static [&'static str] {
1239        &[]
1240    }
1241}
1242
1243/// How a plugin reads the credential its configuration names.
1244///
1245/// A configuration document never carries a credential value, only the name of
1246/// the environment variable holding it.
1247pub trait SecretResolver: Send + Sync {
1248    /// The value of `var`, or `None` when nothing defines it.
1249    ///
1250    /// The returned value is never logged and never appears in `Debug` output.
1251    fn get(&self, var: &str) -> Option<SecretString>;
1252}