KeiSeiKit-1.0/_primitives/_rust/kei-registry/src/block.rs
Parfii-bot 0be354a920 KeiSeiKit-public — clean state
Single-commit clean baseline after security scrub of niche-tells,
project codenames, internal jargon, and contributor-email leaks.

Contents:
- 100 Rust crates (_primitives/_rust/)
- 37 agent manifests (_manifests/) + generated specs (_generated/)
- 67 user-invocable skills (skills/)
- 33 hooks (hooks/)
- Composition blocks (_blocks/)
- Documentation (docs/, README.md)
- TS adapter packages (_ts_packages/)
- Assembler (_assembler/)
- Roles (_roles/)
- Templates (_templates/)
- Forgejo CI (.forgejo/)

Author: Denis Parfionovich <info@greendragon.info>

License: see LICENSE.
2026-05-01 12:09:03 +08:00

90 lines
2.5 KiB
Rust

//! Block — registry record for one kit artefact.
//!
//! Constructor Pattern: this cube owns the data shape only. SQL persistence
//! lives in `store.rs`; query helpers live in `registry.rs`. Block is what
//! flows over the JSON CLI surface.
use serde::{Deserialize, Serialize};
use std::fmt;
use std::str::FromStr;
/// Five recognised block types. Order is the canonical scan order and the
/// wire-format `<role>` segment of the block DNA.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum BlockType {
Primitive,
Skill,
Rule,
Hook,
Atom,
}
impl BlockType {
/// Stable wire-format string. Used as the DNA `role` segment.
pub fn as_str(self) -> &'static str {
match self {
BlockType::Primitive => "primitive",
BlockType::Skill => "skill",
BlockType::Rule => "rule",
BlockType::Hook => "hook",
BlockType::Atom => "atom",
}
}
/// All five recognised types in canonical scan order.
pub fn all() -> &'static [BlockType] {
&[
BlockType::Primitive,
BlockType::Skill,
BlockType::Rule,
BlockType::Hook,
BlockType::Atom,
]
}
}
impl fmt::Display for BlockType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
impl FromStr for BlockType {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"primitive" => Ok(BlockType::Primitive),
"skill" => Ok(BlockType::Skill),
"rule" => Ok(BlockType::Rule),
"hook" => Ok(BlockType::Hook),
"atom" => Ok(BlockType::Atom),
other => Err(format!("unknown block_type: {other}")),
}
}
}
/// Block — single registry record. Mirrors the SQLite `blocks` row plus
/// the synthetic DNA composed from the other facets.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Block {
pub id: i64,
pub dna: String,
pub block_type: BlockType,
pub name: String,
pub path: String,
pub caps: String,
pub scope_sha: String,
pub body_sha: String,
pub nonce: String,
pub created: i64,
pub modified: i64,
pub superseded_by: Option<String>,
}
impl Block {
/// True if no successor row points at this block.
pub fn is_active(&self) -> bool {
self.superseded_by.is_none()
}
}