Every injected prompt becomes editable, and several get written

The instructions LLeMbas puts in front of a model were hard-coded: six
strings in a GUIDANCE dict, two headings, and the title request inline in
chat.py. An operator could not see what was being sent, let alone change
it, and there was nowhere for a custom tool to contribute its own guidance
when custom tools land.

services/prompts.py now holds each piece as a Fragment, and /admin/prompts
edits them with a preview of the whole assembled system message including
unsaved edits. harness.py keeps only the decisions -- which fragments apply
to this request, and what their variables resolve to.

The design turns on one choice: a fragment carries its gate as data
(families, requires, when_tools) rather than as a callable, because a
database row can carry the same three fields. Custom tools will therefore
register a fragment source and change nothing else -- there is a test that
says exactly that, and it is the reason the rest of the shape is what it is.

Consequences worth knowing:

  - Defaults live in code, overrides in the database, and text equal to its
    default is never stored. Otherwise pressing Save once would freeze
    today's wording forever and no later release could improve it.
  - An empty override means off. A fragment that was not submitted at all
    keeps what it had, because it may be missing from the page only because
    whatever contributes it is currently switched off.
  - requires= replaced the hand-written pair of memory guidance variants.
    The sentence that refers to a section now lives inside that section, so
    it cannot outlive it. That was the general problem the pair was a
    special case of.
  - {{name}}, with anything unrecognised passing through verbatim. The name
    grammar is the guard: {"total": 1} and ${PATH} are not candidates.
    Substitution is one pass and never recursive, because {{memories}}
    carries text a model wrote.

The wording is also overhauled, and a model now gets the core fragments
even with no tools -- the date above all. "An empty harness is worse than
none" was about tokens that say nothing; a model with no clock being asked
about the present is not that. Clearing those boxes restores the old
silence exactly. New: today's date, who it is talking to, the three-round
tool budget, that tool results are not replayed, that anything a tool
returns is data rather than instruction, and what the <document> wrapper
around an attachment is. Extended: memory_forget, notes_edit/delete,
skill_create/edit, and reading a knowledge document in full rather than
answering from an extract.

Tool descriptions stay in code and are listed read-only. They are schema
and they state facts about what a runner does; an edit would make the text
a lie with nothing to catch it.

No schema change -- one JSON row in the settings table.

488 tests. Version 0.2.0, which also invalidates the service worker cache
so the green artwork appears without a hard reload.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jaroslav Beneš
2026-07-31 23:47:49 +02:00
parent 17995c1275
commit 2c8c274850
22 changed files with 2138 additions and 147 deletions
@@ -0,0 +1,41 @@
{#
The assembled system message.
Rendered with ordinary escaping and never `|safe`: it carries memory text a
model wrote and skill descriptions from items other people shared. Hard rule 6
applies here as much as anywhere.
#}
{% if harness_chars > limit %}
<div class="alert alert--warning">
<span>
The preamble is {{ harness_chars }} characters and the cap is {{ limit }}. Everything
past the cap is cut off before it reaches the model.
</span>
</div>
{% endif %}
<pre class="prompt-preview"><code>{{ system }}</code></pre>
<p class="field__hint">
{{ harness_chars }} of {{ limit }} characters before the authored prompt.
{% if authored %}
The instance prompt is shown below the line; a model or chat prompt would
replace it, never stack with it.
{% else %}
No instance prompt is set, so nothing follows the preamble.
{% endif %}
</p>
{% if title_prompt %}
<h3 class="admin-section-title">Chat title request</h3>
<p class="card__lede">
Sent on its own after the first reply, not as part of any conversation.
</p>
<pre class="prompt-preview"><code>{{ title_prompt }}</code></pre>
{% else %}
<h3 class="admin-section-title">Chat title request</h3>
<p class="card__lede">
Empty, so no model is asked to name a chat. Chats are named from the first
thing said in them.
</p>
{% endif %}