forked from kent/consciousness
Add transcript tail debug command
This commit is contained in:
parent
54df271308
commit
5e69a0c153
2 changed files with 39 additions and 0 deletions
|
|
@ -4,6 +4,31 @@ use anyhow::Result;
|
|||
use crate::hippocampus as memory;
|
||||
use crate::hippocampus::store;
|
||||
|
||||
pub fn cmd_transcript_tail(path: &str, count: usize, newest_first: bool) -> Result<()> {
|
||||
let Some(iter) = crate::conversation::TailMessages::open(path) else {
|
||||
anyhow::bail!("could not open transcript {}", path);
|
||||
};
|
||||
|
||||
let mut messages: Vec<_> = iter.take(count).collect();
|
||||
if !newest_first {
|
||||
messages.reverse();
|
||||
}
|
||||
|
||||
for message in messages {
|
||||
let role = match message.role {
|
||||
crate::conversation::TranscriptRole::User => "user",
|
||||
crate::conversation::TranscriptRole::Assistant => "assistant",
|
||||
};
|
||||
let timestamp = message.timestamp.as_deref().unwrap_or("-");
|
||||
|
||||
println!("--- {role} offset={} timestamp={} ---", message.offset, timestamp);
|
||||
println!("{}", message.text);
|
||||
println!();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn install_default_file(data_dir: &std::path::Path, name: &str, content: &str) -> Result<()> {
|
||||
let path = data_dir.join(name);
|
||||
if !path.exists() {
|
||||
|
|
|
|||
14
src/main.rs
14
src/main.rs
|
|
@ -333,6 +333,18 @@ enum AdminCmd {
|
|||
#[arg(long)]
|
||||
stats: bool,
|
||||
},
|
||||
/// Print normalized user/assistant messages from a transcript JSONL file
|
||||
#[command(name = "transcript-tail")]
|
||||
TranscriptTail {
|
||||
/// Transcript JSONL path
|
||||
path: String,
|
||||
/// Maximum number of messages to print
|
||||
#[arg(long, short = 'n', default_value_t = 40)]
|
||||
count: usize,
|
||||
/// Print newest messages first instead of chronological order
|
||||
#[arg(long)]
|
||||
newest_first: bool,
|
||||
},
|
||||
}
|
||||
|
||||
/// Print help with subcommands expanded to show nested commands.
|
||||
|
|
@ -458,6 +470,8 @@ impl Run for AdminCmd {
|
|||
Self::Dedup { apply } => cli::admin::cmd_dedup(apply).await,
|
||||
Self::DailyCheck => cli::admin::cmd_daily_check().await,
|
||||
Self::LoadContext { stats } => cli::node::cmd_load_context(stats).await,
|
||||
Self::TranscriptTail { path, count, newest_first }
|
||||
=> cli::admin::cmd_transcript_tail(&path, count, newest_first),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue