refactor(rename): kb crates → kebab — Cargo packages, folders, Rust modules

프로젝트 이름 `kb` → `kebab` rename 의 첫 단계.

- workspace `Cargo.toml`: members `crates/kb-*` → `crates/kebab-*`,
  repository URL `altair823/kb` → `altair823/kebab`.
- 18 crate 폴더 rename via `git mv` (history 보존).
- 각 crate `Cargo.toml`: `name = "kb-*"` → `"kebab-*"`, path deps
  `../kb-*` → `../kebab-*`.
- 모든 `.rs`: `kb_<id>` snake-case 모듈 path 18 개 (`kb_core`,
  `kb_config`, `kb_app`, `kb_cli`, `kb_eval`, `kb_search`, `kb_chunk`,
  `kb_normalize`, `kb_source_fs`, `kb_parse_md`, `kb_parse_types`,
  `kb_store_sqlite`, `kb_store_vector`, `kb_embed`, `kb_embed_local`,
  `kb_llm`, `kb_llm_local`, `kb_rag`) → `kebab_<id>` 일괄 sed (단어
  경계 \\b 사용해 영어 문장 안의 "kb" 약어 미오염).

CLI binary 이름 (`[[bin]] name = "kb"`), 환경변수 `KB_*`, XDG paths,
tracing target, 그리고 docs sweep 은 다음 commit 에서.

## 검증

- `cargo check --workspace` clean — 모든 crate 빌드 통과 후 commit.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-02 03:28:08 +00:00
parent 2aecbf3d9f
commit 911fb49550
143 changed files with 727 additions and 727 deletions

View File

@@ -0,0 +1,175 @@
//! CLI-side wire-schema wrappers.
//!
//! Convention (per design §2): every JSON object emitted on stdout in
//! `--json` mode MUST carry a top-level `schema_version` of the form
//! `"<object>.v1"`. The kb-core types are pure domain types and do NOT
//! carry `schema_version` themselves; the CLI wraps them on emit. The one
//! exception is `DoctorReport`, where `schema_version` is part of the wire
//! type because the doctor wire object IS its own structured surface.
//!
//! Future tasks (P1-5, P3, P4, P5) replacing stub `bail!` paths must call
//! these helpers from the relevant CLI subcommand handler before
//! `serde_json::to_string`.
//!
//! Each helper is total (returns `serde_json::Value`, never an error) — the
//! input is a fully-typed `serde::Serialize` value, so the only way to fail
//! is OOM, which would have killed the process anyway.
use serde_json::Value;
use kebab_app::DoctorReport;
use kebab_core::{Answer, Chunk, DocSummary, IngestReport, SearchHit};
/// Insert `schema_version` into an object-shaped `Value`. Helper for the
/// "serialize, then tag" pattern used by all the per-type wrappers below.
fn tag_object(mut v: Value, schema_version: &str) -> Value {
if let Value::Object(ref mut map) = v {
map.insert(
"schema_version".to_string(),
Value::String(schema_version.to_string()),
);
}
v
}
/// Wrap an [`IngestReport`] as `ingest_report.v1`.
pub fn wire_ingest(r: &IngestReport) -> Value {
let v = serde_json::to_value(r).expect("IngestReport serializes");
tag_object(v, "ingest_report.v1")
}
/// Wrap a single [`DocSummary`] as `doc_summary.v1`.
pub fn wire_doc_summary(d: &DocSummary) -> Value {
let v = serde_json::to_value(d).expect("DocSummary serializes");
tag_object(v, "doc_summary.v1")
}
/// Wrap a list of [`DocSummary`] values as a JSON array of `doc_summary.v1`
/// objects (one tag per element, per design §2.5 — there is no list-envelope
/// schema; the list shape is `[{schema_version: "doc_summary.v1", ...}, ...]`).
pub fn wire_doc_summaries(d: &[DocSummary]) -> Value {
Value::Array(d.iter().map(wire_doc_summary).collect())
}
/// Wrap a [`Chunk`] as `chunk_inspection.v1` (§2.6). NOTE: the wire schema
/// requires `doc_path`, which the kb-core `Chunk` does not currently carry —
/// when P1-5 wires the Ok-path, the implementation should either enrich
/// `Chunk` or pass `doc_path` alongside. For now this helper emits whatever
/// fields `Chunk` serializes with, plus the `schema_version` tag.
pub fn wire_chunk_inspection(c: &Chunk) -> Value {
let v = serde_json::to_value(c).expect("Chunk serializes");
tag_object(v, "chunk_inspection.v1")
}
/// Wrap a single [`SearchHit`] as `search_hit.v1`.
pub fn wire_search_hit(h: &SearchHit) -> Value {
let mut v = serde_json::to_value(h).expect("SearchHit serializes");
// Promote `retrieval.fusion_score` to a top-level `score` per §2.2.
if let Value::Object(ref mut map) = v {
if let Some(Value::Object(retrieval)) = map.get("retrieval") {
if let Some(score) = retrieval.get("fusion_score").cloned() {
map.insert("score".to_string(), score);
}
}
}
tag_object(v, "search_hit.v1")
}
/// Wrap a list of [`SearchHit`] values as a JSON array of `search_hit.v1`
/// objects (one tag per element, per design §2.2).
pub fn wire_search_hits(hits: &[SearchHit]) -> Value {
Value::Array(hits.iter().map(wire_search_hit).collect())
}
/// Wrap an [`Answer`] as `answer.v1`.
pub fn wire_answer(a: &Answer) -> Value {
let v = serde_json::to_value(a).expect("Answer serializes");
tag_object(v, "answer.v1")
}
/// Idempotent pass-through for [`DoctorReport`] — the type already carries
/// `schema_version: "doctor.v1"` (struct-field convention, the one
/// exception called out in the module doc above). This helper exists so
/// every `--json` branch in `kb-cli` goes through `wire::*`, keeping the
/// emit pattern uniform.
pub fn wire_doctor(d: &DoctorReport) -> Value {
// Round-trip through `to_value` to confirm the field is serialized;
// then re-tag (no-op when the field is already present, defensive
// when a future refactor drops the struct-field).
let v = serde_json::to_value(d).expect("DoctorReport serializes");
if let Value::Object(ref map) = v {
if matches!(
map.get("schema_version"),
Some(Value::String(s)) if s == "doctor.v1"
) {
return v;
}
}
tag_object(v, "doctor.v1")
}
#[cfg(test)]
mod tests {
use super::*;
fn schema_of(v: &Value) -> Option<&str> {
v.as_object()?.get("schema_version")?.as_str()
}
#[test]
fn doctor_round_trip_preserves_schema_version() {
let d = DoctorReport {
schema_version: "doctor.v1".to_string(),
ok: true,
checks: Vec::new(),
};
let v = wire_doctor(&d);
assert_eq!(schema_of(&v), Some("doctor.v1"));
// Sanity: ok/checks are preserved.
assert_eq!(v.get("ok").and_then(Value::as_bool), Some(true));
assert!(v.get("checks").and_then(Value::as_array).is_some());
}
#[test]
fn ingest_wrapper_tags_schema_version() {
use kebab_core::SourceScope;
let r = IngestReport {
scope: SourceScope {
root: std::path::PathBuf::from("/tmp"),
include: vec![],
exclude: vec![],
},
scanned: 0,
new: 0,
updated: 0,
skipped: 0,
errors: 0,
duration_ms: 0,
items: None,
};
let v = wire_ingest(&r);
assert_eq!(schema_of(&v), Some("ingest_report.v1"));
assert!(v.get("items").is_some());
}
#[test]
fn doc_summaries_wraps_each_element() {
let v = wire_doc_summaries(&[]);
assert!(v.is_array());
assert_eq!(v.as_array().unwrap().len(), 0);
}
#[test]
fn search_hits_wraps_each_element() {
let v = wire_search_hits(&[]);
assert!(v.is_array());
assert_eq!(v.as_array().unwrap().len(), 0);
}
#[test]
fn tag_object_inserts_into_object() {
let v = Value::Object(serde_json::Map::new());
let tagged = tag_object(v, "x.v1");
assert_eq!(schema_of(&tagged), Some("x.v1"));
}
}