Skip to content

Latest commit

 

History

History
218 lines (181 loc) · 11.1 KB

slack.md

File metadata and controls

218 lines (181 loc) · 11.1 KB

Start a thread from Slack

The Slack pack starts a T3 thread from Slack in three ways:

  • your own message with your trigger emoji, which then is the task;
  • a mention of your Slack app, such as @T3Code - Nora Example, which also is the task;
  • your own reaction with your trigger emoji to any message, which asks the thread to find the cause of the problem in that message and propose the fix.

The trigger emoji is :t3code: by default. Only your own Slack member ID, the setting slack.userId, counts. A message or reaction from anyone else starts nothing.

Choose the trigger emoji

The setting slack.emoji names the trigger emoji. Its default is t3code, a custom emoji that your workspace must have. To use another emoji, such as :eye:, run:

hedge set slack.emoji=eye

Give the emoji's name, with or without the colons: eye and :eye: are the same. Names such as +1 and thumbsup work. A reaction with a skin tone, such as :thumbsup::skin-tone-2:, counts as thumbsup. A value with a space or a colon inside it is not an emoji name: the trigger does not start, and its log and hedge slack-trigger check say why.

hedge set applies the change, and the running trigger starts again with the new emoji. The hub takes the change at its next hedge update.

Choose the nodes

By default the trigger starts threads where it runs, on the hub. To start them on your nodes instead, the devboxes that stay on, name them by their SSH names:

hedge set slack.nodes="devbox-1 devbox-2"

The trigger takes them in turn. Each node needs the Slack pack, which every machine of your profile has, and the hub must reach it over SSH. Leave out a node that you are about to retire. A name that is not an SSH name, or that names a box, stops the trigger, and its log says which.

How it works

The trigger runs all the time as a Hedge service, hedge run slack/slack-trigger: the systemd user service hedge-slack-trigger. Hedge installs it only after you save your Slack app. It runs on the hub that your profile names with hedge hub here. Without a named hub, it runs only on a machine that is alone in its profile: the profile lists no devboxes, the Hub pack is off, and the machine is not a devbox. A profile that two nodes share without a named hub runs it nowhere. Name a hub with hedge hub here in that case.

The trigger holds a Socket Mode connection to your own Slack app, so Slack sends each event within a second, and no address is public.

  1. Slack sends every message and reaction in your channels. The trigger keeps only your own.

  2. It reads the whole Slack thread with your user token and starts a thread with the model of the implementation row of your model table. When your own message says /incident as a word, it uses the incident row instead: on the Codex and both plans, GPT-6.2 Sol at high effort on the ultrafast service tier, which answers several times as fast. To change it, add an incident row to overrides.models in your profile. When T3 does not offer the row's tier for the model, the thread starts on the standard tier. Through the hub's proxy, T3 offers ultrafast once the proxy serves Hedge's Codex catalog (hedge cli-proxy catalog). The thread starts:

    • with slack.nodes set, on those nodes in turn, over SSH with hedge slack-trigger launch, in a scratch folder on the node's T3 Code;
    • otherwise, with the Boxes workflow of the Hub pack on, on the next box from the pool (hedge box spawn);
    • otherwise, in a scratch folder on this machine's T3 Code.

    The prompt quotes the Slack thread as data. Only your message is the task, and the thread asks you before anything other people see.

  3. It reacts with :eyes: as you and posts an ephemeral reply, which only you see, with the thread's link on app.t3.codes.

  4. A failed launch retries every minute for a day, with the same command ID, so T3 starts one thread even when an answer got lost. On a box, the retries go to the same box, and Hedge releases that box when it gives up. On nodes, a launch retries on the next node only when SSH could not connect, or the node's disk was below the start floor. Any other failure, such as a dropped connection or a launch that ran past its 300 s limit, retries on the same node, because T3 there may have the thread already. You get one ephemeral reply about it.

~/.local/state/hedge/slack/slack-trigger.json keeps the handled messages for 31 days, so each message starts one thread, and the next node in turn, so a restart does not start over with the first node. The log is ~/.local/state/hedge/jobs/slack-trigger.log.

Page you for an urgent mention

The workflow mention-pager pages you through incident.io when a person @-mentions you in Slack about something urgent and you do not answer. It is off by default. It needs the workflows slack-thread and page-owner of the Paging (incident.io) pack. Turn it on and give your time zone:

hedge set slack.pagerTimeZone=Europe/Berlin
hedge packs --workflows mention-pager=on

It runs inside the Slack trigger, on the same Socket Mode connection, and it never writes to Slack. It runs claude, so Claude Code must be installed and signed in on the machine that runs the Slack trigger.

  1. A mention is a message from a person, not a bot, that contains your member ID, also when it is a thread reply sent to the channel, a file share, or a /me message. Messages from the member IDs in slack.pagerIgnoredUsers, and messages in the channels of slack.pagerIgnoredChannels (names or IDs, default github), do not count.
  2. At 5, 15, and 30 minutes after the mention, the pager first looks for a post by you since the mention: in its thread, in the channel, and in each thread of the channel with a reply since then. It also counts each post by you in the channel as soon as the trigger receives it. When you posted, it stops.
  3. Otherwise it gives Haiku (claude-haiku-5-5, high effort) the conversation around the mention three times, with the prompt in packs/slack/lib/pager-gate.md. When 2 of the 3 answers say page, it runs hedge page with the key mention:<channel>:<ts>. The title names the author and the channel. The description holds the message, Haiku's reason, the minutes without an answer, and the link to the message, which is also the source URL. For a direct message or a private channel, the title says "a private conversation" and the description holds only the minutes and the link, so the name and the text stay in Slack. It then stops judging that mention. A call that fails is tried once more.
  4. It pages each channel at most once in 3 hours. It pages only Monday to Friday, from slack.pagerFrom (default 5) to slack.pagerUntil (default 21) o'clock in slack.pagerTimeZone. Outside those hours, and inside the 3 hours, it only logs, and the next checkpoint judges again.
  5. After a page, also one whose send failed, it keeps watching for your answer for 3 days: in the feed, and in Slack history every 30 minutes after the last checkpoint. Right before it pages, it reads Slack once more. When you answer, it runs hedge page --resolve with the same key, and incident.io withdraws the page. When the withdrawal fails, it tries again each minute.

A checkpoint that passed more than 5 minutes ago, such as after a restart, is only logged. Each channel is checked on its own, so a slow check in one channel does not hold up another. The pager replaces secret-shaped text, such as tokens, before it sends text to Haiku or incident.io and before it writes its log.

Haiku sees more in two cases:

  • In a channel whose name starts with inc-, it also sees the first 8 messages of the channel, when it can read back to them.
  • With slack.pagerGithubLogin and slack.pagerGithubRepo set, such as PostHog/posthog, it learns which pull requests named in the conversation you wrote and merged in the last 180 days. The pager reads them with gh api search/issues and keeps them for 10 minutes. It reads each named pull request that the search does not show, such as one merged a minute ago, with gh api repos/<owner>/<repo>/pulls/<number>, at most 5 per check. It tells Haiku that none of them are yours only when it could read every one.

When fewer than 2 calls of a check answer in an alert channel, it pages "Pager could not judge a mention in #", with the same limits. That page names the author and links the message, without its text. An alert channel has a name that starts with inc-, or that has one of the words alert, alerts, security, incident, or incidents. In other channels it only logs the failure and judges again at the next checkpoint.

When a pager setting is wrong, such as an unknown time zone, the Slack trigger runs without the pager and logs mention pager off: with the reason.

Each mention, check, answer, and page is one JSON line in ~/.local/state/hedge/slack/mention-pager.jsonl. A check line holds all three answers. Each failed call is a failure line with its mention, its checkpoint, its error, and its standard error.

The pager names each channel with conversations.info, which needs the user scopes channels:read and groups:read. An app made from an older manifest lacks them: add them to the app under OAuth & Permissions, then reinstall it. Until then, the pager names each channel by its ID.

Set up the Slack app

Each person makes their own app. Its name, T3Code - <name>, comes from your Git name, which Hedge sets from your GitHub account.

hedge setup walks you through it when you turn on Start a thread from Slack. To do it later, or again, run hedge slack-trigger setup on the machine that runs the trigger:

  1. Open the link it shows. It makes the app from the manifest in your workspace.
  2. Under Basic Information, add an app-level token with the connections:write scope, and paste it. It starts with xapp-.
  3. Under Install App, install the app. A workspace admin may need to approve it.
  4. Copy the User OAuth Token, and paste it. It starts with xoxp-.

The terminal does not show what you paste. Hedge checks each token with Slack, and checks that the user token is yours. Then it saves both tokens in the Slack pack's secret store, ~/.config/hedge/secrets/slack/app, readable only by you, and applies your profile, which installs the trigger. A running trigger checks the saved app every minute. When it changes, the trigger finishes the launches it already started, stops, and the service starts it again with the new tokens. hedge setup --non-interactive skips this step and lists it as still needed.

hedge doctor lists the setup as a To do until a Slack app that the trigger can use is saved. When you remove the saved app, the trigger stops, writes the To do once to its log, and waits until a Slack app is saved again. The next hedge apply removes the trigger. hedge slack-trigger check checks with Slack that the saved user token is yours. hedge slack-trigger manifest prints the manifest itself.

To mention the app in a channel, invite it there first. Messages and reactions work in every channel you are in, without the app.