onetaskgraph_plugin_api/capability.rs
1//! What a source declares it can do natively, so the engine can compensate for
2//! the rest instead of reducing every source to the weakest one's floor.
3
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6
7/// One source's declared abilities.
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
9pub struct Capabilities {
10 /// Whether the source has projects at all.
11 pub projects: Support,
12 /// Whether the source has documents at all.
13 ///
14 /// The same shape as [`projects`](Self::projects), and read the same way: it says what
15 /// the source *holds*, not which predicate it applies. It is therefore **not** one of
16 /// the predicates the second capability rule reaches — there is no wider result set to
17 /// return and nothing for the engine to narrow. A source declaring `Unsupported` is
18 /// never asked for a document at all; the engine reads this once at the handshake,
19 /// exactly as it reads [`TaskSource::writes`](crate::TaskSource::writes), and a
20 /// document read across several sources reports such a source as holding none rather
21 /// than as having failed.
22 ///
23 /// Defaulted to [`Support::Unsupported`] when a wire value omits it, so a plugin that
24 /// predates documents says nothing here and is read as the document-free source it is.
25 // llmlint: ignore[names_match_behavior] SECOND PERMITTED REASON — this restates at a new field the justification recorded across this crate (`Capabilities.max_page_size` below, `PageRequest.limit` in query.rs, `Task::url` in work.rs) and in AGENTS.md's "The plugin contract": the approved contract specifies this field as a `Support` *in the shape `projects` already uses*, and `projects` has carried exactly this meaning — "the source has projects at all" — since before this change, as AGENTS.md and every plugin's verdict table record. A second enum here would say the same thing two ways for two sibling fields and change the serialized form of a frozen handshake. Renaming or re-typing either is the contract owner's call, not this crate's.
26 // llmlint: ignore[invalid_states_unrepresentable] the unrepresentable state named — "has documents, but some document predicate needs compensation" — is not a state this contract has: a `DocumentQuery`'s predicates are the same `text`/`labels`/`project` the task and project queries carry, and `filter_by_label`, `search_title` and `search_content` already declare how the source applies each of them, over whichever entity it is asked for. Adding a per-entity predicate axis is a contract change with no caller yet, and it would have to reach `projects` in the same breath. Recorded in AGENTS.md, "The three capability rules".
27 #[serde(default = "no_documents")]
28 pub documents: Support,
29 /// Whether the source's tasks have comments at all.
30 ///
31 /// Read exactly as [`documents`](Self::documents) is: it says what the source *holds*,
32 /// not which predicate it applies, so the second capability rule does not reach it. A
33 /// source declaring `Unsupported` is never sent a comment call — the engine reads this
34 /// once at the handshake and refuses such a call before anything is read, naming the
35 /// source and its plugin. Adding, editing and removing a comment is a write, so a source
36 /// declaring `Native` is written through only when
37 /// [`TaskSource::writes`](crate::TaskSource::writes) says it can be written at all.
38 ///
39 /// Defaulted to [`Support::Unsupported`] when a wire value omits it, so a plugin that
40 /// predates comments says nothing here and is read as the comment-free source it is.
41 // llmlint: ignore[names_match_behavior, invalid_states_unrepresentable] the reason recorded at `documents` above, at a new field: the contract says whether a source holds a kind of thing in the shape `projects` and `documents` already use, and a second enum here would say the same thing three ways for three sibling fields. Whether comments can be *written* is `TaskSource::writes`, the one write declaration every write of this contract already reads, so a read-only pairing is a source declaring `Native` here and `Unsupported` there rather than a third variant.
42 #[serde(default = "no_comments")]
43 pub comments: Support,
44 /// Whether the source's tasks hold a [`Priority`](crate::Priority) at all.
45 ///
46 /// Read exactly as [`documents`](Self::documents) and [`comments`](Self::comments) are:
47 /// it says what the source *holds*, not which predicate it applies, so the second
48 /// capability rule does not reach it. A source declaring `Unsupported` reports every
49 /// task's priority as `none`, and the engine never hands it one that is not: a copy
50 /// carrying another priority to it, and a `task priority set` naming it, are both refused
51 /// before the source is asked, naming the source and the field.
52 ///
53 /// Defaulted to [`Support::Unsupported`] when a wire value omits it, so a plugin that
54 /// predates priorities says nothing here and is never handed a priority it would drop.
55 // llmlint: ignore[names_match_behavior, invalid_states_unrepresentable] the reason recorded at `documents` above, at a new field: the contract says whether a source holds a kind of thing in the shape `projects`, `documents` and `comments` already use, and a second enum here would say the same thing four ways for four sibling fields. Whether a priority can be *written* is `TaskSource::writes`, the one write declaration every write of this contract already reads.
56 #[serde(default = "no_priority")]
57 pub priority: Support,
58 /// Whether the source keeps only the tasks whose priority a query lists, itself.
59 ///
60 /// A predicate, and so one the second capability rule reaches: a source declaring
61 /// `Unsupported` ignores [`TaskQuery::priorities`](crate::TaskQuery::priorities) and
62 /// returns the wider set, and the engine narrows it. Its own member rather than a reading
63 /// of [`priority`](Self::priority), because holding a priority and filtering by one are
64 /// two abilities — a board holds a priority on a field it cannot be asked to filter by.
65 ///
66 /// Defaulted to [`Support::Unsupported`] when a wire value omits it, so a plugin that
67 /// predates priorities is narrowed by the engine rather than trusted to have filtered.
68 #[serde(default = "no_priority_filter")]
69 pub filter_by_priority: Support,
70 /// Whether the source keeps only the tasks a query's
71 /// [`TaskQuery::commented_since`](crate::TaskQuery::commented_since) selects, itself: a
72 /// task one of whose comments was created or last edited at or after the instant.
73 ///
74 /// A predicate, and so one the second capability rule reaches: a source declaring
75 /// `Unsupported` ignores the instant and returns the wider set, and the engine narrows it
76 /// — by reading **that source's comments, task by task**, for every task the source's
77 /// other predicates kept. That is correct and it is not cheap, which is why a source that
78 /// can ask its store the narrower question declares `Native`. A source whose tasks have no
79 /// [`comments`](Self::comments) at all holds no comment activity, so the engine keeps none
80 /// of its tasks without asking it anything.
81 ///
82 /// Defaulted to [`Support::Unsupported`] when a wire value omits it, so a plugin that
83 /// predates the predicate is narrowed by the engine rather than trusted to have filtered.
84 #[serde(default = "no_comment_activity_filter")]
85 pub filter_by_comment_activity: Support,
86 /// Whether the source can select tasks belonging to no project.
87 pub orphan_tasks: Support,
88 /// Whether the source filters by label itself.
89 pub filter_by_label: Support,
90 /// Whether the source filters by status itself.
91 pub filter_by_status: Support,
92 /// Whether the source searches titles itself.
93 pub search_title: Support,
94 /// Whether the source searches bodies itself.
95 pub search_content: Support,
96 /// How far the source can walk task dependencies.
97 pub task_dependencies: DependencySupport,
98 /// How far the source can walk project dependencies.
99 pub project_dependencies: DependencySupport,
100 /// The largest page the source will serve. At least 1 — a source that serves no rows
101 /// cannot be paged, and every implementation rejects zero where its config is read.
102 // llmlint: ignore[invalid_states_unrepresentable] this field's wire shape is frozen by the plugin contract every source is written against; only the contract's owner may change it, and tightening it is post-build follow-up.
103 // llmlint: ignore[boundary_inputs_validated] the boundary that reads a user's configuration does reject zero — `CapabilityConfig::max_page_size` (onetaskgraph-in-memory/src/config.rs) is a `NonZeroU32` and names the setting when it refuses. What stays a plain `u32` is this frozen contract field, which only the contract's owner may narrow — AGENTS.md, "The plugin contract".
104 pub max_page_size: u32,
105}
106
107/// What [`Capabilities::documents`] means when a wire value does not carry it.
108///
109/// A named function rather than a `Default` on [`Support`], which has no sensible default
110/// of its own: an absent *predicate* declaration is a plugin that did not answer, while an
111/// absent document declaration is a plugin written before there were any.
112fn no_documents() -> Support {
113 Support::Unsupported
114}
115
116/// What [`Capabilities::comments`] means when a wire value does not carry it: a plugin
117/// written before there were comments, on the terms [`no_documents`] gives.
118fn no_comments() -> Support {
119 Support::Unsupported
120}
121
122/// What [`Capabilities::priority`] means when a wire value does not carry it: a plugin
123/// written before there were priorities, on the terms [`no_documents`] gives.
124fn no_priority() -> Support {
125 Support::Unsupported
126}
127
128/// What [`Capabilities::filter_by_priority`] means when a wire value does not carry it: a
129/// plugin that has never heard of the predicate, and so ignores it — which rule 2 already
130/// makes the one safe reading.
131fn no_priority_filter() -> Support {
132 Support::Unsupported
133}
134
135/// What [`Capabilities::filter_by_comment_activity`] means when a wire value does not carry
136/// it: a plugin that has never heard of the predicate, on the terms [`no_priority_filter`]
137/// gives.
138fn no_comment_activity_filter() -> Support {
139 Support::Unsupported
140}
141
142/// Whether a source applies one predicate itself.
143///
144/// Keeps an `Unsupported` variant because in-memory compensation for a filter or
145/// a search is sound: the engine over-fetches and narrows. Do not conflate this
146/// with [`DependencySupport`], which has no such variant.
147#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
148#[serde(rename_all = "kebab-case")]
149pub enum Support {
150 /// The source applies this predicate itself.
151 Native,
152 /// The source ignores this predicate; the engine narrows the wider result.
153 Unsupported,
154}
155
156impl Support {
157 /// Whether the source applies the predicate itself.
158 #[must_use]
159 pub fn is_native(self) -> bool {
160 matches!(self, Self::Native)
161 }
162}
163
164/// How far a source can walk its own dependency edges.
165///
166/// There is deliberately **no** unsupported variant: dependency traversal is a
167/// guaranteed capability of this product, not one a source may opt out of. A
168/// source that cannot report an item's forward edges cannot implement
169/// [`TaskSource`](crate::TaskSource). The weakest declaration is
170/// [`ForwardOnly`](Self::ForwardOnly), which the engine answers in reverse by a
171/// bounded scan and reports as emulated.
172#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
173#[serde(rename_all = "kebab-case")]
174pub enum DependencySupport {
175 /// The source answers both directions itself.
176 BothDirections,
177 /// The source answers forward edges; the engine emulates the reverse.
178 ForwardOnly,
179}
180
181impl DependencySupport {
182 /// Whether the source answers the reverse direction itself.
183 #[must_use]
184 pub fn answers_reverse(self) -> bool {
185 matches!(self, Self::BothDirections)
186 }
187}