Knowledge, notes, memory and skills, and a harness to make them used
Four places a model can reach for, differing in who writes a record and how it gets in front of the model. **Knowledge** is uploaded by a person and searched by the model. It goes through `services/files.py:prepare` — the same pipeline as a chat attachment — so the same PDF produces the same text whichever way it arrived, and `Document` carries the same content columns as `Attachment` for the same reason. **Notes** are written by the model and edited by you. Too long to inject, so they are searched. **Memory** is short facts, and every one of them goes into every request. That single decision is where the rest of its design comes from: records are capped short, the block has a budget, there is no search tool because the model is already looking at them, and they are not shareable — a record about a person is not content to hand round. **Skills** are saved procedures. Only the name and description are injected; the body is fetched when the model decides one applies, which is what makes a hundred skills affordable. A model may write and revise its own — the safety story is not a gate but a record: every revision is kept, attributed and revertible. A model that has just read a hostile page can save a skill that outlives the conversation, and the honest mitigation is that it is visible and undoable rather than that it was prevented. **The harness** is why any of it gets used. A model handed a tools array ignores it and answers from recall, because nothing in the request suggests otherwise. `services/harness.py` assembles a preamble from what this chat actually has: when to reach for each tool, the memories, the skill index. This is an exception to "system prompts are precedence, not concatenation", and a deliberate one. That rule governs the three *authored* layers and is untouched — exactly one still wins. The harness is a different axis: it describes the machinery rather than the behaviour, nobody authored it, and there is nothing for it to disagree with. It is prepended to whichever authored prompt won, in one system message, since several endpoints reject a second. Supporting changes: - **Sharing**, in one helper. `visible_to()` is the only definition of who can see a library item and every listing and tool goes through it. Sharing grants *reading*; two people editing one note with no history and no merge is worse than copying it. **Administrators do not bypass this** — they bypass permissions elsewhere because an admin can grant themselves those anyway, but reading somebody's private notes is a different act. - **FTS5**, created by `db/migrations.py:ensure_fts` with the triggers an external-content index needs. Idempotent, like the column sync beside it. Terms are ANDed and then ORed: the caller is usually a model writing a whole question, and requiring every word loses the match on one absent term. - **The attach button is a menu** — file, image, a web page, or a document from the library. Attaching a document copies it, because history must not change when a document is edited later. - **A URL fetcher with an SSRF guard.** This server can reach the router, the other services on the box and LLeMbas itself, and the address can come from a model. Private ranges are refused *after resolution* and redirects are followed by hand so every hop is checked. An admin can open it deliberately. - **Model capabilities split** into protocol support and a toggle per built-in tool. Rows predating the split have no `tool_*` keys, and absent counts as on when `tools` is on — otherwise an upgrade silently takes web search away from every model already configured for it. Also fixes the test fixture, which built the schema with `create_all` and so ran against a database without the FTS tables production has; it now runs `sync_schema`, the same path startup takes. 430 tests, ruff clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
{% extends "library/_layout.html" %}
|
||||
{% from "_macros.html" import icon %}
|
||||
{% set section = "skills" %}
|
||||
|
||||
{% block title %}{{ skill.name if skill else "New skill" }} - LLeMbas{% endblock %}
|
||||
{% block heading %}{{ skill.name if skill else "New skill" }}{% endblock %}
|
||||
|
||||
{% block library_content %}
|
||||
<div class="btn-row" style="margin-bottom: var(--sp-5)">
|
||||
<a class="btn btn--sm" href="/library/skills">{{ icon("chevron-right", "icon--sm") }} All skills</a>
|
||||
</div>
|
||||
|
||||
<form method="post"
|
||||
action="{{ '/api/library/skills/' ~ skill.id if skill else '/api/library/skills' }}">
|
||||
<section class="card">
|
||||
{% if not skill %}
|
||||
<div class="field">
|
||||
<label class="field__label" for="name">Name</label>
|
||||
<input class="input mono" id="name" name="name" required maxlength="60"
|
||||
placeholder="weekly-report" pattern="[a-zA-Z0-9 _-]+">
|
||||
<p class="field__hint">
|
||||
Lowercase letters, numbers and hyphens. This is how a model asks for it,
|
||||
and it cannot be changed later.
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="field">
|
||||
<label class="field__label" for="description">When to use it</label>
|
||||
<textarea class="textarea" id="description" name="description" rows="2" required
|
||||
{{ 'disabled' if skill and not is_owner }}
|
||||
placeholder="When the user asks for the weekly report.">{{ skill.description if skill else '' }}</textarea>
|
||||
<p class="field__hint">
|
||||
<strong>The load-bearing field.</strong> This one line is all a model
|
||||
sees until it opens the skill, so it has to say when the skill applies —
|
||||
not what it does.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="field__label" for="body">Instructions</label>
|
||||
<textarea class="textarea" id="body" name="body" rows="18"
|
||||
{{ 'disabled' if skill and not is_owner }}
|
||||
placeholder="Markdown. Steps, conventions, things to avoid.">{{ skill.body if skill else '' }}</textarea>
|
||||
</div>
|
||||
|
||||
{% if skill %}
|
||||
<div class="field">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" name="enabled" value="true" {{ 'checked' if skill.enabled }}
|
||||
{{ 'disabled' if not is_owner }}>
|
||||
<span>Offer this skill to models</span>
|
||||
</label>
|
||||
<p class="field__hint">
|
||||
Turned off, it stays here but disappears from the list the model sees.
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if skill and skill.author == "model" %}
|
||||
<div class="alert alert--warning">
|
||||
{{ icon("sparkle", "alert__icon") }}
|
||||
<div>
|
||||
<strong>A model wrote this version.</strong>
|
||||
<div class="text-sm" style="margin-top: var(--sp-1)">
|
||||
Worth reading before you rely on it. A model that has just read a web
|
||||
page can be talked into things by that page, and a skill persists.
|
||||
Every earlier version is below.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</section>
|
||||
|
||||
{% if skill %}{% include "library/_share.html" %}{% endif %}
|
||||
|
||||
{% if not skill or is_owner %}
|
||||
<div class="form-actions">
|
||||
<button class="btn btn--primary" type="submit">{{ "Save" if skill else "Create skill" }}</button>
|
||||
{% if skill %}
|
||||
<span class="spacer"></span>
|
||||
<button class="btn btn--danger" type="submit"
|
||||
formaction="/api/library/skills/{{ skill.id }}/delete"
|
||||
data-confirm-button="Delete the skill “{{ skill.name }}” and all its history?"
|
||||
data-confirm-title="Delete skill">
|
||||
{{ icon("trash", "icon--sm") }} Delete
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</form>
|
||||
|
||||
{% if skill and revisions %}
|
||||
<section class="card">
|
||||
<h2 class="card__title">History <span class="badge">{{ revisions|length }}</span></h2>
|
||||
<p class="card__lede">
|
||||
What this skill said before each change. This is the whole safety story for a
|
||||
model editing its own instructions: not a gate, but a record and a way back.
|
||||
</p>
|
||||
<ul class="model-list">
|
||||
{% for revision in revisions %}
|
||||
<li class="model-list__item">
|
||||
<div style="min-width: 0">
|
||||
<strong>{{ revision.created_at.strftime("%Y-%m-%d %H:%M") }}</strong>
|
||||
{% if revision.author == "model" %}
|
||||
<span class="badge badge--gold">model</span>
|
||||
{% else %}
|
||||
<span class="badge">you</span>
|
||||
{% endif %}
|
||||
{% if revision.note %}<div class="text-xs faint">{{ revision.note }}</div>{% endif %}
|
||||
<div class="text-xs faint">{{ revision.body[:200] }}{{ "…" if revision.body|length > 200 }}</div>
|
||||
</div>
|
||||
{% if is_owner %}
|
||||
<form method="post"
|
||||
action="/api/library/skills/{{ skill.id }}/revert/{{ revision.id }}"
|
||||
data-confirm="Put the skill back to this version? The current one is kept in the history."
|
||||
data-confirm-label="Revert" data-confirm-danger="false">
|
||||
<button class="btn btn--sm" type="submit">{{ icon("refresh", "icon--sm") }} Revert</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</section>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user