A menu for what a chat may use, and three keys
Six smaller things, all of them about the interface not saying what is true.
The @ button only ever inserted the character, which the @ key already does
without a button. It becomes the scope menu: what this chat may use, switched
off per chat. Chat.scope_json is filtered inside resolve_tools AFTER the
capability, permission and instance gates -- exactly as chat.knowledge_bases
narrows knowledge_search -- so a crafted POST turning something on reaches a
tool the gates already removed, and there is a test that writes the column
directly to prove it. Absent means on, for every key, so "why is this off?" has
one answer. It is keyed on the gate rather than the tool name, so notes is one
switch rather than five. The switches carry no role="menuitem", deliberately:
ui.js closes a picker when a menuitem is clicked, which is right for an action
menu and wrong for a list you want to set several of -- which is why the menu
needs no JavaScript at all. Typing @ is untouched.
With no skills, nothing should mention them. tool.skills was gated on the family
alone, so somebody with an empty library was told "the list below gives each
one's name" above no list, handed skill_get, and watched the model spend a round
finding out. It requires skills now; the writing half moved to
tool.skills_write, which is deliberately not gated, because saving the first one
is what somebody with none most needs. And core.tool_list finally reads
tool_names, which had been resolved and documented with no fragment using it.
The composer's toolbar is one row again. .composer__actions is last in the DOM
with margin-left:auto, so the moment an agent chat added a connection, a
directory and a mode, Send and the microphone dropped to a second line.
chat.css has no media queries by design and the fix is not to add one:
.composer__context is the single child allowed to shrink and scroll sideways.
There is a test asserting the file still contains no @media.
The effort picker shows the level in force. "Effort: default" named no level and
was true of nothing in particular; chat.resolved_effort is the chat's own value
and build_request reads the same field, so what is shown is what is sent. The
model's default is a seed, copied onto the row at creation and on a model
change, and never consulted at request time -- a fallback would resurrect it
underneath a cleared effort and make "off" silently do nothing. "off" is a
sentinel and not an empty value, because start_chat declares Form("") and cannot
tell absent from empty: with value="" the reader picks off and gets high.
Alt+M dictates, Alt+R reads the last reply aloud, Ctrl+Enter sends from
anywhere. All three click the button that already does the job, so audio.js
keeps its one delegated listener. Alt+M and not Alt+D, which is the address bar
in Chrome and Firefox. Ctrl+Enter never means Stop -- Send and Stop are the same
element, and Esc already stops. Driven under a DOM stub before committing, per
the rule in CLAUDE.md, and tests/test_commands_js.py pins that every key has a
row in SHORTCUTS, since /help reads that list.
And the memory tooling, which had seven defects. The worst: memory_forget was a
case-insensitive substring first-match delete with nothing warning about it, so
forgetting "coffee" against "Drinks coffee black" and "Allergic to coffee"
silently removed whichever was older -- a wrong deletion nobody would ever find
out about, from a tool whose description invited exactly the short fragment that
misfires. It matches exactly first, then by substring, and refuses an ambiguous
one while naming what it matched. add() refuses an exact duplicate. The
at-the-limit refusal no longer tells the model to delete one to make room: past
the block's budget it is not shown all of them and would be guessing, which
feeds straight back into the first defect. And context.memories no longer claims
the memories "still apply", which nothing checks and which taught a model to
trust a stale one over what the person had just said.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
"""Memory: the two ways it used to lose somebody's facts quietly.
|
||||
|
||||
`memory_forget` was a case-insensitive substring FIRST-match delete with nothing
|
||||
warning about it, so a short fragment removed whichever memory happened to be
|
||||
older -- and a wrong deletion here is not something anybody finds out about.
|
||||
`memory_add` had no defence against the same fact being stored four times in
|
||||
slightly different words, which costs the window forever *and* makes every
|
||||
forget after it ambiguous.
|
||||
|
||||
Both are asserted on the rows, not on the wording.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import func, select
|
||||
|
||||
from lembas.db.models import Memory, User
|
||||
from lembas.security.passwords import hash_password
|
||||
from lembas.services import tools as tools_service
|
||||
from lembas.services.library import memories as memories_service
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def owner(db):
|
||||
user = User(name="Frodo", email="f@shire.test", password_hash=hash_password("x"))
|
||||
db.add(user)
|
||||
db.commit()
|
||||
return user
|
||||
|
||||
|
||||
def _count(db, owner) -> int:
|
||||
return db.scalar(
|
||||
select(func.count()).select_from(Memory).where(Memory.owner_id == owner.id)
|
||||
)
|
||||
|
||||
|
||||
def _forget(owner, text: str):
|
||||
import asyncio
|
||||
|
||||
context = tools_service.ToolContext(owner_id=owner.id)
|
||||
return asyncio.run(tools_service.run_tool(context, "memory_forget", f'{{"content": "{text}"}}'))
|
||||
|
||||
|
||||
# --- Forgetting ----------------------------------------------------------------
|
||||
def test_an_ambiguous_forget_removes_nothing(db, owner):
|
||||
"""Two memories about coffee; "coffee" names neither of them."""
|
||||
memories_service.add(db, owner=owner, content="Drinks coffee black.")
|
||||
memories_service.add(db, owner=owner, content="Allergic to coffee.")
|
||||
|
||||
outcome = _forget(owner, "coffee")
|
||||
|
||||
assert _count(db, owner) == 2
|
||||
assert outcome.event["status"] == "error"
|
||||
assert "Drinks coffee black." in outcome.content
|
||||
assert "Allergic to coffee." in outcome.content
|
||||
|
||||
|
||||
def test_quoting_a_memory_in_full_removes_that_one(db, owner):
|
||||
"""Exact-first is what makes this work. "Drinks coffee." is a substring of
|
||||
"Drinks coffee. Never tea." too, so a substring-only match would call the
|
||||
unambiguous case ambiguous and refuse to do anything at all."""
|
||||
short = memories_service.add(db, owner=owner, content="Drinks coffee.")
|
||||
long = memories_service.add(db, owner=owner, content="Drinks coffee. Never tea.")
|
||||
short_id, long_id = short.id, long.id
|
||||
|
||||
_forget(owner, "Drinks coffee.")
|
||||
|
||||
db.expire_all()
|
||||
assert db.get(Memory, short_id) is None
|
||||
assert db.get(Memory, long_id) is not None
|
||||
|
||||
|
||||
def test_forgetting_something_that_is_not_there_says_so(db, owner):
|
||||
memories_service.add(db, owner=owner, content="Drinks coffee black.")
|
||||
outcome = _forget(owner, "tea")
|
||||
assert _count(db, owner) == 1
|
||||
assert outcome.event["status"] == "error"
|
||||
|
||||
|
||||
def test_an_unambiguous_fragment_still_works(db, owner):
|
||||
"""Quoting in full is what the description asks for, but a fragment that
|
||||
genuinely names one memory should not be made to fail."""
|
||||
memories_service.add(db, owner=owner, content="Drinks coffee black.")
|
||||
memories_service.add(db, owner=owner, content="Lives in Bree.")
|
||||
|
||||
_forget(owner, "Bree")
|
||||
|
||||
db.expire_all()
|
||||
assert _count(db, owner) == 1
|
||||
|
||||
|
||||
# --- Adding --------------------------------------------------------------------
|
||||
def test_an_exact_duplicate_creates_nothing(db, owner):
|
||||
first = memories_service.add(db, owner=owner, content="Prefers metric units.")
|
||||
again = memories_service.add(db, owner=owner, content=" Prefers metric units. ")
|
||||
|
||||
assert _count(db, owner) == 1
|
||||
assert again.id == first.id
|
||||
|
||||
|
||||
def test_the_limit_refuses_and_does_not_tell_the_model_to_guess(db, owner, monkeypatch):
|
||||
"""Past MAX_TOTAL_CHARS the injected block is truncated, so the model is not
|
||||
shown every memory. Telling it to remove one to make room asks it to choose
|
||||
blind -- and the forget path above is exactly where blind guessing bites."""
|
||||
monkeypatch.setattr(memories_service, "MAX_RECORDS", 3)
|
||||
for index in range(3):
|
||||
memories_service.add(db, owner=owner, content=f"Fact {index}")
|
||||
|
||||
with pytest.raises(ValueError) as caught:
|
||||
memories_service.add(db, owner=owner, content="One too many")
|
||||
|
||||
assert _count(db, owner) == 3
|
||||
message = str(caught.value)
|
||||
assert "note instead" in message
|
||||
assert "Remove one first" not in message
|
||||
Reference in New Issue
Block a user