Husk
GitHub

Chat to bot

Triggers

http, webhook and cron are mounted by the server, and discord, slack and telegram start a chat adapter.

A husk becomes a bot through triggers declared in its spec. husk serve reads them and mounts what it can, and so does the shared Husk your chat apps start, through a job host (below).

triggers:
  - type: http
  - type: cron
    schedule: '*/15 * * * *'
    prompt: Any red builds on main in the last 15 minutes?
  - type: webhook
    path: /gh
    secret: ${GITHUB_WEBHOOK_SECRET}
curl -s localhost:7377/v1/triggers | jq

What is actually mounted

The spec accepts seven trigger types. husk serve mounts six; cli needs nothing mounted.

TypeMountedWhere
httpyesALL /v1/t/<husk><path>
webhookyesPOST /v1/w/<husk><path>
cronyesThe in-process scheduler
clin/aIt is the default; it means "no server surface", which is correct
discordyesA Discord gateway connection, when DISCORD_BOT_TOKEN is set
slackyesSLACK_BOT_TOKEN, and either Socket Mode with SLACK_APP_TOKEN or the Events API at POST /v1/a/<husk>/slack/events with SLACK_SIGNING_SECRET. The Events API wins when both are set
telegramyesLong polling, when TELEGRAM_BOT_TOKEN is set

Where triggers run

husk serve mounts them in its own process. The shared Husk does not: when a husk has any trigger but cli, it starts a job host, husk-mcp --jobs, on a loopback port of its own (HUSK_JOBS_PORT, or any free one), recorded in ~/.husk/jobs.json and logging to ~/.husk/jobs.log. The shared Husk forwards /v1/t, /v1/w, /v1/a and GET /v1/triggers to it, so every trigger keeps the shared Husk's address. The job host runs nothing itself: each bot's run is asked of the shared Husk, starting it again if it has gone, so a take-over reaches that run as it reaches a chat. The job host leaves once no husk has a trigger, or when a husk serve starts, which mounts them itself.

Each process reads the bot tokens from its own environment and from ~/.husk/.env. The job host's environment is the shared Husk's.

discord, slack and telegram

triggers:
  - type: discord
    channels: ['1234567890123456789']   # required: with none, the trigger is not started
    mentionOnly: true                   # DMs always count as a mention
  - type: slack
    channels: []
  - type: telegram
    allowlist: [alice, '123456789']     # usernames or numeric ids

Each one starts a chat adapter from @husk-ai/adapters in the process that runs the triggers. A message the adapter accepts becomes a run of that husk, and the run's final text is the reply, or (the agent produced no text).

Three rules, each logged and shown in GET /v1/triggers when it stops a trigger:

  • Say who it answers. A discord or slack trigger needs channels, and a telegram one needs an allowlist. With neither it would answer anyone who can reach the bot, and the bot runs commands on a computer, so it is not started.
  • One husk per platform. A bot token is one bot, so a second husk with a discord trigger is not started while another has it.
  • One computer per husk. Everyone the bot answers shares that husk's computer and its files.

A second trigger of the same type in one husk is ignored, with a log line and nothing in GET /v1/triggers.

Who gets an answer:

  • Discord and Slack answer in the listed channels only. A DM is a channel too, so it needs its channel id listed; once there it counts as a mention. On Discord, a reply to the bot's message also counts as one.
  • Telegram takes a message whose sender's username or numeric id, or whose chat id, is on the allowlist. Usernames match without regard to case, with or without the @. In a group the bot answers only when the message has its @username; a private chat always counts.
  • Every adapter answers each person at most 5 times in 60 seconds. Past that it replies Rate limited. Try again in 42s., with the real wait.

The token is read from the environment when the adapter starts, so set it before the process that runs the triggers starts. With no token the adapter stays idle, and GET /v1/triggers says which variable it is waiting for:

{ "husk": "support-bot", "type": "discord", "at": "discord", "detail": "idle -- DISCORD_BOT_TOKEN is not set" }

An adapter whose trigger did not change keeps running when you edit the husk, so saving an unrelated change does not drop the Discord connection. Deleting the husk stops it. Code that calls serve() from @husk-ai/server can pass adapters: false to start none of them; husk serve has no switch for it.

The Slack Events API route is the one route under /v1/ that does not take the server token, because Slack cannot send it. On the default loopback bind, Husk answers only loopback names, its defence against DNS rebinding, token or not. So a tunnel has to pass a loopback Host: ngrok http 7377 --host-header=rewrite, or cloudflared with --http-host-header 127.0.0.1:7377. The other way is to bind another address with HUSK_TOKEN set. Socket Mode needs none of this. The adapter checks Slack's signature on the raw body before anything runs, and answers only on the path it mounted.

http

triggers:
  - type: http
    path: /triage      # default '/'
    auth: token        # default 'token'

Mounted at /v1/t/<husk-name><path> and it answers any method.

curl -X POST localhost:7377/v1/t/ci-triage \
  -H 'content-type: application/json' \
  -d '{"input":"why is main red?"}'

The prompt is extracted in this order:

  1. Query ?input=, ?text=, ?q=
  2. A raw string or Buffer body
  3. JSON keys input, text, message, prompt, content, query
  4. Otherwise, the whole JSON body stringified

No prompt anywhere is a 422 with no prompt found in the request.

Stream instead of buffering with Accept: text/event-stream or ?stream=true; you then get RunEvent frames.

{ "runId": "run_x", "text": "…", "stopReason": "complete", "usage": { } }

webhook

triggers:
  - type: webhook
    path: /gh
    secret: ${GITHUB_WEBHOOK_SECRET}

Mounted at POST /v1/w/<husk-name><path>. With a secret, the body is verified as HMAC-SHA256 over the raw bytes, and the signature is read from the first of X-Husk-Signature, X-Hub-Signature-256, X-Signature-256, with a leading sha256= stripped; a bare hex works too. A mismatch is a 403 E_EXEC_DENIED, and so is a signature named for another algorithm, such as sha1=, which says so.

A signed request needs no server token: the signature is its credential, so a sender that cannot add one, such as GitHub, reaches the webhook wherever husk serve is exposed (Self-hosting). Without a secret, the webhook takes the server's token like any other route, and a request that carries a signature anyway is refused with a 403, since there is nothing to check it against.

${GITHUB_WEBHOOK_SECRET} is read from the server's environment when the trigger is mounted. If it is unset or empty, the webhook is not mounted at all, and the server logs why: mounted unsigned, anyone could start the husk, and the placeholder's own text is printed right here.

Without a secret, GET /v1/triggers reports the mount as UNSIGNED -- set `secret` on the trigger. Anyone who can reach the port can spend your model budget.

Without a secret, the prompt is found as for http. With one, it comes from the signed body alone, and ?input=, ?text= and ?q= are ignored: the signature does not cover the address, so a prompt there could be swapped on a captured delivery. There is no replay window, so the same signed delivery sent again runs again.

cron

triggers:
  - type: cron
    schedule: '*/15 * * * *'
    prompt: Any red builds on main in the last 15 minutes? If none, reply exactly "clear".

Both schedule and prompt are required; the schema gives them no defaults, because a cron trigger with nothing to say is not a trigger.

Standard five-field cron, in the host's local time. Names such as mon and jan work, and so do @hourly, @daily, @midnight, @weekly, @monthly, @yearly and @annually. A sixth field is refused: seconds are not supported. When both day fields are restricted the job runs on either, as Vixie cron does, so 0 0 1 * mon is the 1st and every Monday.

The scheduler runs in the process that runs the triggers — there is no external cron and no persistence, so a missed window while it was down is not replayed. An invalid schedule is logged as husk <name>: <message> and that one job is skipped; the rest of the husk still mounts.

GET /v1/triggers reports each binding's next fire time, or never fires.

cli

The default when a spec declares no triggers. It means the husk is run with husk run and exposes no server surface, which is the right default for something you have just distilled and not yet reviewed.

Idempotency

The control plane honours Idempotency-Key on POST, PUT, PATCH and DELETE, including on the trigger paths. A replay returns the recorded status and body with Idempotency-Replayed: true.

The cache is in memory with a 15-minute TTL, so it does not survive a restart, and it does not cover streaming responses — an SSE reply is never recorded, so a retried streaming request runs the agent again.