Skip to main content

khive_pack_template/
lib.rs

1//! Reference scaffold for a dynamically registered khive pack.
2
3pub mod handlers;
4mod pack;
5pub mod vocab;
6
7use khive_runtime::KhiveRuntime;
8use khive_types::{HandlerDef, Pack};
9
10pub(crate) use pack::TEMPLATE_HANDLERS;
11
12/// Canonical pack name. Must match the factory below and `PackFactory::name()`.
13pub(crate) const PACK_NAME: &str = "template";
14
15/// Example pack joining vocabulary, handlers, dependencies, and a runtime handle.
16///
17/// See `crates/khive-pack-template/docs/api/pack-scaffold.md`.
18pub struct TemplatePack {
19    runtime: KhiveRuntime,
20}
21
22impl Pack for TemplatePack {
23    const NAME: &'static str = PACK_NAME;
24    /// Declare note kinds this pack contributes. Must not overlap with other packs.
25    const NOTE_KINDS: &'static [&'static str] = vocab::NOTE_KINDS;
26    /// Declare entity kinds this pack contributes. Must not overlap with other packs.
27    const ENTITY_KINDS: &'static [&'static str] = vocab::ENTITY_KINDS;
28    /// Handler table. Each entry is one verb or subhandler the pack can dispatch.
29    const HANDLERS: &'static [HandlerDef] = &TEMPLATE_HANDLERS;
30    /// Pack dependencies. The named packs must be in the configured `KHIVE_PACKS` list.
31    const REQUIRES: &'static [&'static str] = &["kg"];
32}
33
34impl TemplatePack {
35    /// Bind the template pack to the runtime used by its handlers.
36    pub fn new(runtime: KhiveRuntime) -> Self {
37        Self { runtime }
38    }
39    pub(crate) fn runtime(&self) -> &KhiveRuntime {
40        &self.runtime
41    }
42}