Skip to main content

lsp_max_protocol/
custom_methods.rs

1use crate::lsp_3_18::LspRequest as Request;
2use crate::*;
3
4// ---------------------------------------------------------------------------
5// Method name constants for the 11 new max/* methods
6// ---------------------------------------------------------------------------
7
8/// max/hook — Register or query hook descriptors. Returns all hooks if no id given.
9pub const METHOD_HOOK: &str = "max/hook";
10
11/// max/hookGraph — Return the directed hook dependency graph rooted at an optional node.
12pub const METHOD_HOOK_GRAPH: &str = "max/hookGraph";
13
14/// max/chain — Return chain descriptors. Returns all chains if no chain_id given.
15pub const METHOD_CHAIN: &str = "max/chain";
16
17/// max/propagate — Propagate a signal through a chain or from a hook. Returns affected nodes and receipts.
18pub const METHOD_PROPAGATE: &str = "max/propagate";
19
20/// max/autonomicLoop — Query or trigger an autonomic (self-regulating) loop. Returns loop status.
21pub const METHOD_AUTONOMIC_LOOP: &str = "max/autonomicLoop";
22
23/// max/manifoldSnapshot — Return a full manifold snapshot: conformance, hooks, chains, receipts.
24pub const METHOD_MANIFOLD_SNAPSHOT: &str = "max/manifoldSnapshot";
25
26/// max/lawfulTransition — Assert a phase transition is lawful against all active LawAxes. Returns violated laws.
27pub const METHOD_LAWFUL_TRANSITION: &str = "max/lawfulTransition";
28
29/// max/admission — Admissibility gate. Returns Admitted/Refused/Unknown. Never collapses Unknown.
30pub const METHOD_ADMISSION: &str = "max/admission";
31
32/// max/refusal — Explicit refusal gate. Records a refused LawAxis with rationale and receipt.
33pub const METHOD_REFUSAL: &str = "max/refusal";
34
35/// max/replay — Replay an event log against a snapshot and return conformance evidence.
36pub const METHOD_REPLAY: &str = "max/replay";
37
38/// max/releaseActuation — Actuate a release if and only if the ConformanceVector admits it. Strict mode blocks on Unknown.
39pub const METHOD_RELEASE_ACTUATION: &str = "max/releaseActuation";
40
41/// max/lsif — Stream the current registry state as an exhaustive LSIF NDJSON graph.
42pub const METHOD_LSIF_EXPORT: &str = "max/lsif";
43
44// Request implementations
45
46pub enum MaxSnapshot {}
47impl Request for MaxSnapshot {
48    type Params = ();
49    type Result = SnapshotId;
50    const METHOD: &'static str = "max/snapshot";
51}
52
53pub enum MaxConformanceVector {}
54impl Request for MaxConformanceVector {
55    type Params = SnapshotId;
56    type Result = ConformanceVector;
57    const METHOD: &'static str = "max/conformanceVector";
58}
59
60pub enum MaxExplainDiagnostic {}
61impl Request for MaxExplainDiagnostic {
62    type Params = String; // diagnostic_id
63    type Result = MaxDiagnostic;
64    const METHOD: &'static str = "max/explainDiagnostic";
65}
66
67pub enum MaxRepairPlan {}
68impl Request for MaxRepairPlan {
69    type Params = String; // diagnostic_id or law_id
70    type Result = Vec<MaxCodeAction>;
71    const METHOD: &'static str = "max/repairPlan";
72}
73
74pub enum MaxApplyRepairTransaction {}
75impl Request for MaxApplyRepairTransaction {
76    type Params = MaxCodeAction;
77    type Result = Receipt;
78    const METHOD: &'static str = "max/applyRepairTransaction";
79}
80
81pub enum MaxExportAnalysisBundle {}
82impl Request for MaxExportAnalysisBundle {
83    type Params = SnapshotId;
84    type Result = AnalysisBundle;
85    const METHOD: &'static str = "max/exportAnalysisBundle";
86}
87
88pub enum MaxRunGate {}
89impl Request for MaxRunGate {
90    type Params = GateId;
91    type Result = bool;
92    const METHOD: &'static str = "max/runGate";
93}
94
95pub enum MaxClearDiagnostic {}
96impl Request for MaxClearDiagnostic {
97    type Params = String; // diagnostic_id
98    type Result = ();
99    const METHOD: &'static str = "max/clearDiagnostic";
100}
101
102pub enum MaxReceipt {}
103impl Request for MaxReceipt {
104    type Params = String; // receipt_id
105    type Result = Receipt;
106    const METHOD: &'static str = "max/receipt";
107}
108
109// New doctrine methods
110
111pub enum MaxHook {}
112impl Request for MaxHook {
113    type Params = Option<String>; // optional hook_id; None = list all
114    type Result = Vec<HookDescriptor>;
115    const METHOD: &'static str = "max/hook";
116}
117
118pub enum MaxHookGraph {}
119impl Request for MaxHookGraph {
120    type Params = Option<String>; // optional root node_id
121    type Result = Vec<HookGraphNode>;
122    const METHOD: &'static str = "max/hookGraph";
123}
124
125pub enum MaxChain {}
126impl Request for MaxChain {
127    type Params = Option<String>; // optional chain_id
128    type Result = Vec<ChainDescriptor>;
129    const METHOD: &'static str = "max/chain";
130}
131
132pub enum MaxPropagate {}
133impl Request for MaxPropagate {
134    type Params = String; // chain_id or hook_id to propagate from
135    type Result = PropagationResult;
136    const METHOD: &'static str = "max/propagate";
137}
138
139pub enum MaxAutonomicLoop {}
140impl Request for MaxAutonomicLoop {
141    type Params = Option<String>; // optional loop_id
142    type Result = AutonomicLoopStatus;
143    const METHOD: &'static str = "max/autonomicLoop";
144}
145
146pub enum MaxManifoldSnapshot {}
147impl Request for MaxManifoldSnapshot {
148    type Params = SnapshotId;
149    type Result = ManifoldSnapshot;
150    const METHOD: &'static str = "max/manifoldSnapshot";
151}
152
153pub enum MaxLawfulTransition {}
154impl Request for MaxLawfulTransition {
155    type Params = TransitionAttempt;
156    type Result = LawfulTransitionResult;
157    const METHOD: &'static str = "max/lawfulTransition";
158}
159
160pub enum MaxAdmission {}
161impl Request for MaxAdmission {
162    type Params = LawAxis;
163    type Result = AdmissionResult;
164    const METHOD: &'static str = "max/admission";
165}
166
167pub enum MaxRefusal {}
168impl Request for MaxRefusal {
169    type Params = LawAxis;
170    type Result = RefusalResult;
171    const METHOD: &'static str = "max/refusal";
172}
173
174pub enum MaxReplay {}
175impl Request for MaxReplay {
176    type Params = SnapshotId;
177    type Result = ReplayResult;
178    const METHOD: &'static str = "max/replay";
179}
180
181pub enum MaxReleaseActuation {}
182impl Request for MaxReleaseActuation {
183    type Params = SnapshotId;
184    type Result = ReleaseActuationResult;
185    const METHOD: &'static str = "max/releaseActuation";
186}
187
188// ── Rule-pack protocol methods (ERRC Innovation 2 + 4) ────────────────────
189
190/// max/rulePacks — list all active rule packs with their metadata and
191/// dependency graph.
192pub const METHOD_RULE_PACKS: &str = "max/rulePacks";
193
194/// max/rulePackStatus — return the conformance status contributed by a single
195/// rule pack: which of its rules fired, on which files, and the resulting
196/// per-axis verdict.
197pub const METHOD_RULE_PACK_STATUS: &str = "max/rulePackStatus";
198
199/// max/rulePackDiff — compare two snapshots (by seq number) and return which
200/// rule-pack findings were added, removed, or unchanged.
201pub const METHOD_RULE_PACK_DIFF: &str = "max/rulePackDiff";
202
203/// max/workspaceConformance — return the workspace-level ConformanceVector:
204/// the aggregate of all per-file vectors across all open documents.
205/// Refused axes propagate from any file; axes with no coverage remain Unknown.
206pub const METHOD_WORKSPACE_CONFORMANCE: &str = "max/workspaceConformance";
207
208/// Rule-pack descriptor returned by `max/rulePacks`.
209#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
210pub struct RulePackDescriptor {
211    /// Pack identifier.
212    pub id: String,
213    /// Pack semantic version.
214    pub version: String,
215    /// Rule IDs contained in this pack.
216    pub rule_ids: Vec<String>,
217    /// Packs this pack depends on.
218    pub depends_on: Vec<String>,
219    /// Number of rules that fired in the last workspace scan.
220    pub active_rule_count: usize,
221}
222
223/// Per-pack status returned by `max/rulePackStatus`.
224#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
225pub struct RulePackStatusResult {
226    /// Pack identifier.
227    pub pack_id: String,
228    /// Rules that fired, grouped by file URI.
229    pub findings_by_uri: std::collections::HashMap<String, Vec<String>>,
230    /// The ConformanceVector contribution from this pack alone.
231    pub conformance: ConformanceVector,
232}
233
234/// Diff entry returned by `max/rulePackDiff`.
235#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
236pub struct RulePackDiffEntry {
237    /// Rule ID of the changed finding.
238    pub rule_id: String,
239    /// File URI.
240    pub uri: String,
241    /// Line number (0-based).
242    pub line: u32,
243    /// `"added"`, `"removed"`, or `"unchanged"`.
244    pub change: String,
245}
246
247pub enum MaxRulePacks {}
248impl Request for MaxRulePacks {
249    type Params = ();
250    type Result = Vec<RulePackDescriptor>;
251    const METHOD: &'static str = "max/rulePacks";
252}
253
254pub enum MaxRulePackStatus {}
255impl Request for MaxRulePackStatus {
256    type Params = String; // pack_id
257    type Result = RulePackStatusResult;
258    const METHOD: &'static str = "max/rulePackStatus";
259}
260
261pub enum MaxRulePackDiff {}
262impl Request for MaxRulePackDiff {
263    type Params = (u64, u64); // (seq_before, seq_after)
264    type Result = Vec<RulePackDiffEntry>;
265    const METHOD: &'static str = "max/rulePackDiff";
266}
267
268pub enum MaxWorkspaceConformance {}
269impl Request for MaxWorkspaceConformance {
270    type Params = ();
271    type Result = ConformanceVector;
272    const METHOD: &'static str = "max/workspaceConformance";
273}