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:
Jaroslav Beneš
2026-08-03 11:22:03 +02:00
parent 39ff34ffac
commit 0452e742e8
20 changed files with 1308 additions and 81 deletions
+82 -7
View File
@@ -55,6 +55,11 @@ KEEPALIVE_AFTER = 15.0
# better than four hundred rows nobody meant to write.
MAX_QUEUED = 10
# How many things one chat may have switched off. There are a dozen families and
# sixty skills at most, so this is not a limit anybody reaches by hand -- it is
# there so a crafted POST cannot grow the column without bound.
MAX_SCOPE_KEYS = 200
def _owned_chat(db: DBSession, chat_id: str, user_id: str) -> Chat:
chat = db.get(Chat, chat_id)
@@ -135,10 +140,19 @@ def _new_chat(
if profile is not None and agent_mode.strip() in agent_policy.MODES:
chat.agent_mode = agent_mode.strip()
# After the model's defaults, so choosing one on the new-chat screen wins
# over the administrator's. Empty means "whatever the model said", not
# "none" -- clearing it is what the blank option on an existing chat does.
# over the administrator's.
#
# `"off"` is a sentinel, and it has to be: `reasoning_effort` arrives as
# `Form("")`, so an absent field and an empty one are indistinguishable --
# the FastAPI trap this codebase has already been bitten by once. With
# `value=""` on the off option, the reader would pick "off", the value would
# fall out of EFFORTS, the model's default seeded above would stay, and they
# would silently get "high". The picker shows what will be sent, so the two
# have to agree.
wanted_effort = reasoning_effort.strip().lower()
if wanted_effort in chat_service.EFFORTS:
if wanted_effort == "off":
chat.params_json = {k: v for k, v in chat.params_json.items() if k != "reasoning_effort"}
elif wanted_effort in chat_service.EFFORTS:
chat.params_json = {**chat.params_json, "reasoning_effort": wanted_effort}
db.add(chat)
db.commit()
@@ -518,6 +532,54 @@ async def attach_base(
)
@router.post("/{chat_id}/scope")
async def set_scope(
db: Db,
user: RequiredUser,
chat_id: str,
kind: str = Form(""),
name: str = Form(""),
on: bool = Form(False),
) -> Response:
"""Turn one thing this chat may use on or off. **Narrowing only.**
Nothing here widens anything. `resolve_tools` applies this *after* the
model's capabilities, the reader's permissions and the instance
configuration, so a crafted POST turning something on reaches a tool those
gates have already removed -- there is a test for exactly that.
On is stored by **removing** the key rather than by writing True, so absent
stays the single representation of "on" and the column cannot grow a row per
family per chat. Bounded, so a crafted request cannot grow it either.
JSON reassignment rather than mutation: a plain dict assignment into a JSON
column is not detected.
"""
chat = _owned_chat(db, chat_id, user.id)
bucket = {"family": "families", "skill": "skills"}.get(kind.strip())
wanted = name.strip()[:64]
if bucket is None or not wanted:
raise HTTPException(status.HTTP_400_BAD_REQUEST, "Say what to turn on or off.")
scope = dict(chat.scope_json or {})
entries = dict(scope.get(bucket) or {})
if on:
entries.pop(wanted, None)
else:
if len(entries) >= MAX_SCOPE_KEYS:
raise HTTPException(status.HTTP_409_CONFLICT, "Too many things switched off.")
entries[wanted] = False
if entries:
scope[bucket] = entries
else:
scope.pop(bucket, None)
chat.scope_json = scope
db.commit()
return Response(status_code=status.HTTP_204_NO_CONTENT)
@router.post("/{chat_id}/keep")
async def keep_chat(db: Db, user: RequiredUser, chat_id: str) -> Response:
"""Stop a temporary chat being temporary.
@@ -1373,20 +1435,33 @@ async def update_chat(request: Request, db: Db, user: RequiredUser, chat_id: str
**_clean_params(**{k: str(v) for k, v in submitted_params.items()}),
}
# Not a number, so it cannot go through _PARAM_RANGES. Empty means clear it,
# the same as every other parameter here; anything that is not one of the
# three is ignored rather than refused, so a typo does not cost a message.
# Not a number, so it cannot go through _PARAM_RANGES. `"off"` and empty
# both clear it -- the sentinel because that is what the picker sends now,
# empty because anything still posting the old value must keep working.
# Anything that is neither is ignored rather than refused, so a typo does
# not cost a message.
if "reasoning_effort" in form:
if not allowed.get("chat.params"):
raise HTTPException(
status.HTTP_403_FORBIDDEN, "You may not change sampling parameters."
)
wanted = str(form["reasoning_effort"]).strip().lower()
if not wanted:
if not wanted or wanted == "off":
chat.params_json = {**(chat.params_json or {}), "reasoning_effort": None}
elif wanted in chat_service.EFFORTS:
chat.params_json = {**(chat.params_json or {}), "reasoning_effort": wanted}
# Switching model re-seeds an effort that was never chosen, so "what the
# picker shows is what is sent" stays true afterwards. Only when the key is
# ABSENT: `None` means somebody cleared it deliberately, and resurrecting
# that would make "off" silently do nothing on the next model change.
if model_id and "reasoning_effort" not in (chat.params_json or {}):
seeded = ((match.params_json if match is not None else None) or {}).get(
"reasoning_effort"
)
if seeded in chat_service.EFFORTS:
chat.params_json = {**(chat.params_json or {}), "reasoning_effort": seeded}
db.commit()
return Response(status_code=status.HTTP_204_NO_CONTENT)