Skip to main content

harn_hostlib/
schemas.rs

1//! Embedded JSON Schemas for every hostlib host method.
2//!
3//! Schemas live at `schemas/<module>/<method>.{request,response}.json` and
4//! are baked into the crate at compile time via `include_str!`. They're the
5//! source of truth for hostlib request/response compatibility: the schema
6//! files ship with the crate (see the `include` field in `Cargo.toml`),
7//! and consumers fetch them through this module.
8//!
9//! Schemas use JSON Schema draft 2020-12.
10
11/// Direction of a schema (request body vs. response body).
12#[derive(Clone, Copy, Debug, PartialEq, Eq)]
13pub enum SchemaKind {
14    /// Schema for the *input* of a host method.
15    Request,
16    /// Schema for the *output* of a host method.
17    Response,
18}
19
20/// One `(module, method, kind, schema_text)` tuple for every shipped schema.
21///
22/// Embedders use this catalog to:
23/// - assert that every registered builtin has a matching schema (drift test);
24/// - export the schemas to downstream consumers;
25/// - validate live request/response payloads in tests.
26pub const SCHEMAS: &[(&str, &str, SchemaKind, &str)] = &[
27    // ast/
28    (
29        "ast",
30        "parse_file",
31        SchemaKind::Request,
32        include_str!("../schemas/ast/parse_file.request.json"),
33    ),
34    (
35        "ast",
36        "parse_file",
37        SchemaKind::Response,
38        include_str!("../schemas/ast/parse_file.response.json"),
39    ),
40    (
41        "ast",
42        "symbols",
43        SchemaKind::Request,
44        include_str!("../schemas/ast/symbols.request.json"),
45    ),
46    (
47        "ast",
48        "symbols",
49        SchemaKind::Response,
50        include_str!("../schemas/ast/symbols.response.json"),
51    ),
52    (
53        "ast",
54        "outline",
55        SchemaKind::Request,
56        include_str!("../schemas/ast/outline.request.json"),
57    ),
58    (
59        "ast",
60        "outline",
61        SchemaKind::Response,
62        include_str!("../schemas/ast/outline.response.json"),
63    ),
64    (
65        "ast",
66        "parse_errors",
67        SchemaKind::Request,
68        include_str!("../schemas/ast/parse_errors.request.json"),
69    ),
70    (
71        "ast",
72        "parse_errors",
73        SchemaKind::Response,
74        include_str!("../schemas/ast/parse_errors.response.json"),
75    ),
76    (
77        "ast",
78        "undefined_names",
79        SchemaKind::Request,
80        include_str!("../schemas/ast/undefined_names.request.json"),
81    ),
82    (
83        "ast",
84        "undefined_names",
85        SchemaKind::Response,
86        include_str!("../schemas/ast/undefined_names.response.json"),
87    ),
88    (
89        "ast",
90        "function_body",
91        SchemaKind::Request,
92        include_str!("../schemas/ast/function_body.request.json"),
93    ),
94    (
95        "ast",
96        "function_body",
97        SchemaKind::Response,
98        include_str!("../schemas/ast/function_body.response.json"),
99    ),
100    (
101        "ast",
102        "function_bodies",
103        SchemaKind::Request,
104        include_str!("../schemas/ast/function_bodies.request.json"),
105    ),
106    (
107        "ast",
108        "function_bodies",
109        SchemaKind::Response,
110        include_str!("../schemas/ast/function_bodies.response.json"),
111    ),
112    (
113        "ast",
114        "extract_imports",
115        SchemaKind::Request,
116        include_str!("../schemas/ast/extract_imports.request.json"),
117    ),
118    (
119        "ast",
120        "extract_imports",
121        SchemaKind::Response,
122        include_str!("../schemas/ast/extract_imports.response.json"),
123    ),
124    (
125        "ast",
126        "symbol_extract",
127        SchemaKind::Request,
128        include_str!("../schemas/ast/symbol_extract.request.json"),
129    ),
130    (
131        "ast",
132        "symbol_extract",
133        SchemaKind::Response,
134        include_str!("../schemas/ast/symbol_extract.response.json"),
135    ),
136    (
137        "ast",
138        "symbol_delete",
139        SchemaKind::Request,
140        include_str!("../schemas/ast/symbol_delete.request.json"),
141    ),
142    (
143        "ast",
144        "symbol_delete",
145        SchemaKind::Response,
146        include_str!("../schemas/ast/symbol_delete.response.json"),
147    ),
148    (
149        "ast",
150        "symbol_replace",
151        SchemaKind::Request,
152        include_str!("../schemas/ast/symbol_replace.request.json"),
153    ),
154    (
155        "ast",
156        "symbol_replace",
157        SchemaKind::Response,
158        include_str!("../schemas/ast/symbol_replace.response.json"),
159    ),
160    (
161        "ast",
162        "bracket_balance",
163        SchemaKind::Request,
164        include_str!("../schemas/ast/bracket_balance.request.json"),
165    ),
166    (
167        "ast",
168        "bracket_balance",
169        SchemaKind::Response,
170        include_str!("../schemas/ast/bracket_balance.response.json"),
171    ),
172    // code_index/
173    (
174        "code_index",
175        "query",
176        SchemaKind::Request,
177        include_str!("../schemas/code_index/query.request.json"),
178    ),
179    (
180        "code_index",
181        "query",
182        SchemaKind::Response,
183        include_str!("../schemas/code_index/query.response.json"),
184    ),
185    (
186        "code_index",
187        "rebuild",
188        SchemaKind::Request,
189        include_str!("../schemas/code_index/rebuild.request.json"),
190    ),
191    (
192        "code_index",
193        "rebuild",
194        SchemaKind::Response,
195        include_str!("../schemas/code_index/rebuild.response.json"),
196    ),
197    (
198        "code_index",
199        "stats",
200        SchemaKind::Request,
201        include_str!("../schemas/code_index/stats.request.json"),
202    ),
203    (
204        "code_index",
205        "stats",
206        SchemaKind::Response,
207        include_str!("../schemas/code_index/stats.response.json"),
208    ),
209    (
210        "code_index",
211        "imports_for",
212        SchemaKind::Request,
213        include_str!("../schemas/code_index/imports_for.request.json"),
214    ),
215    (
216        "code_index",
217        "imports_for",
218        SchemaKind::Response,
219        include_str!("../schemas/code_index/imports_for.response.json"),
220    ),
221    (
222        "code_index",
223        "importers_of",
224        SchemaKind::Request,
225        include_str!("../schemas/code_index/importers_of.request.json"),
226    ),
227    (
228        "code_index",
229        "importers_of",
230        SchemaKind::Response,
231        include_str!("../schemas/code_index/importers_of.response.json"),
232    ),
233    // code_index — file table accessors
234    (
235        "code_index",
236        "path_to_id",
237        SchemaKind::Request,
238        include_str!("../schemas/code_index/path_to_id.request.json"),
239    ),
240    (
241        "code_index",
242        "path_to_id",
243        SchemaKind::Response,
244        include_str!("../schemas/code_index/path_to_id.response.json"),
245    ),
246    (
247        "code_index",
248        "id_to_path",
249        SchemaKind::Request,
250        include_str!("../schemas/code_index/id_to_path.request.json"),
251    ),
252    (
253        "code_index",
254        "id_to_path",
255        SchemaKind::Response,
256        include_str!("../schemas/code_index/id_to_path.response.json"),
257    ),
258    (
259        "code_index",
260        "file_ids",
261        SchemaKind::Request,
262        include_str!("../schemas/code_index/file_ids.request.json"),
263    ),
264    (
265        "code_index",
266        "file_ids",
267        SchemaKind::Response,
268        include_str!("../schemas/code_index/file_ids.response.json"),
269    ),
270    (
271        "code_index",
272        "file_meta",
273        SchemaKind::Request,
274        include_str!("../schemas/code_index/file_meta.request.json"),
275    ),
276    (
277        "code_index",
278        "file_meta",
279        SchemaKind::Response,
280        include_str!("../schemas/code_index/file_meta.response.json"),
281    ),
282    (
283        "code_index",
284        "file_hash",
285        SchemaKind::Request,
286        include_str!("../schemas/code_index/file_hash.request.json"),
287    ),
288    (
289        "code_index",
290        "file_hash",
291        SchemaKind::Response,
292        include_str!("../schemas/code_index/file_hash.response.json"),
293    ),
294    // code_index — cached reads
295    (
296        "code_index",
297        "read_range",
298        SchemaKind::Request,
299        include_str!("../schemas/code_index/read_range.request.json"),
300    ),
301    (
302        "code_index",
303        "read_range",
304        SchemaKind::Response,
305        include_str!("../schemas/code_index/read_range.response.json"),
306    ),
307    (
308        "code_index",
309        "reindex_file",
310        SchemaKind::Request,
311        include_str!("../schemas/code_index/reindex_file.request.json"),
312    ),
313    (
314        "code_index",
315        "reindex_file",
316        SchemaKind::Response,
317        include_str!("../schemas/code_index/reindex_file.response.json"),
318    ),
319    (
320        "code_index",
321        "trigram_query",
322        SchemaKind::Request,
323        include_str!("../schemas/code_index/trigram_query.request.json"),
324    ),
325    (
326        "code_index",
327        "trigram_query",
328        SchemaKind::Response,
329        include_str!("../schemas/code_index/trigram_query.response.json"),
330    ),
331    (
332        "code_index",
333        "extract_trigrams",
334        SchemaKind::Request,
335        include_str!("../schemas/code_index/extract_trigrams.request.json"),
336    ),
337    (
338        "code_index",
339        "extract_trigrams",
340        SchemaKind::Response,
341        include_str!("../schemas/code_index/extract_trigrams.response.json"),
342    ),
343    (
344        "code_index",
345        "word_get",
346        SchemaKind::Request,
347        include_str!("../schemas/code_index/word_get.request.json"),
348    ),
349    (
350        "code_index",
351        "word_get",
352        SchemaKind::Response,
353        include_str!("../schemas/code_index/word_get.response.json"),
354    ),
355    (
356        "code_index",
357        "deps_get",
358        SchemaKind::Request,
359        include_str!("../schemas/code_index/deps_get.request.json"),
360    ),
361    (
362        "code_index",
363        "deps_get",
364        SchemaKind::Response,
365        include_str!("../schemas/code_index/deps_get.response.json"),
366    ),
367    (
368        "code_index",
369        "outline_get",
370        SchemaKind::Request,
371        include_str!("../schemas/code_index/outline_get.request.json"),
372    ),
373    (
374        "code_index",
375        "outline_get",
376        SchemaKind::Response,
377        include_str!("../schemas/code_index/outline_get.response.json"),
378    ),
379    // code_index — change log
380    (
381        "code_index",
382        "current_seq",
383        SchemaKind::Request,
384        include_str!("../schemas/code_index/current_seq.request.json"),
385    ),
386    (
387        "code_index",
388        "current_seq",
389        SchemaKind::Response,
390        include_str!("../schemas/code_index/current_seq.response.json"),
391    ),
392    (
393        "code_index",
394        "changes_since",
395        SchemaKind::Request,
396        include_str!("../schemas/code_index/changes_since.request.json"),
397    ),
398    (
399        "code_index",
400        "changes_since",
401        SchemaKind::Response,
402        include_str!("../schemas/code_index/changes_since.response.json"),
403    ),
404    (
405        "code_index",
406        "version_record",
407        SchemaKind::Request,
408        include_str!("../schemas/code_index/version_record.request.json"),
409    ),
410    (
411        "code_index",
412        "version_record",
413        SchemaKind::Response,
414        include_str!("../schemas/code_index/version_record.response.json"),
415    ),
416    // code_index — agents + locks
417    (
418        "code_index",
419        "agent_register",
420        SchemaKind::Request,
421        include_str!("../schemas/code_index/agent_register.request.json"),
422    ),
423    (
424        "code_index",
425        "agent_register",
426        SchemaKind::Response,
427        include_str!("../schemas/code_index/agent_register.response.json"),
428    ),
429    (
430        "code_index",
431        "agent_heartbeat",
432        SchemaKind::Request,
433        include_str!("../schemas/code_index/agent_heartbeat.request.json"),
434    ),
435    (
436        "code_index",
437        "agent_heartbeat",
438        SchemaKind::Response,
439        include_str!("../schemas/code_index/agent_heartbeat.response.json"),
440    ),
441    (
442        "code_index",
443        "agent_unregister",
444        SchemaKind::Request,
445        include_str!("../schemas/code_index/agent_unregister.request.json"),
446    ),
447    (
448        "code_index",
449        "agent_unregister",
450        SchemaKind::Response,
451        include_str!("../schemas/code_index/agent_unregister.response.json"),
452    ),
453    (
454        "code_index",
455        "lock_try",
456        SchemaKind::Request,
457        include_str!("../schemas/code_index/lock_try.request.json"),
458    ),
459    (
460        "code_index",
461        "lock_try",
462        SchemaKind::Response,
463        include_str!("../schemas/code_index/lock_try.response.json"),
464    ),
465    (
466        "code_index",
467        "lock_release",
468        SchemaKind::Request,
469        include_str!("../schemas/code_index/lock_release.request.json"),
470    ),
471    (
472        "code_index",
473        "lock_release",
474        SchemaKind::Response,
475        include_str!("../schemas/code_index/lock_release.response.json"),
476    ),
477    (
478        "code_index",
479        "status",
480        SchemaKind::Request,
481        include_str!("../schemas/code_index/status.request.json"),
482    ),
483    (
484        "code_index",
485        "status",
486        SchemaKind::Response,
487        include_str!("../schemas/code_index/status.response.json"),
488    ),
489    (
490        "code_index",
491        "current_agent_id",
492        SchemaKind::Request,
493        include_str!("../schemas/code_index/current_agent_id.request.json"),
494    ),
495    (
496        "code_index",
497        "current_agent_id",
498        SchemaKind::Response,
499        include_str!("../schemas/code_index/current_agent_id.response.json"),
500    ),
501    // scanner/
502    (
503        "scanner",
504        "scan_project",
505        SchemaKind::Request,
506        include_str!("../schemas/scanner/scan_project.request.json"),
507    ),
508    (
509        "scanner",
510        "scan_project",
511        SchemaKind::Response,
512        include_str!("../schemas/scanner/scan_project.response.json"),
513    ),
514    (
515        "scanner",
516        "scan_incremental",
517        SchemaKind::Request,
518        include_str!("../schemas/scanner/scan_incremental.request.json"),
519    ),
520    (
521        "scanner",
522        "scan_incremental",
523        SchemaKind::Response,
524        include_str!("../schemas/scanner/scan_incremental.response.json"),
525    ),
526    // fs_watch/
527    (
528        "fs_watch",
529        "subscribe",
530        SchemaKind::Request,
531        include_str!("../schemas/fs_watch/subscribe.request.json"),
532    ),
533    (
534        "fs_watch",
535        "subscribe",
536        SchemaKind::Response,
537        include_str!("../schemas/fs_watch/subscribe.response.json"),
538    ),
539    (
540        "fs_watch",
541        "unsubscribe",
542        SchemaKind::Request,
543        include_str!("../schemas/fs_watch/unsubscribe.request.json"),
544    ),
545    (
546        "fs_watch",
547        "unsubscribe",
548        SchemaKind::Response,
549        include_str!("../schemas/fs_watch/unsubscribe.response.json"),
550    ),
551    // tools/
552    (
553        "tools",
554        "search",
555        SchemaKind::Request,
556        include_str!("../schemas/tools/search.request.json"),
557    ),
558    (
559        "tools",
560        "search",
561        SchemaKind::Response,
562        include_str!("../schemas/tools/search.response.json"),
563    ),
564    (
565        "tools",
566        "read_file",
567        SchemaKind::Request,
568        include_str!("../schemas/tools/read_file.request.json"),
569    ),
570    (
571        "tools",
572        "read_file",
573        SchemaKind::Response,
574        include_str!("../schemas/tools/read_file.response.json"),
575    ),
576    (
577        "tools",
578        "write_file",
579        SchemaKind::Request,
580        include_str!("../schemas/tools/write_file.request.json"),
581    ),
582    (
583        "tools",
584        "write_file",
585        SchemaKind::Response,
586        include_str!("../schemas/tools/write_file.response.json"),
587    ),
588    (
589        "tools",
590        "delete_file",
591        SchemaKind::Request,
592        include_str!("../schemas/tools/delete_file.request.json"),
593    ),
594    (
595        "tools",
596        "delete_file",
597        SchemaKind::Response,
598        include_str!("../schemas/tools/delete_file.response.json"),
599    ),
600    (
601        "tools",
602        "list_directory",
603        SchemaKind::Request,
604        include_str!("../schemas/tools/list_directory.request.json"),
605    ),
606    (
607        "tools",
608        "list_directory",
609        SchemaKind::Response,
610        include_str!("../schemas/tools/list_directory.response.json"),
611    ),
612    (
613        "tools",
614        "get_file_outline",
615        SchemaKind::Request,
616        include_str!("../schemas/tools/get_file_outline.request.json"),
617    ),
618    (
619        "tools",
620        "get_file_outline",
621        SchemaKind::Response,
622        include_str!("../schemas/tools/get_file_outline.response.json"),
623    ),
624    (
625        "tools",
626        "git",
627        SchemaKind::Request,
628        include_str!("../schemas/tools/git.request.json"),
629    ),
630    (
631        "tools",
632        "git",
633        SchemaKind::Response,
634        include_str!("../schemas/tools/git.response.json"),
635    ),
636    (
637        "tools",
638        "run_command",
639        SchemaKind::Request,
640        include_str!("../schemas/tools/run_command.request.json"),
641    ),
642    (
643        "tools",
644        "run_command",
645        SchemaKind::Response,
646        include_str!("../schemas/tools/run_command.response.json"),
647    ),
648    (
649        "tools",
650        "read_command_output",
651        SchemaKind::Request,
652        include_str!("../schemas/tools/read_command_output.request.json"),
653    ),
654    (
655        "tools",
656        "read_command_output",
657        SchemaKind::Response,
658        include_str!("../schemas/tools/read_command_output.response.json"),
659    ),
660    (
661        "tools",
662        "run_test",
663        SchemaKind::Request,
664        include_str!("../schemas/tools/run_test.request.json"),
665    ),
666    (
667        "tools",
668        "run_test",
669        SchemaKind::Response,
670        include_str!("../schemas/tools/run_test.response.json"),
671    ),
672    (
673        "tools",
674        "run_build_command",
675        SchemaKind::Request,
676        include_str!("../schemas/tools/run_build_command.request.json"),
677    ),
678    (
679        "tools",
680        "run_build_command",
681        SchemaKind::Response,
682        include_str!("../schemas/tools/run_build_command.response.json"),
683    ),
684    (
685        "tools",
686        "inspect_test_results",
687        SchemaKind::Request,
688        include_str!("../schemas/tools/inspect_test_results.request.json"),
689    ),
690    (
691        "tools",
692        "inspect_test_results",
693        SchemaKind::Response,
694        include_str!("../schemas/tools/inspect_test_results.response.json"),
695    ),
696    (
697        "tools",
698        "manage_packages",
699        SchemaKind::Request,
700        include_str!("../schemas/tools/manage_packages.request.json"),
701    ),
702    (
703        "tools",
704        "manage_packages",
705        SchemaKind::Response,
706        include_str!("../schemas/tools/manage_packages.response.json"),
707    ),
708    (
709        "tools",
710        "cancel_handle",
711        SchemaKind::Request,
712        include_str!("../schemas/tools/cancel_handle.request.json"),
713    ),
714    (
715        "tools",
716        "cancel_handle",
717        SchemaKind::Response,
718        include_str!("../schemas/tools/cancel_handle.response.json"),
719    ),
720    (
721        "tools",
722        "enable",
723        SchemaKind::Request,
724        include_str!("../schemas/tools/enable.request.json"),
725    ),
726    (
727        "tools",
728        "enable",
729        SchemaKind::Response,
730        include_str!("../schemas/tools/enable.response.json"),
731    ),
732];
733
734/// Look up a single schema as raw JSON text.
735pub fn lookup(module: &str, method: &str, kind: SchemaKind) -> Option<&'static str> {
736    SCHEMAS
737        .iter()
738        .find(|(m, mt, k, _)| *m == module && *mt == method && *k == kind)
739        .map(|(_, _, _, body)| *body)
740}