Files, open beside the conversation
A third side panel, built the way the terminal is and filled the way the inspector is: tabs holding open files. Project files over SFTP in an agent chat; notes, skills, knowledge documents, this chat's text attachments and its own scratch document everywhere. Read with pygments, edited in a plain textarea, saved with a conflict check. A bug found on the way in, and the reason this needed its own read path. `ssh.read_file` ends in `clean_output`, which strips ANSI escapes and decodes with errors="replace" -- right for the output of a command, and fatal for an editor: open a file containing an escape byte, press Save, and you have silently rewritten it with the escapes gone and every undecodable byte replaced by U+FFFD. `read_text`/`write_text` decode strictly, report binary rather than mangling it, carry an mtime:size token for a file that moved underneath, and refuse an oversize write rather than truncating -- `write_file` truncates because a model is told how many bytes it wrote, and somebody pressing Save is not. The model-facing pair is untouched: what it returns is a contract a model has been shown. A truncated read opens read-only for the mirror-image reason. Six sources go through one dispatch table, for the reason tool_labels.py is a table: six independently written permission checks is how one ends up written slightly differently, and that failure looks like editing somebody else's note. A save on a project file bypasses agent/policy.py, which makes it the fourth documented exception to "the modes do not govern the keyboard" and the first that writes. Same argument as the terminal panel -- whoever owns the credential could write the file with scp -- but the consequence is larger and is now said out loud rather than left to be inferred. The model opens tabs from the file tools it was already calling, so no new schema and no tokens. It never brings one to the front: an agent reads forty files in a long reply, and taking the screen each time would drag somebody through all of them and lose any edit in progress. Only the strip is streamed, guarded on truthiness so the frame can never blank itself -- an empty one would close every open tab, the approval card you could press twice with the sign reversed. Both halves are settled on the server, which is why canvas.js needs no guard against a swap at all. No vendored editor. CodeMirror 6 needs a bundler, which is hard rule 1; CodeMirror 5 would be a larger payload than xterm on every page, and xterm is the one heavy dependency precisely because it loads only where it can be used. So: server-rendered highlighting for reading, a textarea for writing, and the panel says there is no colour while you type rather than pretending. Also here: a scratch document per chat, with `scratch_write` at RISK_READ on plan_update's argument, and a test pinning the three numbers that decide a panel's width -- LAYOUT_BOUNDS drops an unknown variable silently, so a panel missing from it has a drag handle that works and forgets. Driven under a DOM stub and against the running application. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -28,6 +28,7 @@ from sqlalchemy import select
|
||||
|
||||
from lembas.db.models import KIND_AGENT, ROLE_ASSISTANT, ROLE_USER, Chat, Message, User
|
||||
from lembas.db.session import session_scope
|
||||
from lembas.services import canvas as canvas_service
|
||||
from lembas.services import chat as chat_service
|
||||
from lembas.services import compaction as compaction_service
|
||||
from lembas.services import interaction, settings_store, tokens, tool_labels
|
||||
@@ -167,6 +168,12 @@ class Generation:
|
||||
# `_persist` stays one writer with one rule; only this decides whether the
|
||||
# tools are withdrawn for a final round.
|
||||
plan_final: bool = False
|
||||
# Which files this reply has put in the canvas panel. Seeded once from
|
||||
# `chat.canvas_json` where `_run` already has the chat loaded, then mutated
|
||||
# in place -- two `file_read` calls in one round that each re-read the row
|
||||
# would leave only the second, which is the lost update `plan` above
|
||||
# documents. Folded back by `_persist`, the single writer.
|
||||
canvas: dict = field(default_factory=dict)
|
||||
# The queue, seen from the reply's side. `drained` says this reply's ending
|
||||
# handed the next waiting prompt to a fresh one; `injected_ids` names the
|
||||
# prompts taken into *this* reply between two rounds of tool calls. Both are
|
||||
@@ -413,6 +420,12 @@ async def _run(generation: Generation) -> None:
|
||||
# worth asking for. Read here with the rest, because titling happens
|
||||
# after this session has closed.
|
||||
title_from_prompt = chat.kind == KIND_AGENT
|
||||
# Seeded once, here, where the chat is already loaded. Mutated from
|
||||
# then on; see the field's own note.
|
||||
generation.canvas = {
|
||||
"tabs": list((chat.canvas_json or {}).get("tabs") or []),
|
||||
"active": (chat.canvas_json or {}).get("active") or "",
|
||||
}
|
||||
# Read here, with the rest, because titling happens after this
|
||||
# session has closed and must not open another one.
|
||||
title_prompt = prompts_service.resolve(db, "task.title")
|
||||
@@ -643,6 +656,13 @@ async def _run(generation: Generation) -> None:
|
||||
generation.tool_events.append(outcome.event)
|
||||
generation.output_bytes += len(outcome.content)
|
||||
messages.append(tools_service.tool_turn(call, outcome.content))
|
||||
if opened := outcome.event.get("canvas"):
|
||||
# A runner cannot write the message row, so the loop carries
|
||||
# this exactly as it carries a merged plan. Never activated:
|
||||
# an agent reads forty files in a long reply, and dragging
|
||||
# somebody through all of them -- or away from a file they
|
||||
# are editing -- is what makes a panel like this unusable.
|
||||
canvas_service.open_tab(generation.canvas, opened, activate=False)
|
||||
if outcome.event.get("plan"):
|
||||
generation.plan = outcome.event["plan"]
|
||||
# Only `plan_submit` sets this. `plan_update` writes the
|
||||
@@ -1591,6 +1611,11 @@ def _persist(generation: Generation, title: str, elapsed: float) -> None:
|
||||
message.reasoning_ms = generation.reasoning_ms
|
||||
message.tool_calls_json = generation.tool_events
|
||||
message.plan_json = generation.plan or {}
|
||||
if generation.canvas.get("tabs"):
|
||||
# A union with whatever the row says *now*, not an overwrite:
|
||||
# the snapshot above was seeded when the reply began, and
|
||||
# somebody may have opened a tab by hand since.
|
||||
chat.canvas_json = canvas_service.merge(chat.canvas_json, generation.canvas)
|
||||
if generation.plan:
|
||||
# This bubble now carries the plan in force, and the chat points
|
||||
# at it so the harness can find it with one primary-key lookup
|
||||
|
||||
Reference in New Issue
Block a user