Skip to content

feat: Session-Ergonomie — Namen, -c, context, Kosten, Budget, fork - #50

Merged
webmatze merged 1 commit into
mainfrom
feat/session-ergonomics
Aug 8, 2026
Merged

feat: Session-Ergonomie — Namen, -c, context, Kosten, Budget, fork#50
webmatze merged 1 commit into
mainfrom
feat/session-ergonomics

Conversation

@webmatze

@webmatze webmatze commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Closes #28. Auf deinen Wunsch alles in einem PR statt in vier.

A+B — Namen und -c

Eine Session bekommt ihren Namen aus dem ersten Prompt (kebab-case, fünf Wörter, ohne LLM-Call — dafür ist ein Provider-Roundtrip zu teuer), und über den Namen wird fortgesetzt.

smith "why does this test fail on Linux?"
smith -c "and now fix it"          # dieselbe Session, ein Turn mehr
smith rename <session> my-refactor # oder /rename my-refactor im Chat
smith resume my-refactor
  • Ein abgeleiteter Name, der kollidieren würde, bekommt einen Zähler (fix-the-tests-2) — sonst wäre Resume-by-Name mehrdeutig. Ein rename auf einen belegten Namen wird abgelehnt.
  • Mehrdeutigkeit ist trotzdem behandelt: Trefferliste statt stiller Auswahl.
  • Alte Session-Dateien ohne name/parent_id bleiben ladbar.

Eine Erweiterung über das Issue hinaus: Headless-Läufe werden jetzt ebenfalls als Session gespeichert. Ohne das würde smith -c "und jetzt die Tests" nach einem Headless-Lauf eine unbeteiligte ältere Chat-Session fortsetzen — genau das Beispiel aus dem Issue hätte also nicht funktioniert.

C — smith context

Context for session my-refactor (120.000 token budget)

  System prompt               97    0%
  Skills                     420    0%
  Project (SMITH.md)         310    0%
  Tool definitions         1.153    1%
  Messages                34.100   28%
  ───────────────────────────────────
  Total                   36.080   30%

  Compactions this session: 1 (truncated)

build_system_prompt liefert jetzt beschriftete Teile; Prompt und Aufschlüsselung werden aus denselben Teilen gebaut, gezählt mit demselben Schätzer, den die Compaction benutzt. Eine Anzeige, die von der Entscheidung abweicht, die sie beschreibt, wäre schlimmer als keine.

Die Compaction-Zeile erscheint nur bei einer laufenden Session — eine von der Platte gelesene hat diese Historie nicht, und sie zu raten wäre schlechter als sie wegzulassen.

D — Kosten

Neue src/smith/pricing.cr, getrennte Sätze für Input, Output, Cache-Write und Cache-Read.

  • Unbekanntes Modell → n/a, nie eine geratene Zahl. In der Tabelle stehen nur Modelle, deren Preise tatsächlich bekannt sind.
  • Ollama immer $0.00.
  • Alles überschreibbar per [pricing."provider/model"] — eine ins Release eingebackene Tabelle kann Preisänderungen nicht folgen.

E — --max-budget-usd

Beendet den Lauf mit Exit-Code 2, abgegrenzt von 1 für einen Fehler. Geprüft nach jedem Turn statt davor, damit die gerade bezahlte Antwort noch ankommt.

Ohne Preisbasis gibt es nichts durchzusetzen, und das steht auf stderr, statt eine automatisierte Ausführung in falscher Sicherheit zu lassen.

F — smith fork

Kopie unter neuer ID mit parent_id; Original unberührt, Checkpoints bleiben bei der Session, die sie erzeugt hat.

Nebenbei

ChatCommands.parse liefert jetzt eine Invocation mit Argument, damit /rename <name> eines transportieren kann. Ein Slash-Aufruf mit Argumenten gehört weiterhin dem Skill-Katalog — /deploy staging ändert sich nicht.

Verifikation

  • 552 Specs grün, Format sauber, Build ok — macOS und Linux (Docker); 34 neue Specs
  • Live gegen claude-sonnet-5: Headless-Lauf → smith list zeigt den abgeleiteten Namen → smith -c setzt dieselbe Session fort (4 statt 2 Messages) → renameresume über den Namen → forkcontext
  • Budget: Exit-Code 2 gemessen (ohne Pipe, damit nicht tail den Code liefert), Warnung ohne Preisbasis geprüft

🤖 Generated with Claude Code

Six small things from #28 that are unremarkable alone and together are
the difference between usable and pleasant.

Names. A session takes its name from its first prompt (kebab-case, five
words, no LLM call — naming a session is not worth a provider roundtrip),
and the name is what you resume by. A derived name that would collide
gets a counter, because a collision would make resume-by-name ambiguous;
renaming onto a name another session holds is refused. Ambiguity is still
handled — it reports the candidates rather than silently picking one.
Sessions saved before names existed keep loading.

Continue. `smith -c "and now the tests"` runs one more turn on the last
session; bare `-c` resumes it interactively. For that to mean anything,
headless runs are now saved too — otherwise -c after a headless run would
pick up an unrelated older chat.

Context. `smith context` (and /context) shows where the window goes.
build_system_prompt now returns labelled parts, and both the prompt and
the breakdown are built from them, so the report cannot drift from the
thing it describes; counting uses the same estimator compaction uses.
The compaction line is only shown for a live session — a session read
back from disk has no such history, and guessing would be worse.

Cost. A new pricing.cr converts tokens to dollars per provider/model,
with cache writes and reads at their own rates. Only models whose
published rates are known are in the table: an unknown one prices as
n/a, never as a guess, since a wrong figure is worse than none. Ollama is
always free. Every rate is overridable from config, because a table
baked into a release cannot track vendor changes.

Budget. --max-budget-usd stops the loop once the estimate reaches the
ceiling and exits 2, distinct from 1 for a failed turn, so automation can
tell "too expensive" from "broken". Checked after each turn rather than
before, so the answer just paid for is still delivered. Without a price
for the model there is nothing to enforce, and that is said on stderr
rather than leaving a run to believe it is capped.

Fork. `smith fork <session>` copies the transcript under a new id and
records where it came from, for taking one start two ways.

ChatCommands now carries an argument, so /rename has somewhere to put the
name; a slash invocation *with* arguments still belongs to the skill
catalog, so /deploy staging is unaffected.

Closes #28.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@webmatze
webmatze merged commit 3c55fe2 into main Aug 8, 2026
2 checks passed
@webmatze
webmatze deleted the feat/session-ergonomics branch August 8, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session-Ergonomie: Namen, -c, smith context, Kosten, Budget, fork

1 participant