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/
527    (
528        "fs",
529        "set_mode",
530        SchemaKind::Request,
531        include_str!("../schemas/fs/set_mode.request.json"),
532    ),
533    (
534        "fs",
535        "set_mode",
536        SchemaKind::Response,
537        include_str!("../schemas/fs/set_mode.response.json"),
538    ),
539    (
540        "fs",
541        "staged_status",
542        SchemaKind::Request,
543        include_str!("../schemas/fs/staged_status.request.json"),
544    ),
545    (
546        "fs",
547        "staged_status",
548        SchemaKind::Response,
549        include_str!("../schemas/fs/staged_status.response.json"),
550    ),
551    (
552        "fs",
553        "commit_staged",
554        SchemaKind::Request,
555        include_str!("../schemas/fs/commit_staged.request.json"),
556    ),
557    (
558        "fs",
559        "commit_staged",
560        SchemaKind::Response,
561        include_str!("../schemas/fs/commit_staged.response.json"),
562    ),
563    (
564        "fs",
565        "discard_staged",
566        SchemaKind::Request,
567        include_str!("../schemas/fs/discard_staged.request.json"),
568    ),
569    (
570        "fs",
571        "discard_staged",
572        SchemaKind::Response,
573        include_str!("../schemas/fs/discard_staged.response.json"),
574    ),
575    // fs_watch/
576    (
577        "fs_watch",
578        "subscribe",
579        SchemaKind::Request,
580        include_str!("../schemas/fs_watch/subscribe.request.json"),
581    ),
582    (
583        "fs_watch",
584        "subscribe",
585        SchemaKind::Response,
586        include_str!("../schemas/fs_watch/subscribe.response.json"),
587    ),
588    (
589        "fs_watch",
590        "unsubscribe",
591        SchemaKind::Request,
592        include_str!("../schemas/fs_watch/unsubscribe.request.json"),
593    ),
594    (
595        "fs_watch",
596        "unsubscribe",
597        SchemaKind::Response,
598        include_str!("../schemas/fs_watch/unsubscribe.response.json"),
599    ),
600    // tools/
601    (
602        "tools",
603        "search",
604        SchemaKind::Request,
605        include_str!("../schemas/tools/search.request.json"),
606    ),
607    (
608        "tools",
609        "search",
610        SchemaKind::Response,
611        include_str!("../schemas/tools/search.response.json"),
612    ),
613    (
614        "tools",
615        "read_file",
616        SchemaKind::Request,
617        include_str!("../schemas/tools/read_file.request.json"),
618    ),
619    (
620        "tools",
621        "read_file",
622        SchemaKind::Response,
623        include_str!("../schemas/tools/read_file.response.json"),
624    ),
625    (
626        "tools",
627        "write_file",
628        SchemaKind::Request,
629        include_str!("../schemas/tools/write_file.request.json"),
630    ),
631    (
632        "tools",
633        "write_file",
634        SchemaKind::Response,
635        include_str!("../schemas/tools/write_file.response.json"),
636    ),
637    (
638        "tools",
639        "delete_file",
640        SchemaKind::Request,
641        include_str!("../schemas/tools/delete_file.request.json"),
642    ),
643    (
644        "tools",
645        "delete_file",
646        SchemaKind::Response,
647        include_str!("../schemas/tools/delete_file.response.json"),
648    ),
649    (
650        "tools",
651        "list_directory",
652        SchemaKind::Request,
653        include_str!("../schemas/tools/list_directory.request.json"),
654    ),
655    (
656        "tools",
657        "list_directory",
658        SchemaKind::Response,
659        include_str!("../schemas/tools/list_directory.response.json"),
660    ),
661    (
662        "tools",
663        "get_file_outline",
664        SchemaKind::Request,
665        include_str!("../schemas/tools/get_file_outline.request.json"),
666    ),
667    (
668        "tools",
669        "get_file_outline",
670        SchemaKind::Response,
671        include_str!("../schemas/tools/get_file_outline.response.json"),
672    ),
673    (
674        "tools",
675        "git",
676        SchemaKind::Request,
677        include_str!("../schemas/tools/git.request.json"),
678    ),
679    (
680        "tools",
681        "git",
682        SchemaKind::Response,
683        include_str!("../schemas/tools/git.response.json"),
684    ),
685    (
686        "tools",
687        "run_command",
688        SchemaKind::Request,
689        include_str!("../schemas/tools/run_command.request.json"),
690    ),
691    (
692        "tools",
693        "run_command",
694        SchemaKind::Response,
695        include_str!("../schemas/tools/run_command.response.json"),
696    ),
697    (
698        "tools",
699        "read_command_output",
700        SchemaKind::Request,
701        include_str!("../schemas/tools/read_command_output.request.json"),
702    ),
703    (
704        "tools",
705        "read_command_output",
706        SchemaKind::Response,
707        include_str!("../schemas/tools/read_command_output.response.json"),
708    ),
709    (
710        "tools",
711        "run_test",
712        SchemaKind::Request,
713        include_str!("../schemas/tools/run_test.request.json"),
714    ),
715    (
716        "tools",
717        "run_test",
718        SchemaKind::Response,
719        include_str!("../schemas/tools/run_test.response.json"),
720    ),
721    (
722        "tools",
723        "run_build_command",
724        SchemaKind::Request,
725        include_str!("../schemas/tools/run_build_command.request.json"),
726    ),
727    (
728        "tools",
729        "run_build_command",
730        SchemaKind::Response,
731        include_str!("../schemas/tools/run_build_command.response.json"),
732    ),
733    (
734        "tools",
735        "inspect_test_results",
736        SchemaKind::Request,
737        include_str!("../schemas/tools/inspect_test_results.request.json"),
738    ),
739    (
740        "tools",
741        "inspect_test_results",
742        SchemaKind::Response,
743        include_str!("../schemas/tools/inspect_test_results.response.json"),
744    ),
745    (
746        "tools",
747        "manage_packages",
748        SchemaKind::Request,
749        include_str!("../schemas/tools/manage_packages.request.json"),
750    ),
751    (
752        "tools",
753        "manage_packages",
754        SchemaKind::Response,
755        include_str!("../schemas/tools/manage_packages.response.json"),
756    ),
757    (
758        "tools",
759        "cancel_handle",
760        SchemaKind::Request,
761        include_str!("../schemas/tools/cancel_handle.request.json"),
762    ),
763    (
764        "tools",
765        "cancel_handle",
766        SchemaKind::Response,
767        include_str!("../schemas/tools/cancel_handle.response.json"),
768    ),
769    (
770        "tools",
771        "enable",
772        SchemaKind::Request,
773        include_str!("../schemas/tools/enable.request.json"),
774    ),
775    (
776        "tools",
777        "enable",
778        SchemaKind::Response,
779        include_str!("../schemas/tools/enable.response.json"),
780    ),
781    // secret_store/
782    (
783        "secret_store",
784        "get",
785        SchemaKind::Request,
786        include_str!("../schemas/secret_store/get.request.json"),
787    ),
788    (
789        "secret_store",
790        "get",
791        SchemaKind::Response,
792        include_str!("../schemas/secret_store/get.response.json"),
793    ),
794    (
795        "secret_store",
796        "set",
797        SchemaKind::Request,
798        include_str!("../schemas/secret_store/set.request.json"),
799    ),
800    (
801        "secret_store",
802        "set",
803        SchemaKind::Response,
804        include_str!("../schemas/secret_store/set.response.json"),
805    ),
806    (
807        "secret_store",
808        "delete",
809        SchemaKind::Request,
810        include_str!("../schemas/secret_store/delete.request.json"),
811    ),
812    (
813        "secret_store",
814        "delete",
815        SchemaKind::Response,
816        include_str!("../schemas/secret_store/delete.response.json"),
817    ),
818    (
819        "secret_store",
820        "list",
821        SchemaKind::Request,
822        include_str!("../schemas/secret_store/list.request.json"),
823    ),
824    (
825        "secret_store",
826        "list",
827        SchemaKind::Response,
828        include_str!("../schemas/secret_store/list.response.json"),
829    ),
830];
831
832/// Look up a single schema as raw JSON text.
833pub fn lookup(module: &str, method: &str, kind: SchemaKind) -> Option<&'static str> {
834    SCHEMAS
835        .iter()
836        .find(|(m, mt, k, _)| *m == module && *mt == method && *k == kind)
837        .map(|(_, _, _, body)| *body)
838}