feat: personal notes, each person's standing instructions for how Jarvis answers them
A personalNotes tool (add, list, delete the asker's own notes) offered only with a notes backend. The app keeps the notes in config/notes.json and sends the asker's with every voice, chat and task reply; the reply engine puts them in a <person_notes> fence as that person's preferences, which never permit an action or a tool. The worker's schedule bridge becomes a shared app bridge for schedule_action and note_action. A 사람별 지침 screen edits and deletes any note; features.notes turns the tool and the notes off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -203,6 +203,8 @@ struct Inner {
|
||||
schedules: OnceLock<Arc<crate::schedule::Store>>,
|
||||
/// Scheduled tasks waiting for the brain's answer, by reply id.
|
||||
tasks: Mutex<HashMap<String, tokio::sync::oneshot::Sender<String>>>,
|
||||
/// Each person's standing instructions, sent with their replies (admin.spec.md, "Personal notes").
|
||||
notes: OnceLock<Arc<crate::notes::Notes>>,
|
||||
/// What Jarvis did outside its answers (admin.spec.md, "Activity").
|
||||
activity: OnceLock<Arc<crate::activity::Activity>>,
|
||||
/// Speech requests whose end someone waits for (`say_to_end`), by request id.
|
||||
@@ -279,6 +281,7 @@ impl DiscordCore {
|
||||
tasks: Mutex::new(HashMap::new()),
|
||||
speech_waits: Mutex::new(HashMap::new()),
|
||||
activity: OnceLock::new(),
|
||||
notes: OnceLock::new(),
|
||||
});
|
||||
tokio::spawn(player_task(Arc::downgrade(&inner), player_rx));
|
||||
tokio::spawn(worker_task(Arc::downgrade(&inner), worker_events));
|
||||
@@ -513,7 +516,7 @@ impl DiscordCore {
|
||||
let id = with_playback(&self.inner, |p| p.adopt());
|
||||
let _ = self.inner.events.send(CoreEvent::AnswerAsked { id: id.clone(), user, ended_at: heard.0,
|
||||
final_at: heard.1 });
|
||||
self.inner.worker.reply(&id, user, text, "voice", true);
|
||||
self.inner.worker.reply_in(&id, user, text, "voice", true, None, ¬es_of(&self.inner, user));
|
||||
Some(id)
|
||||
}
|
||||
|
||||
@@ -527,7 +530,7 @@ impl DiscordCore {
|
||||
/// Have the brain answer a chat message written in `channel` under `id`; the text comes as
|
||||
/// `CoreEvent::ReplyText`.
|
||||
pub fn chat_answer(&self, id: &str, user: u64, channel: u64, text: &str) -> bool {
|
||||
self.inner.worker.reply_in(id, user, text, "chat", false, Some(channel))
|
||||
self.inner.worker.reply_in(id, user, text, "chat", false, Some(channel), ¬es_of(&self.inner, user))
|
||||
}
|
||||
|
||||
/// The store the brain's schedule tool works on; without one its actions fail.
|
||||
@@ -535,6 +538,11 @@ impl DiscordCore {
|
||||
let _ = self.inner.schedules.set(store);
|
||||
}
|
||||
|
||||
/// The store of each person's standing instructions.
|
||||
pub fn set_notes(&self, notes: Arc<crate::notes::Notes>) {
|
||||
let _ = self.inner.notes.set(notes);
|
||||
}
|
||||
|
||||
/// The activity log chat actions are recorded in.
|
||||
pub fn set_activity(&self, activity: Arc<crate::activity::Activity>) {
|
||||
let _ = self.inner.activity.set(activity);
|
||||
@@ -544,7 +552,7 @@ impl DiscordCore {
|
||||
pub async fn run_task(&self, id: &str, user: u64, text: &str) -> Option<String> {
|
||||
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||
self.inner.tasks.lock().unwrap().insert(id.to_owned(), tx);
|
||||
if !self.inner.worker.reply(id, user, text, "task", false) {
|
||||
if !self.inner.worker.reply_in(id, user, text, "task", false, None, ¬es_of(&self.inner, user)) {
|
||||
self.inner.tasks.lock().unwrap().remove(id);
|
||||
return None;
|
||||
}
|
||||
@@ -789,6 +797,14 @@ fn report_chat_channels(inner: &Inner) {
|
||||
inner.worker.chat_channels(inner.bot_id.get().copied(), &inner.settings.chat_channels);
|
||||
}
|
||||
|
||||
/// The person's standing instructions for a reply; none with `features.notes` off.
|
||||
fn notes_of(inner: &Inner, user: u64) -> Vec<String> {
|
||||
match inner.notes.get() {
|
||||
Some(n) if inner.settings.features.notes => n.texts_of(user),
|
||||
_ => vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn should_hear(inner: &Inner, user: u64) -> bool {
|
||||
if Some(user) == inner.bot_id.get().copied() {
|
||||
return false;
|
||||
@@ -905,6 +921,19 @@ async fn worker_task(core: std::sync::Weak<Inner>, mut rx: mpsc::UnboundedReceiv
|
||||
core.inner.worker.chat_action_result(&a.id, result);
|
||||
});
|
||||
}
|
||||
WorkerEvent::NoteAction(a) => {
|
||||
let result = match inner.notes.get() {
|
||||
Some(notes) => {
|
||||
let name = a.user.parse().map(|u| name_of(&inner, u)).unwrap_or_else(|_| a.user.clone());
|
||||
crate::notes::act(notes, &a, &name, chrono::Utc::now().timestamp())
|
||||
}
|
||||
None => Err("notes are not available".into()),
|
||||
};
|
||||
if let Err(e) = &result {
|
||||
debug_log!("conversation", "note {} {} refused: {e}", a.action, a.id);
|
||||
}
|
||||
inner.worker.note_action_result(&a.id, result);
|
||||
}
|
||||
WorkerEvent::ScheduleAction(a) => {
|
||||
let result = match inner.schedules.get() {
|
||||
Some(store) => {
|
||||
|
||||
Reference in New Issue
Block a user