huskies: merge 864
This commit is contained in:
+65
-23
@@ -9,23 +9,65 @@ use super::content_store::{
|
||||
use super::shadow_write::{PIPELINE_DB, PipelineWriteMsg};
|
||||
use crate::io::story_metadata::parse_front_matter;
|
||||
|
||||
/// Typed metadata for a pipeline item write.
|
||||
///
|
||||
/// Replaces the prior YAML-parsing write path (story 864): callers now pass
|
||||
/// metadata explicitly instead of round-tripping it through a serialized
|
||||
/// front-matter blob. Every field is `Option`-typed; `None` means
|
||||
/// "leave unchanged" on update, "use the default" on insert.
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct ItemMeta {
|
||||
pub name: Option<String>,
|
||||
pub agent: Option<String>,
|
||||
pub retry_count: Option<i64>,
|
||||
pub blocked: Option<bool>,
|
||||
pub depends_on: Option<Vec<u32>>,
|
||||
}
|
||||
|
||||
impl ItemMeta {
|
||||
/// Convenience constructor for the common "just set a name" case.
|
||||
#[cfg(test)]
|
||||
pub fn named(name: impl Into<String>) -> Self {
|
||||
Self {
|
||||
name: Some(name.into()),
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse YAML front-matter from a content string into typed metadata.
|
||||
///
|
||||
/// This is an explicit caller-side conversion — the write path itself
|
||||
/// no longer parses YAML. Use this when the caller has a raw content
|
||||
/// string with front-matter and wants the metadata to flow into the
|
||||
/// CRDT. Returns `Self::default()` if parsing fails or there is no
|
||||
/// front-matter present.
|
||||
pub fn from_yaml(content: &str) -> Self {
|
||||
match parse_front_matter(content) {
|
||||
Ok(m) => Self {
|
||||
name: m.name,
|
||||
agent: m.agent,
|
||||
retry_count: m.retry_count.map(|r| r as i64),
|
||||
blocked: m.blocked,
|
||||
depends_on: m.depends_on,
|
||||
},
|
||||
Err(_) => Self::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Write a pipeline item from in-memory content (no filesystem access).
|
||||
///
|
||||
/// This is the primary write path for the DB-backed pipeline. It updates
|
||||
/// the CRDT, the in-memory content store, and the SQLite shadow table.
|
||||
pub fn write_item_with_content(story_id: &str, stage: &str, content: &str) {
|
||||
let (name, agent, retry_count, blocked, depends_on) = match parse_front_matter(content) {
|
||||
Ok(meta) => (
|
||||
meta.name,
|
||||
meta.agent,
|
||||
meta.retry_count.map(|r| r as i64),
|
||||
meta.blocked,
|
||||
meta.depends_on
|
||||
.as_ref()
|
||||
.and_then(|d| serde_json::to_string(d).ok()),
|
||||
),
|
||||
Err(_) => (None, None, None, None, None),
|
||||
};
|
||||
///
|
||||
/// The metadata in `meta` is authoritative: this function does NOT parse
|
||||
/// `content` to extract front-matter fields. Callers must pass typed
|
||||
/// metadata explicitly via `ItemMeta`.
|
||||
pub fn write_item_with_content(story_id: &str, stage: &str, content: &str, meta: ItemMeta) {
|
||||
let depends_on_json = meta
|
||||
.depends_on
|
||||
.as_ref()
|
||||
.and_then(|d| serde_json::to_string(d).ok());
|
||||
|
||||
// Update in-memory content store.
|
||||
ensure_content_store();
|
||||
@@ -42,11 +84,11 @@ pub fn write_item_with_content(story_id: &str, stage: &str, content: &str) {
|
||||
crate::crdt_state::write_item(
|
||||
story_id,
|
||||
stage,
|
||||
name.as_deref(),
|
||||
agent.as_deref(),
|
||||
retry_count,
|
||||
blocked,
|
||||
depends_on.as_deref(),
|
||||
meta.name.as_deref(),
|
||||
meta.agent.as_deref(),
|
||||
meta.retry_count,
|
||||
meta.blocked,
|
||||
depends_on_json.as_deref(),
|
||||
None,
|
||||
None,
|
||||
merged_at_ts,
|
||||
@@ -57,11 +99,11 @@ pub fn write_item_with_content(story_id: &str, stage: &str, content: &str) {
|
||||
let msg = PipelineWriteMsg {
|
||||
story_id: story_id.to_string(),
|
||||
stage: stage.to_string(),
|
||||
name,
|
||||
agent,
|
||||
retry_count,
|
||||
blocked,
|
||||
depends_on,
|
||||
name: meta.name,
|
||||
agent: meta.agent,
|
||||
retry_count: meta.retry_count,
|
||||
blocked: meta.blocked,
|
||||
depends_on: depends_on_json,
|
||||
content: Some(content.to_string()),
|
||||
};
|
||||
let _ = db.tx.send(msg);
|
||||
|
||||
Reference in New Issue
Block a user