feat(nutrition): meals belong to the person who logged them
- meals.user_id (v1 databases gain it on open, DEFAULT '' keeps their meals the single user's); insert_meal, get_meals_between and delete_meal take the person, and delete only removes that person's meal. - turn_state.set_user / ToolContext.user_id carry the asker; logMeal, fetchMeals and deleteMeal use it. The v2 brain sets it for each reply. - Tests: two people never see or delete each other's meals, no user is v1's single user, and a v1 database opens with its meals kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,7 @@ class ToolContext:
|
||||
user_print: Callable[[str], None],
|
||||
language: Optional[str] = None,
|
||||
broadcasting: Optional[bool] = None,
|
||||
user_id: str = "",
|
||||
):
|
||||
self.db = db
|
||||
self.cfg = cfg
|
||||
@@ -44,6 +45,9 @@ class ToolContext:
|
||||
# ``None`` means "no signal" (evals, text entry, older bot): callers
|
||||
# fall back to the master flag so behaviour is unchanged.
|
||||
self.broadcasting = broadcasting
|
||||
# v2: the person asking (Discord user ID); '' is v1's single user.
|
||||
# Personal data (meals) is stored and read under this person only.
|
||||
self.user_id = user_id
|
||||
|
||||
|
||||
class Tool(ABC):
|
||||
@@ -115,10 +119,11 @@ class Tool(ABC):
|
||||
# thread-local state (set by the bridge) rather than threaded through
|
||||
# the whole engine call chain. Absent (eval / unit test) -> None.
|
||||
try:
|
||||
from jarvis.reply.turn_state import get_broadcasting
|
||||
from jarvis.reply.turn_state import get_broadcasting, get_user
|
||||
broadcasting = get_broadcasting()
|
||||
user_id = get_user() or ""
|
||||
except Exception:
|
||||
broadcasting = None
|
||||
broadcasting, user_id = None, ""
|
||||
context = ToolContext(
|
||||
db=db,
|
||||
cfg=cfg,
|
||||
@@ -129,5 +134,6 @@ class Tool(ABC):
|
||||
user_print=user_print,
|
||||
language=language,
|
||||
broadcasting=broadcasting,
|
||||
user_id=user_id,
|
||||
)
|
||||
return self.run(tool_args, context)
|
||||
|
||||
Reference in New Issue
Block a user