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:
javis-bot
2026-11-14 17:10:53 +09:00
parent e4b6327cf9
commit a5bd25b86f
32 changed files with 901 additions and 91 deletions

View File

@@ -48,6 +48,11 @@ class _LlmPaused(Exception):
"""The app paused the LLM (a game runs): nothing is answered until it is ready again."""
# The asker's standing instructions the app sends with a reply (personal_notes.spec.md).
MAX_NOTES = 20
MAX_NOTE_CHARS = 300
class VoiceWorker:
def _partials_held(self) -> bool:
return self.llm_game and self.answering > 0
@@ -347,7 +352,8 @@ class Session:
"chat_delete": self._on_chat_delete, "reply": self._on_reply,
"addressed": self._on_addressed, "rank": self._on_rank,
"chat_channels": self._on_chat_channels, "chat_action_result": self._on_chat_action_result,
"schedule_action_result": self._on_schedule_action_result,
"schedule_action_result": self._on_app_action_result,
"note_action_result": self._on_app_action_result,
"memory_config": self._on_memory_config, "reply_delivered": self._on_reply_delivered,
"prepare": self._on_prepare, "llm": self._on_llm}.get(kind)
if handler is None:
@@ -516,13 +522,14 @@ class Session:
result["error"] = str(msg.get("error") or "the app could not do it")
fut.set_result(result)
async def schedule_action(self, action: str, args: dict) -> dict:
"""Ask the app to add, list or delete a schedule and wait for its answer (or a timeout)."""
async def app_action(self, kind: str, action: str, args: dict) -> dict:
"""Ask the app to add, list or delete a schedule or a note (``kind``) and wait for its answer
(or a timeout)."""
aid = f"{self.worker.chat_action_prefix}-{self.sid}-{next(self._chat_ids)}"
fut = asyncio.get_running_loop().create_future()
self.chat_waiting[aid] = fut
self.send({**args, "type": "schedule_action", "id": aid, "action": action})
debug_log(f"schedule action {aid} {action}", "voice_worker")
self.send({**args, "type": f"{kind}_action", "id": aid, "action": action})
debug_log(f"{kind} action {aid} {action}", "voice_worker")
try:
return await asyncio.wait_for(fut, self.worker.chat_timeout_s)
except asyncio.TimeoutError:
@@ -530,7 +537,7 @@ class Session:
finally:
self.chat_waiting.pop(aid, None)
def _on_schedule_action_result(self, msg: dict) -> None:
def _on_app_action_result(self, msg: dict) -> None:
fut = self.chat_waiting.get(msg.get("id"))
if fut is None or fut.done():
return
@@ -559,16 +566,19 @@ class Session:
return
rid, user, text = got
via, speak, channel = msg.get("via"), msg.get("speak", False), msg.get("channel")
notes = msg.get("notes", [])
if via not in ("voice", "chat", "task") or not isinstance(speak, bool) or len(rid.encode()) > 255 \
or (via == "task" and speak) or not (channel is None or isinstance(channel, str)):
or (via == "task" and speak) or not (channel is None or isinstance(channel, str)) \
or not (isinstance(notes, list) and len(notes) <= MAX_NOTES
and all(isinstance(n, str) and len(n) <= MAX_NOTE_CHARS for n in notes)):
self.error("bad_message", "reply needs via voice|chat|task, a boolean speak (false for a task), "
"an optional string channel and an id under 256 bytes", id=rid)
"an optional string channel, at most 20 string notes and an id under 256 bytes", id=rid)
return
if self.worker.brain is None:
self.error("brain_unavailable", "the worker was started without --brain", id=rid)
return
if via == "task":
asyncio.get_running_loop().create_task(self._task(rid, user, text))
asyncio.get_running_loop().create_task(self._task(rid, user, text, notes))
return
if speak:
self.thinking_replies.add(rid)
@@ -578,9 +588,9 @@ class Session:
waiting = self.worker.replies_unanswered
early = waiting.get(user, 0) > 0 # sent before their previous answer: not a reply to it
waiting[user] = waiting.get(user, 0) + 1
asyncio.get_running_loop().create_task(self._reply(rid, user, text, via, speak, early, channel))
asyncio.get_running_loop().create_task(self._reply(rid, user, text, via, speak, early, channel, notes))
async def _task(self, rid: str, user: str, text: str) -> None:
async def _task(self, rid: str, user: str, text: str, notes: list | None = None) -> None:
"""A scheduled task (schedule.spec.md, "Tasks"): answered in the chat lane with the read-only
tools, its own short-term memory and the person's history scope. It is not a turn of their
conversation, so their turn count and delete confirmations stay as they are."""
@@ -600,7 +610,8 @@ class Session:
history = HistoryContext()
try:
async with self._llm():
answer = await asyncio.to_thread(w.brain.reply, user, text, history, task=True)
answer = await asyncio.to_thread(w.brain.reply, user, text, history, task=True,
notes=notes or [])
except Exception as e: # the brain must never take the session down
debug_log(f"brain task {rid} failed: {type(e).__name__}", "llm")
answer = (answer or "").strip()
@@ -742,9 +753,9 @@ class Session:
asyncio.get_running_loop().create_task(rank())
async def _reply(self, rid: str, user: str, text: str, via: str, speak: bool, early: bool = False,
channel: str | None = None) -> None:
channel: str | None = None, notes: list | None = None) -> None:
try:
await self._reply_inner(rid, user, text, via, speak, early, channel)
await self._reply_inner(rid, user, text, via, speak, early, channel, notes or [])
finally:
self.thinking_replies.discard(rid)
self.cancelled_replies.discard(rid)
@@ -782,7 +793,7 @@ class Session:
self._delivered(rid, ok)
async def _reply_inner(self, rid: str, user: str, text: str, via: str, speak: bool, early: bool,
chat_channel: str | None = None) -> None:
chat_channel: str | None = None, notes: list | None = None) -> None:
w = self.worker
channel = self.voice_channel
# Person first, then lane: a reply waiting for its asker's other answer holds no lane.
@@ -805,15 +816,17 @@ class Session:
from .chat_bridge import ChatBridge
chat = ChatBridge(self, asyncio.get_running_loop(), turn, w.pending_deletes.setdefault(user, {}), user) \
if self.chat_channels else None
from .schedule_bridge import ScheduleBridge
schedule = ScheduleBridge(self, asyncio.get_running_loop(), user, via,
chat_channel if via == "chat" else None)
from .app_bridge import AppBridge
origin = (user, via, chat_channel if via == "chat" else None)
schedule = AppBridge(self, asyncio.get_running_loop(), "schedule", *origin)
notes_backend = AppBridge(self, asyncio.get_running_loop(), "note", *origin)
try:
async with self._llm(rid if speak else None):
w.answering += 1
try:
answer = await asyncio.to_thread(w.brain.reply, user, text, history, chat=chat,
schedule=schedule)
schedule=schedule, notes=notes or [],
notes_backend=notes_backend)
finally:
w.answering -= 1
if not w.answering and w.scheduler: