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:
co-authored by
Claude Opus 5
parent
2c914993aa
commit
5766446b84
@@ -0,0 +1,74 @@
|
||||
{% from "_macros.html" import icon %}
|
||||
{#
|
||||
One file, read or edited.
|
||||
|
||||
A read/edit split rather than a highlighting editor, because there is no
|
||||
vendored code editor and adding one would be a build step (hard rule 1) or a
|
||||
payload larger than xterm's on every page in the application -- and xterm is
|
||||
called out as the one heavy dependency precisely because it loads only on a
|
||||
chat that can open a terminal.
|
||||
|
||||
So: pygments server-side for reading, and a plain <textarea> for writing. A
|
||||
textarea's value is text by construction, which is the same argument as
|
||||
"attachments are served, never linked" -- pick the shape where the failure
|
||||
cannot happen rather than the shape where it has to be prevented.
|
||||
|
||||
`rendered` is the ONE `|safe` here. It is either pygments output, which
|
||||
escapes what it is given, or render_markdown, which is the single path in this
|
||||
application allowed to emit HTML.
|
||||
#}
|
||||
<div class="canvas__doc" x-data="{ editing: false }" data-canvas-doc="{{ doc.key }}">
|
||||
|
||||
{% if doc.binary %}
|
||||
<p class="canvas__note">
|
||||
{{ icon("warning", "icon--sm") }}
|
||||
This does not look like text, so there is nothing to show and nothing that
|
||||
could safely be saved back.
|
||||
</p>
|
||||
{% elif doc.truncated %}
|
||||
<p class="canvas__note">
|
||||
{{ icon("warning", "icon--sm") }}
|
||||
Showing the beginning only. Saving from here would delete the rest, so this
|
||||
one is read-only.
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if doc.editable %}
|
||||
<div class="canvas__actions" x-show="!editing">
|
||||
<button class="btn btn--sm" type="button"
|
||||
@click="editing = true; $nextTick(() => $refs.editor.focus())">
|
||||
{{ icon("pencil", "icon--sm") }} Edit
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="canvas__view" {% if doc.editable %}x-show="!editing"{% endif %}>
|
||||
{% if rendered %}
|
||||
{{ rendered | safe }}
|
||||
{% else %}
|
||||
<p class="canvas__empty">This file is empty.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if doc.editable %}
|
||||
<form class="canvas__form" x-show="editing" x-cloak
|
||||
hx-post="/api/chats/{{ chat.id }}/canvas/save"
|
||||
hx-target="#canvas-inner" hx-swap="innerHTML">
|
||||
<input type="hidden" name="key" value="{{ doc.key }}">
|
||||
{# What version this was opened at. The save compares it and refuses a file
|
||||
that moved underneath, rather than overwriting somebody else's work. #}
|
||||
<input type="hidden" name="revision" value="{{ doc.revision }}">
|
||||
<label class="visually-hidden" for="canvas-editor">{{ doc.title }}</label>
|
||||
<textarea class="canvas__editor" id="canvas-editor" name="text"
|
||||
spellcheck="false" x-ref="editor"
|
||||
data-canvas-editor>{{ doc.text }}</textarea>
|
||||
<div class="canvas__actions">
|
||||
<button class="btn btn--primary btn--sm" type="submit">
|
||||
{{ icon("check", "icon--sm") }} Save
|
||||
</button>
|
||||
<button class="btn btn--sm" type="button" @click="editing = false">Cancel</button>
|
||||
<span class="canvas__hint">No colour while you type. Tab inserts a tab.</span>
|
||||
</div>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
Reference in New Issue
Block a user