use super::*;
use crate::observe::*;
pub(super) fn observe_cli() -> Cli {
Cli::create("observe")
.description("Read durable activity through scoped snapshots and resumable changes.")
.command(
"capabilities",
tracked_typed::<(), (), (), ObserveCapabilities, _, _>(
"capabilities",
|_context: TypedContext<(), (), ()>| async move {
match DaemonClient
.call("observe.capabilities", serde_json::json!({}))
.await
{
Ok(value) => TypedResult::ok(value),
Err(error) => TypedResult::error("OBSERVE_READ_FAILED", error),
}
},
)
.description("Report implemented observation sources and limits.")
.mcp(read_only())
.done(),
)
.command(
"projects",
tracked_typed::<(), (), (), Vec<ObserveProject>, _, _>(
"projects",
|_context: TypedContext<(), (), ()>| async move {
match DaemonClient
.call("observe.projects", serde_json::json!({}))
.await
{
Ok(value) => TypedResult::ok(value),
Err(error) => TypedResult::error("OBSERVE_READ_FAILED", error),
}
},
)
.description("List observed projects across this apoc instance.")
.mcp(read_only())
.done(),
)
.command(
"snapshot",
page_command(
"snapshot",
"observe.snapshot",
"Read a consistent project or explicit global snapshot.",
),
)
.command(
"rows",
page_command(
"rows",
"observe.rows",
"Page observation rows at the snapshot high-water mark.",
),
)
.command(
"watch",
page_command(
"watch",
"observe.watch",
"Resume durable changes after a snapshot or watch cursor.",
),
)
.command(
"get",
page_command(
"get",
"observe.get",
"Read one scoped observation by its exact id.",
),
)
.command(
"tracks",
tracked_typed::<(), ObserveReadOptions, (), Vec<ObserveTrack>, _, _>(
"tracks",
|context: TypedContext<(), ObserveReadOptions, ()>| async move {
match DaemonClient
.call("observe.tracks", serde_json::json!(context.options))
.await
{
Ok(value) => TypedResult::ok(value),
Err(error) => TypedResult::error("OBSERVE_READ_FAILED", error),
}
},
)
.description("List tracks in the selected project or global scope.")
.mcp(read_only())
.done(),
)
}
fn page_command(
name: &'static str,
method: &'static str,
description: &'static str,
) -> incurs::command::CommandDef {
tracked_typed::<(), ObserveReadOptions, (), ObservePage, _, _>(
name,
move |context: TypedContext<(), ObserveReadOptions, ()>| async move {
match DaemonClient
.call(method, serde_json::json!(context.options))
.await
{
Ok(value) => TypedResult::ok(value),
Err(error) => TypedResult::error("OBSERVE_READ_FAILED", error),
}
},
)
.description(description)
.mcp(read_only())
.done()
}