Husk
GitHub

Chat to bot

The distiller

How a transcript becomes a husk.yaml, what the heuristic path can and cannot see, and why the confidence number is capped at 0.75.

Interactive chat-to-bot diagram — open locally for pan/zoom and PNG/SVG export.

husk distill ./chat.md --no-model
husk distill tr_01hxyz --out support-bot.yaml
husk distill
FlagWhat it does
--model <m>Model to distil with. Default auto
--no-modelForce the free heuristic path even when a model is configured
--engine <e>What the bot runs on: claude-code, codex or builtin. Default: see below
--out <file>Where to write. Default husk.yaml
--name <n>Override the generated husk name
--forceOverwrite an existing file
--jsonPrint the distillation result

What the bot runs on

A bot keeps running on the AI the chat came from, under your own login, with that app's own limits. husk distill picks it the way the console's "Make a bot from a chat" does:

  1. The chat's own app, when it is installed. A Claude Code chat runs on your Claude Code, and goes on with that chat itself; a Codex chat runs on your Codex.
  2. Otherwise the other one, if it is installed. A chat from an app that cannot run on its own, such as Claude Desktop or ChatGPT, runs on your Claude Code or Codex.
  3. Husk's own engine only when neither is installed. It needs a model of its own: an API key, or a local model.

husk distill says which it chose, on its "runs on" line, and --engine picks another.

Two modes

transcript ──▶ importer ──▶ Transcript ──▶ distiller ──▶ DistilledAgent ──▶ husk.yaml

The heuristic mode has to be good, because it is the mode that runs with no API key. The model-backed mode does the same job better and falls back to the heuristic rather than failing.

Both produce a DistilledAgent:

interface DistilledAgent {
  name: string;
  description: string;
  persona: string;
  knowledge: Array<{ title: string; content: string; source?: string }>;
  examples: Array<{ user: string; assistant: string }>;
  suggestedTools: string[];
  suggestedModel?: string;
  needsComputer: boolean;
  confidence: number;   // 0..1
  notes: string[];      // what it could not determine
}

The heuristic path

Synchronous, free, offline. Four miners run over the transcript.

Which turns count as yours

First, whatever the source, Husk filters synthetic user messages out by pattern: injected <command-name>, <system-reminder> and <task-notification> blocks, a turn that is nothing but such a block, [SYSTEM NOTIFICATION, Caveat: The messages below…, [Request interrupted, [Image: original NxN, Base directory for this skill:, This session is being continued…, and Please continue the conversation….

Those are not things you typed. Mining a persona from them produces a bot that talks like a tool harness.

Then attribution picks among what is left. Claude Code marks a real human prompt with promptSource: when any remaining message carries it, only those count as your turns. Otherwise every remaining user message does. A mis-attributed harness block is screened out either way.

Rules become the persona

Each human turn is split into sentences, stripped of code fences and markdown chrome, and scored against a directive table:

WeightSignal
4Identity — "you are…"
3"from now on", "always", "never"
2"do not", "make sure"
1–2Style instructions
1"use", "prefer"

A sentence needs weight ≥ 2 to survive. Survivors are deduplicated on a normalised key, keeping the shortest phrasing, then ranked by weight × (1 + log₂(occurrences)) — a rule you repeated four times beats one you said once. Corrections are skipped.

The persona is the identity line, a blank, then How you work: with one bullet per remaining rule. When the transcript used a computer, Husk appends:

You have a Linux computer. Run commands to check things rather than guessing,
and show the command you ran when the result matters.

Knowledge is durable fact

A human turn qualifies as knowledge when it is at least 180 characters, is not a correction, is not a short question, and carries at least one fact signal: a code fence, a URL, an absolute path, a bullet list, or a key: value line. A turn over 3,000 characters is refused rather than clamped, and so is one that is mostly markup, reads as a status report, or still holds harness plumbing. Content is clamped to 1200 characters and the title is the first line, trimmed to 72 characters on a word boundary.

Examples are exchanges you did not correct

A human turn is paired with the first substantial assistant reply after it — unless the next human turn is a correction, which is the signal that the reply was wrong. Candidates are ranked by reply length, then re-sorted chronologically and sampled evenly across the conversation, so the examples are not all from the first five minutes.

Tools come from observed use

Every toolName in the transcript, plus meta.tools and meta.sidechainTools, mapped onto the computer, files, web and browser bundles. A chat that drove Husk's browser (browser_goto, browser_click and the rest) gets the browser bundle and the computer it runs in; one that only read pages gets web. Orchestration tools that do not port to a husk — Task, TodoWrite, ExitPlanMode, Thinking and their kin — are dropped, and their presence is reported as a note.

The confidence number

confidence = 0.75 × min(1,
    0.35 × min(rules, 6) / 6
  + 0.30 × min(examples, 4) / 4
  + 0.15 × min(knowledge, 3) / 3
  + 0.10 × (any tools ? 1 : 0)
  + 0.10 × min(assistantMessages, 20) / 20)

The heuristic path can never report more than 0.75. That ceiling is deliberate: pattern-matching sentences is a decent first pass, not a reading of the conversation, and the number should say so.

The notes

Whatever it could not determine, in plain sentences:

  • No role instruction found -- nothing matching "you are a...", "act as", or "think like a..." -- so the persona opens with the topic instead.
  • No recurring standing instructions found. The persona is topic-only.
  • No durable user-supplied facts found worth carrying as knowledge.
  • No uncorrected user/assistant exchange was clean enough to use as an example.
  • No tool use observed; the husk is configured with the default files toolkit. A husk always gets at least one tool, so toSpec writes tools: [files].
  • Orchestration tools (Task, TodoWrite, ...) were observed but are not portable to a husk.
  • Heuristic distillation: no model was used. Review the persona before shipping. — always on this path, and dropped once the model path starts, even if every call then fails.

They land in the spec under metadata.distillerNotes, so they survive into the file and a reviewer sees them.

The model-backed path

A map/reduce over the whole transcript: every message lands in a window, none is cut off the end.

  1. The heuristic runs first, as the baseline to fall back to.
  2. The transcript is split into windows of about 12,000 tokens with a 2-message overlap at each boundary.
  3. Each window is extracted in turn, one at a time, at temperature: 0 with a JSON response format, and validated against a schema.
  4. One reduce call merges the candidates, also schema-validated.

After two failed windows in a row, or a cancel, the rest are skipped, with the note Stopped extraction after repeated failures or cancellation; skipped 5 of 7 slices. Every run also notes what it tried, as in Model distillation attempted 2 of 7 slices with anthropic/claude-sonnet-5.

Model mode can report a confidence up to 1.0.

Three fallbacks, not one

Where it failsWhat happens
One windowA note: Slice 3/7: model JSON did not validate. for a reply that does not fit the schema, or Slice 3/7: extraction failed. for a call that fails or a reply that is not JSON. That window contributes nothing
Every windowThe heuristic result, plus Model distillation produced nothing usable; fell back to heuristics.
The reduce callA deterministic local merge: rules unioned and ranked by occurrence, capped at 12, confidence capped at min(0.7, heuristic + 0.1), plus Model reduce pass failed; candidates were merged deterministically.

distillWithModel never throws. Every path ends in a DistilledAgent.

The transcript wins on tools

The merge takes the union of observed tools first, then adds anything the model suggested that is not on the ignore list. The transcript is ground truth about which tools were used; the model only adds to it.

The output

toSpec turns a DistilledAgent into a validated HuskSpec. The name is slugged to at most 64 characters and falls back to husk-bot if nothing survives; displayName is the name with spaces for dashes and a capital first letter; the description is clamped to 280; tool names are mapped onto bundles, with files when none maps; computer.enabled follows needsComputer, and is on whenever the tools include browser; the confidence and the notes go into metadata; and provenance goes into origin.

husk distill writes the file for review, not for machines: a comment header, then the spec, leaving out version and every block still at its defaults, in a fixed order — identity, model, persona, tools, knowledge, examples, then computer, limits, guardrails, memory, triggers, origin and metadata.

# Distilled by husk from /home/me/chat.jsonl (claude-code).
# 941 messages · confidence 0.62 · heuristic
# No durable user-supplied facts found worth carrying as knowledge.
# Heuristic distillation: no model was used. Review the persona before shipping.
# Review the persona before you serve this. Distillation is a draft, not an oracle.
 
apiVersion: husk/v1
name: support-triage
displayName: Support triage
description: Classifies inbound support messages.
 
model: auto
 
persona: |-
  You triage inbound support messages.
  ...

The header names the transcript, its message count, the confidence and the path taken (model attempted: <id> on the model path), then every note. A value with a newline, or of 72 characters or more, is a |- literal block, so a persona is diffable line by line. No YAML anchors or aliases, and lines are never folded.

A bot the console makes is saved as a plain YAML dump instead, unless you edit its text there: every field, defaults included, no header, and long lines folded at 100 characters. stringifySpec in @husk-ai/sessions writes a header of its own (# Support Triage -- a husk.), but neither the CLI nor the console calls it.

husk validate support-bot.yaml

Read it before you ship it

The distiller writes a starting point. The confidence number and the notes exist so you know how much of one — and the file is designed to be edited, which is why the husk.yaml reference documents every field rather than treating the file as generated output.