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,87 @@
|
||||
{% from "_macros.html" import icon %}
|
||||
{#
|
||||
The head, the tab strip and whichever file is in front. Everything the panel
|
||||
swaps, in one fragment.
|
||||
|
||||
Both together, always: rendering only the body would leave the strip showing a
|
||||
tab that is no longer there after a close, and rendering only the strip would
|
||||
leave the previous file on screen after a switch.
|
||||
#}
|
||||
<div class="panel-head">
|
||||
<h2 class="panel-head__title">
|
||||
{{ icon("file-text", "icon--sm") }}
|
||||
<span>{{ doc.title if doc else "Canvas" }}</span>
|
||||
{% if doc and doc.subtitle %}
|
||||
<span class="canvas__where" title="{{ doc.subtitle }}">{{ doc.subtitle }}</span>
|
||||
{% endif %}
|
||||
</h2>
|
||||
|
||||
{% if doc and doc.key.startswith("scratch:") %}
|
||||
{# A copy, like every other attach path -- a transcript must not change
|
||||
because the pad was edited afterwards. #}
|
||||
<button class="btn btn--sm" type="button"
|
||||
hx-post="/api/files/from-scratch"
|
||||
hx-vals='{"chat_id": "{{ chat.id }}"}'
|
||||
hx-target="#attachments" hx-swap="beforeend"
|
||||
title="Put this in the message box as an attachment">
|
||||
{{ icon("attach", "icon--sm") }} Attach
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
<button class="btn btn--icon btn--sm" type="button" data-toggle="#canvas"
|
||||
aria-label="Close canvas">
|
||||
{{ icon("x", "icon--sm") }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{% include "chat/_canvas_tabs.html" %}
|
||||
|
||||
{#
|
||||
Opening one by hand. A path box rather than a file browser: the model opens
|
||||
what it touches, which is the path this feature is really for, and a second
|
||||
directory browser beside the one the composer already has would be a lot of
|
||||
interface for the rarer case. A relative path resolves against the project
|
||||
directory, exactly as it does for the model.
|
||||
#}
|
||||
<div class="canvas__open">
|
||||
{% if canvas_agent %}
|
||||
{# Its own form. A second control named `key` in the same one -- the Scratch
|
||||
button below -- would send two values for one field, and which of them the
|
||||
server took would be an accident. #}
|
||||
<form class="canvas__open-form"
|
||||
hx-post="/api/chats/{{ chat.id }}/canvas/tabs"
|
||||
hx-target="#canvas-inner" hx-swap="innerHTML">
|
||||
<input class="input input--mono canvas__path" type="text" name="key"
|
||||
placeholder="agent:path/to/file" aria-label="Open a file"
|
||||
autocomplete="off" spellcheck="false">
|
||||
<button class="btn btn--sm" type="submit">Open</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
<button class="btn btn--sm" type="button"
|
||||
hx-post="/api/chats/{{ chat.id }}/canvas/tabs"
|
||||
hx-vals='{"key": "scratch:{{ chat.id }}"}'
|
||||
hx-target="#canvas-inner" hx-swap="innerHTML"
|
||||
title="This chat's own working document">
|
||||
{{ icon("file-text", "icon--sm") }} Scratch
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="canvas__body">
|
||||
{% if error %}
|
||||
<div class="alert alert--error" role="alert">
|
||||
{{ icon("warning", "alert__icon") }} <span>{{ error }}</span>
|
||||
</div>
|
||||
{% elif conflict %}
|
||||
{% include "chat/_canvas_conflict.html" %}
|
||||
{% elif doc %}
|
||||
{% include "chat/_canvas_doc.html" %}
|
||||
{% else %}
|
||||
<p class="canvas__empty">
|
||||
Nothing open. A file the model reads or writes appears here, and
|
||||
{% if canvas_agent %}the @ menu can put one here too.{% else %}notes,
|
||||
skills and this chat's own scratch document can be opened from the @ menu.
|
||||
{% endif %}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
Reference in New Issue
Block a user