code_ranker_plugin_api/preset.rs
1//! The Prompt-Generator [`Preset`] DTO.
2//!
3//! A `Preset` is **prompt-generator domain data**, not part of the parser
4//! contract: a plugin *produces* its set (via
5//! [`LanguagePlugin::presets`](crate::plugin::LanguagePlugin::presets)), but every
6//! other consumer — the report snapshot, the `recommend` console/prompt views —
7//! only *reads* presets and never parses anything. The type therefore lives here,
8//! away from [`plugin`](crate::plugin), so those reporting consumers do not couple
9//! to the parsing contract just to name this struct.
10
11use serde::{Deserialize, Serialize};
12
13/// The language-neutral **prompt scaffolding** the Prompt-Generator wraps a
14/// [`Preset`] in — the framing prose around a principle (intro, the doc-read
15/// note, the task protocol, the focus line, and the dependency-cycle note).
16/// **Data, not code**: it lives in the metric catalog (`builtin.toml [prompt]`)
17/// and is carried in the snapshot, so the CLI's `prompt` format and the HTML
18/// viewer's Prompt Generator render the same text from one source. `{id}` in a
19/// `task` line is substituted with the active preset id at render time.
20#[derive(Debug, Clone, Default, Serialize, Deserialize)]
21pub struct PromptTemplate {
22 /// One-line intent shown under the principle title.
23 #[serde(default)]
24 pub intro: String,
25 /// Shown after the `doc_url` link: read the full principle first.
26 #[serde(default)]
27 pub doc_note: String,
28 /// The task-protocol bullet lines (one entry per bullet).
29 #[serde(default)]
30 pub task: Vec<String>,
31 /// The closing emphasis line.
32 #[serde(default)]
33 pub focus: String,
34 /// Note prepended to a single dependency-cycle's module list.
35 #[serde(default)]
36 pub cycle_note: String,
37}
38
39/// A Prompt-Generator preset (a refactoring principle): a ready-to-paste AI
40/// instruction plus how the UI seeds the node selection for it. Each plugin
41/// builds its own set from config via [`LanguagePlugin::presets`](crate::plugin::LanguagePlugin::presets)
42/// (the common catalog plus any language-specific presets).
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct Preset {
45 /// Stable id / short code shown on the button (e.g. `"ADP"`).
46 pub id: String,
47 /// Button label (usually the id).
48 pub label: String,
49 /// Full principle title (first heading of the generated prompt).
50 pub title: String,
51 /// The prompt body (Markdown, language-neutral by default).
52 pub prompt: String,
53 /// Link to the full principle doc, if any.
54 #[serde(default, skip_serializing_if = "Option::is_none")]
55 pub doc_url: Option<String>,
56 /// The metric the recommended-node list sorts by (an attribute key, or the
57 /// pseudo-metric `"cycle"`).
58 pub sort_metric: String,
59 /// Which connection sets the preset pre-selects: any of `"in"`/`"out"`/`"common"`.
60 #[serde(default, skip_serializing_if = "Vec::is_empty")]
61 pub connections: Vec<String>,
62}