A directory the model knows about, and @ to name a file in it
An agent chat used to open with the model knowing the name of a machine and nothing about what was on it, so the first two rounds of every reply went on finding out. It now gets a listing: one read-only command, `git ls-files` where that works and `find` otherwise, falling back to an SFTP walk that always does. git first because a repository already carries somebody's considered list of what is not part of the project, and reproducing it by hand is how an index ends up mostly build output. The listing is budgeted rather than dumped. A tree of a thousand files is worse than no tree -- it costs the window on every request forever and buries the four names that mattered -- so directories that will not fit are shown as a count and the model is told to open one itself. Collapsing picks the deepest and largest first: by saving alone it would take `src/` before `src/web/static/vendor/`, because it contains it, and lose every name worth having. Read from a cache and never fetched. `harness.context_variables` is synchronous and sits on the request path; the walk happens in the generation setup, which is async and already doing network work, with a short wait. A chat whose first reply outruns its first walk simply has no listing that turn and the fragment disappears rather than appearing as an empty heading. Then `@`, over the same index and over the library, and `/` for commands with an Alt-based keyboard for the same jobs. A mentioned file arrives as contents, not a reference -- a small model asked to call file_read often does not bother -- and it arrives with its absolute path and the machine it came from, because a model handed `main.py` cannot tell which of four it is and cannot name it back when asked to change something. The rule that matters for `/`: a message that merely starts with a slash still sends. `//` escapes and an unrecognised command is posted as written. Swallowing somebody's message is a much worse failure than an unknown command. Two exceptions to Manual mode now, not one. Browsing and indexing are a person acting, not a model, so neither passes through policy.py -- the same argument the terminal panel rests on. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -244,6 +244,53 @@ async def inspect_chat(request: Request, db: Db, user: RequiredUser, chat_id: st
|
||||
)
|
||||
|
||||
|
||||
@router.get("/{chat_id}/usage")
|
||||
async def chat_usage(request: Request, db: Db, user: RequiredUser, chat_id: str) -> Response:
|
||||
"""What this conversation has cost, and how full the window is.
|
||||
|
||||
Owner-checked and nothing else: it is your own chat's totals. Unlike the
|
||||
inspector next door there is no admin branch, because there is no reason
|
||||
for one -- the numbers describe a conversation, and reading somebody's
|
||||
conversation is exactly what `sharing` has no admin branch for either.
|
||||
|
||||
Summed from what each reply recorded rather than recomputed: an endpoint
|
||||
that reported no usage contributed an estimate at the time, and re-deriving
|
||||
it now with a different estimator would make the totals move under a chat
|
||||
that had not changed.
|
||||
"""
|
||||
chat = _owned_chat(db, chat_id, user.id)
|
||||
replies = list(
|
||||
db.scalars(
|
||||
select(Message)
|
||||
.where(Message.chat_id == chat.id, Message.role == ROLE_ASSISTANT)
|
||||
.order_by(Message.created_at)
|
||||
)
|
||||
)
|
||||
|
||||
totals = {"prompt": 0, "completion": 0, "total": 0}
|
||||
estimated = False
|
||||
for reply in replies:
|
||||
usage = metrics_service.from_message(reply.usage_json)
|
||||
totals["prompt"] += usage.prompt_tokens
|
||||
totals["completion"] += usage.completion_tokens
|
||||
totals["total"] += usage.total_tokens
|
||||
estimated = estimated or usage.estimated
|
||||
|
||||
last = replies[-1] if replies else None
|
||||
return render(
|
||||
request,
|
||||
"chat/_usage.html",
|
||||
{
|
||||
"chat": chat,
|
||||
"totals": totals,
|
||||
"estimated": estimated,
|
||||
"replies": len(replies),
|
||||
"metrics": metrics_service.from_message(last.usage_json if last else None),
|
||||
"model": chat_service.model_for(db, chat),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
# Roughly what a downscaled phone photo comes to as base64. The exact figure
|
||||
# does not matter; putting megabytes of it into the DOM does.
|
||||
_REDACTED_URI = "data:…base64 image omitted…"
|
||||
|
||||
Reference in New Issue
Block a user