Files
LLeMbas/src/lembas/web/templates/library/skill_detail.html
T
Jaroslav Beneš b8e7745311 An instance that can be somebody else's
A name, a tagline, a logo, a favicon and the launcher icons derived from it; the
Middle-earth strings as data; themes as token sets; and a stylesheet for what
none of that reaches. All four are on one page, in one settings group.

The snapshot is a Jinja global over a process-level cache, because render() has
no session and four render paths never reach it at all -- the sign-in page, the
error pages, the offline page and the SSE fragments. A context value would have
had to be threaded through every one and would still have missed those. It being
a global is also what lets mark() branch on an uploaded logo without any of its
six call sites learning about branding; the macro that renders the sidebar link
is called brandlink now, because a macro imported as `brand` shadows the global
for the whole template and took out every page at once.

Defaults in code and overrides in the database, as the prompt fragments do, with
one difference stated in the module: an empty fragment means off, an empty
flavour string means the shipped wording. And blanked rather than dropped --
settings_store.update merges, so an omitted key leaves what was stored last time
and "I typed the default back in" would store something different from "I changed
nothing".

A custom theme sets a handful of tokens and inherits the rest, and the
inheritance is a CSS fact: tokens.css matches [data-base="shire"] as well as
[data-theme="shire"], so a custom light theme lands on parchment rather than four
light colours on near-black. Values are validated on read rather than on save,
because a theme written straight into the settings table still has to produce a
stylesheet that parses -- a `}` in a value ends the rule and silently breaks
every rule after it. The soft variants are derived from the accent, or a changed
accent leaves focus rings in the old hue and reads as half-working.

/branding.css is a route, not an inline block: an external stylesheet has no HTML
context to escape from. The link carries a content hash, so a save is not left to
the browser's cache, and it is deliberately outside the service worker's precache
list, which is versioned by the release.

The instance name moved off /admin/general rather than being duplicated there.
An upgrade keeps it: the general row is read as a seed exactly while the branding
row has never mentioned the name, which is `key in row` and not `row[key] is
truthy` -- the two read alike would resurrect the old name underneath a cleared
one.

The theme list stops being a hard-coded pair in five places. Every failure mode
in that area is silent, so it is driven under a DOM stub as well as tested.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-06 15:42:25 +02:00

127 lines
4.9 KiB
HTML

{% extends "library/_layout.html" %}
{% from "_macros.html" import icon %}
{% set section = "skills" %}
{% block title %}{{ skill.name if skill else "New skill" }} - {{ brand.name }}{% 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--leaf">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 %}