feat(app): 대화 screen to read what people said, Jarvis's answers and how each answer was made

The management app reads the worker's history store (read only) and shows
people's words, Jarvis's answers and the answer traces in time order, with
filters for kind, place, person, channel, day and text, live follow, older
items on demand and expandable traces (records given, tools offered, plan,
model thinking, tool calls and results).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-16 03:08:38 +09:00
parent a20ebe4eae
commit 46f71e7f03
15 changed files with 724 additions and 4 deletions

View File

@@ -396,6 +396,29 @@ impl AdminApi {
crate::info_log!("admin", "note {id} deleted");
Ok(json!({"deleted": id.to_string()}))
}
// The 대화 screen (admin.spec.md, "Conversations"): records and answer traces.
"history_query" => {
let dir = self.dir()?;
let text = |k: &str| args.get(k).and_then(Value::as_str).map(str::trim).filter(|s| !s.is_empty()).map(String::from);
let flag = |k: &str| args.get(k).and_then(Value::as_bool).unwrap_or(true);
let q = crate::history_view::Query {
said: flag("said"), answered: flag("answered"), thought: flag("thought"),
via: text("via"), person: text("person"), channel: text("channel"), find: text("find"),
since: args.get("since").and_then(Value::as_f64), until: args.get("until").and_then(Value::as_f64),
limit: args.get("limit").and_then(Value::as_u64).map_or(crate::history_view::DEFAULT_LIMIT, |n| n as usize),
};
let bot = self.secrets()?.get(DISCORD_TOKEN).ok().flatten().and_then(|t| crate::history_view::bot_id_of_token(&t));
let path = dir.path().join("memory").join("history.sqlite");
let mut v = tokio::task::spawn_blocking(move || crate::history_view::query(&path, bot.as_deref(), &q))
.await.map_err(|e| e.to_string())??;
// Chat channels by the names given them in the settings.
let named = crate::settings::load_settings(&dir.settings_file()).map(|s| s.chat_channels).unwrap_or_default();
for ch in v["channels"].as_array_mut().into_iter().flatten() {
let name = named.iter().find(|c| Some(c.id.to_string().as_str()) == ch["id"].as_str()).map(|c| c.name.clone());
ch["name"] = json!(name.unwrap_or_default());
}
Ok(v)
}
"activity_list" => {
let limit = args.get("limit").and_then(Value::as_u64).unwrap_or(200).clamp(1, 1000) as usize;
Ok(json!({"items": crate::activity::Activity::new(self.dir()?.path()).recent(limit)}))
@@ -541,6 +564,28 @@ mod tests {
assert!(store.all().unwrap().is_empty());
}
#[tokio::test]
async fn the_conversation_screen_reads_records_and_traces_with_channel_names() {
let (a, base) = api("api-history");
let data = base.join("d");
a.call("folder_choose", json!({"path": data.to_string_lossy()})).await.unwrap();
assert_eq!(a.call("history_query", json!({})).await.unwrap()["missing"], true);
std::fs::create_dir_all(data.join("memory")).unwrap();
let c = rusqlite::Connection::open(data.join("memory").join("history.sqlite")).unwrap();
c.execute_batch(crate::history_view::TEST_SCHEMA).unwrap();
c.execute_batch("INSERT INTO history(ts, kind, channel_id, author_id, author_name, text, norm)
VALUES (1, 'chat', '123456789012345678', '1', 'Alice', '안녕', '안녕');
INSERT INTO traces(ts, via, channel_id, user_id, question, answer, ms, steps)
VALUES (2, 'chat', '123456789012345678', '1', '안녕', '반가워요', 5, '[]');").unwrap();
a.call("settings_apply", json!({"changes": {"chatChannels": [{"id": "123456789012345678", "name": "잡담"}]}})).await.unwrap();
let v = a.call("history_query", json!({"thought": false})).await.unwrap();
assert_eq!(v["items"].as_array().unwrap().len(), 1);
assert_eq!(v["items"][0]["who"]["name"], "Alice");
assert_eq!(v["channels"][0]["name"], "잡담");
let v = a.call("history_query", json!({"said": false, "find": "반가"})).await.unwrap();
assert_eq!(v["items"][0]["type"], "thought");
}
#[tokio::test]
async fn the_activity_screen_reads_the_newest_entries() {
let (a, base) = api("api-activity");