huskies: merge 515_story_add_a_debug_mcp_tool_to_dump_the_in_memory_crdt_state_for_inspection

This commit is contained in:
dave
2026-04-10 10:20:41 +00:00
parent c6b6be872b
commit f015fe5a1d
5 changed files with 353 additions and 1 deletions
+59
View File
@@ -98,6 +98,7 @@ pub fn build_routes(
"/oauth/status",
get(oauth::oauth_status),
)
.at("/debug/crdt", get(debug_crdt_handler))
.at("/assets/*path", get(assets::embedded_asset))
.at("/", get(assets::embedded_index))
.at("/*path", get(assets::embedded_file));
@@ -126,6 +127,64 @@ pub fn build_routes(
route.data(ctx_arc)
}
/// Debug HTTP endpoint: `GET /debug/crdt[?story_id=<id>]`
///
/// Returns the raw in-memory CRDT state as JSON. Accepts an optional
/// `story_id` query parameter to restrict the dump to a single item.
///
/// **This is a debug endpoint.** Use `GET /api/pipeline` or the
/// `get_pipeline_status` MCP tool for normal pipeline introspection.
#[poem::handler]
pub fn debug_crdt_handler(req: &poem::Request) -> poem::Response {
let story_id_filter = req.uri().query().and_then(|q| {
q.split('&').find_map(|pair| {
let (key, val) = pair.split_once('=')?;
if key == "story_id" {
Some(val.to_string())
} else {
None
}
})
});
let dump = crate::crdt_state::dump_crdt_state(story_id_filter.as_deref());
let items: Vec<serde_json::Value> = dump
.items
.into_iter()
.map(|item| {
serde_json::json!({
"story_id": item.story_id,
"stage": item.stage,
"name": item.name,
"agent": item.agent,
"retry_count": item.retry_count,
"blocked": item.blocked,
"depends_on": item.depends_on,
"content_index": item.content_index,
"is_deleted": item.is_deleted,
})
})
.collect();
let body = serde_json::json!({
"metadata": {
"in_memory_state_loaded": dump.in_memory_state_loaded,
"total_items": dump.total_items,
"total_ops_in_list": dump.total_ops_in_list,
"max_seq_in_list": dump.max_seq_in_list,
"persisted_ops_count": dump.persisted_ops_count,
"pending_persist_ops_count": null,
},
"items": items,
});
poem::Response::builder()
.status(poem::http::StatusCode::OK)
.header(poem::http::header::CONTENT_TYPE, "application/json")
.body(serde_json::to_string_pretty(&body).unwrap_or_default())
}
type ApiTuple = (
ProjectApi,
ModelApi,