feat(spaces): add spatial memory and governed actions (#1650)

This commit is contained in:
rUv
2026-08-19 13:23:29 -04:00
committed by GitHub
parent d36f346bba
commit c929bbc8b3
28 changed files with 3192 additions and 94 deletions

View File

@@ -2,9 +2,36 @@
use std::path::PathBuf;
use clap::Args;
use clap::{Args, ValueEnum};
use ruview_auth::{login, scope};
use ruview_cognitum_spaces::{Client, Credential};
use ruview_cognitum_spaces::{Client, Credential, PageRequest, SpatialKind};
#[derive(Clone, Copy, Debug, ValueEnum)]
pub enum SpatialResourceKind {
Sites,
Buildings,
Floors,
Spaces,
Zones,
Entities,
Events,
Alerts,
}
impl From<SpatialResourceKind> for SpatialKind {
fn from(value: SpatialResourceKind) -> Self {
match value {
SpatialResourceKind::Sites => Self::Sites,
SpatialResourceKind::Buildings => Self::Buildings,
SpatialResourceKind::Floors => Self::Floors,
SpatialResourceKind::Spaces => Self::Spaces,
SpatialResourceKind::Zones => Self::Zones,
SpatialResourceKind::Entities => Self::Entities,
SpatialResourceKind::Events => Self::Events,
SpatialResourceKind::Alerts => Self::Alerts,
}
}
}
#[derive(Debug, Args)]
pub struct SpacesArgs {
@@ -20,6 +47,22 @@ pub struct SpacesArgs {
#[arg(long, env = ruview_auth::login::CREDENTIALS_PATH_ENV)]
pub credentials_path: Option<PathBuf>,
/// Versioned hierarchy/event/alert collection. Omit for the legacy flat projection.
#[arg(long, value_enum)]
pub resource: Option<SpatialResourceKind>,
/// Page size for a versioned resource collection (1..=100).
#[arg(long, default_value_t = 50, value_parser = clap::value_parser!(u8).range(1..=100), requires = "resource")]
pub limit: u8,
/// Opaque next-page cursor returned by a prior versioned read.
#[arg(long, requires = "resource")]
pub cursor: Option<String>,
/// API-key compatibility only: exact workspace UUID. OAuth derives this from its signed token.
#[arg(long, requires = "resource")]
pub workspace_id: Option<String>,
/// Emit the validated response as JSON.
#[arg(long)]
pub json: bool,
@@ -46,7 +89,47 @@ pub async fn spaces_cmd(args: SpacesArgs) -> anyhow::Result<()> {
Credential::oauth(session.ensure_fresh().await?)?
}
};
let response = Client::new(&args.base_url, credential)?.list().await?;
let client = Client::new(&args.base_url, credential)?;
if let Some(resource) = args.resource {
let response = client
.list_spatial(
resource.into(),
&PageRequest {
limit: args.limit,
cursor: args.cursor,
workspace_id: args.workspace_id,
},
)
.await?;
if args.json {
println!("{}", serde_json::to_string_pretty(&response)?);
return Ok(());
}
println!(
"Cognitum Spatial {}: {}",
response.kind.as_str(),
response.data.len()
);
println!(
"Boundary: {} / {}",
response.boundary.authoritative_state, response.boundary.cloud_role
);
for item in response.data {
println!(
"{}\tkind={}\tprivacy={}\tsite={}\tspace={}",
item.id,
item.kind.as_str(),
item.privacy,
item.site_id.as_deref().unwrap_or("-"),
item.space_id.as_deref().unwrap_or("-")
);
}
if let Some(cursor) = response.next_cursor {
println!("Next cursor: {cursor}");
}
return Ok(());
}
let response = client.list().await?;
if args.json {
println!("{}", serde_json::to_string_pretty(&response)?);
return Ok(());