Documentation
¶
Overview ¶
Package slagent provides a unified streaming interface for Slack agent sessions.
It supports two backends transparently:
- Native streaming (bot tokens, xoxb-*): uses chat.startStream/appendStream/stopStream
- Compat streaming (session/user tokens): uses chat.postMessage/chat.update
The backend is selected automatically based on the token type.
Index ¶
- Constants
- func InstanceEmoji(instanceID string) string
- func MarkdownToMrkdwn(text string) string
- func ParseMessage(text string) (instanceID, cleaned string, targeted bool)
- func PollReaction(ctx context.Context, p Prompter, msgTS string, reactions []string, ...) (string, error)
- func ShortcodesToUnicode(text string) string
- type BlockKind
- type CommandMessage
- type FeedbackMessage
- type Message
- type Prompter
- type QuitMessage
- type SandboxToggle
- type StopMessage
- type TextMessage
- type Thread
- func (t *Thread) AddReaction(msgTS, reaction string)
- func (t *Thread) Channel() string
- func (t *Thread) DeleteMessage(msgTS string) error
- func (t *Thread) Emoji() string
- func (t *Thread) FinalizeReaction(msgTS, selected string, all []string)
- func (t *Thread) FormatHistory(msgs []slackapi.Message) string
- func (t *Thread) GetReactions(msgTS string) ([]slackapi.ItemReaction, error)
- func (t *Thread) InstanceID() string
- func (t *Thread) LastTS() string
- func (t *Thread) NewTurn() Turn
- func (t *Thread) PollReaction(msgTS string, expected []string) (string, error)
- func (t *Thread) PollReplies() ([]Message, error)
- func (t *Thread) Post(text string) (string, error)
- func (t *Thread) PostBlocks(fallback string, blocks ...slackapi.Block) error
- func (t *Thread) PostEphemeral(userID, text string)
- func (t *Thread) PostMarkdown(text string) error
- func (t *Thread) PostPrompt(text string, reactions []string) (string, error)
- func (t *Thread) PostUser(user, text string) error
- func (t *Thread) RemoveAllReactions(msgTS string, reactions []string)
- func (t *Thread) Replies(ctx context.Context) ([]Message, error)
- func (t *Thread) Resume(threadTS string, afterTS ...string) []slackapi.Message
- func (t *Thread) SetModeSuffix(suffix string)
- func (t *Thread) Start(title string) (string, error)
- func (t *Thread) ThinkingEmoji() string
- func (t *Thread) ThreadTS() string
- func (t *Thread) Title() string
- func (t *Thread) Topic() string
- func (t *Thread) URL() string
- func (t *Thread) UpdateMessage(msgTS, text string) error
- type ThreadOption
- func WithBufferSize(n int) ThreadOption
- func WithInstanceID(id string) ThreadOption
- func WithMarkdownConverter(fn func(string) string) ThreadOption
- func WithObserve() ThreadOption
- func WithOpenAccess() ThreadOption
- func WithOwner(userID string) ThreadOption
- func WithPollInterval(d time.Duration) ThreadOption
- func WithSlackLog(w io.Writer) ThreadOption
- func WithThinkingEmoji(shortcode string) ThreadOption
- type Turn
Constants ¶
const ( ToolRunning = "running" ToolDone = "done" ToolError = "error" )
Tool status constants for use with Turn.Tool().
Variables ¶
This section is empty.
Functions ¶
func InstanceEmoji ¶
InstanceEmoji returns the emoji for a given instance ID (short code). Falls back to 🤖 for unknown IDs.
func MarkdownToMrkdwn ¶
MarkdownToMrkdwn converts Markdown to Slack mrkdwn format.
func ParseMessage ¶
ParseMessage extracts the target instance and cleaned text from a Slack message. Strips leading @mentions, then checks for :shortcode: prefix.
func PollReaction ¶
func PollReaction(ctx context.Context, p Prompter, msgTS string, reactions []string, timeout time.Duration) (string, error)
PollReaction posts a prompt and polls for a reaction until one is selected, the context is cancelled, or the timeout expires. Returns the selected reaction name or "" on timeout/cancel.
func ShortcodesToUnicode ¶
ShortcodesToUnicode converts Slack shortcodes to Unicode emoji. Handles :lock:, :thread:, and all identity emoji shortcodes.
Types ¶
type CommandMessage ¶
type CommandMessage struct {
User, UserID, Command string
}
CommandMessage is a /command to forward to Claude.
type FeedbackMessage ¶
type FeedbackMessage struct {
Text string // emoji-prefixed feedback (e.g. "🔓 Thread opened for everyone.")
}
FeedbackMessage is local feedback from a handled command (e.g. /open, /lock). Not forwarded to Claude — only shown in terminal.
type Message ¶
type Message interface {
// contains filtered or unexported methods
}
Message is a typed event from a thread participant.
type Prompter ¶
type Prompter interface {
PostPrompt(text string, reactions []string) (string, error)
PollReaction(ts string, expected []string) (string, error)
DeleteMessage(ts string) error
UpdateMessage(ts, text string) error
RemoveAllReactions(ts string, reactions []string)
AddReaction(ts, name string)
GetReactions(ts string) ([]slackapi.ItemReaction, error)
}
Prompter is the interface for interactive prompt flows (permission, plan mode, sandbox). Thread implements this implicitly.
type QuitMessage ¶
type QuitMessage struct {
User, UserID string
}
QuitMessage requests terminating the session (owner only).
type SandboxToggle ¶
SandboxToggle requests a sandbox enable/disable (owner only).
type StopMessage ¶
type StopMessage struct {
User, UserID string
}
StopMessage requests interrupting the current turn.
type TextMessage ¶
type TextMessage struct {
User, UserID, Text string
Observe bool // observe-only: user not authorized to get responses
}
TextMessage is a regular text message from a user.
type Thread ¶
type Thread struct {
// Access control (embedded — exports IsAuthorized, IsVisible, SetOpen, etc.)
*access.Controller
// contains filtered or unexported fields
}
Thread manages an agent session in a Slack thread.
func NewThread ¶
func NewThread(c *client.Client, channel string, opts ...ThreadOption) *Thread
NewThread creates a new thread manager.
func (*Thread) AddReaction ¶
AddReaction adds a single reaction to a message.
func (*Thread) DeleteMessage ¶
DeleteMessage deletes a message from the thread.
func (*Thread) FinalizeReaction ¶
FinalizeReaction cleans up reactions after the owner has made a selection. It removes all non-selected reactions and re-adds the selected one (which was toggled off when the owner clicked it).
func (*Thread) FormatHistory ¶
FormatHistory formats thread messages into a text block for Claude to absorb. Messages from slagent instances are identified by block_id and shown with their emoji prefix. Human messages show the resolved user name.
func (*Thread) GetReactions ¶
func (t *Thread) GetReactions(msgTS string) ([]slackapi.ItemReaction, error)
GetReactions returns the reactions on a message.
func (*Thread) InstanceID ¶
InstanceID returns the instance identifier used in block_id tagging.
func (*Thread) PollReaction ¶
PollReaction checks which pre-added reaction the owner has clicked (removed). All expected reactions are pre-added by us (the owner via session token). When the owner clicks one, Slack toggles it off. We detect selection by checking which expected reaction no longer has the owner in its user list. Other users adding reactions is a noop — only the owner's removal counts. Returns the selected reaction name, or "" if no selection yet.
func (*Thread) PollReplies ¶
PollReplies fetches new messages without blocking (single poll).
func (*Thread) PostBlocks ¶
PostBlocks sends a message with blocks in the thread.
func (*Thread) PostEphemeral ¶
Post sends a plain message in the thread. PostEphemeral sends a message visible only to the specified user in the thread.
func (*Thread) PostMarkdown ¶
PostMarkdown posts markdown content as code blocks in the thread.
func (*Thread) PostPrompt ¶
PostPrompt posts a message and adds reaction emojis for interactive responses. Returns the message timestamp for use with PollReaction. Reaction names use Slack short codes without colons (e.g. "white_check_mark", "one").
func (*Thread) PostUser ¶
PostUser posts a user message with context block ("👤 @user") and text section.
func (*Thread) RemoveAllReactions ¶
RemoveAllReactions removes all given reactions from a message.
func (*Thread) Replies ¶
Replies returns new messages since the last call, filtering by permissions. It blocks until ctx is cancelled or messages arrive, polling at the configured interval.
func (*Thread) Resume ¶
Resume attaches to an existing thread and recovers access state from the title. If afterTS is provided, it is used as the cursor position (skipping all messages up to that point). Otherwise, all replies are fetched and returned for history injection (fresh join). Returns the fetched messages (excluding the parent).
func (*Thread) SetModeSuffix ¶
SetModeSuffix sets a suffix appended to the thread title (e.g. " — 📋 planning") and updates the thread parent message. Pass "" to clear.
func (*Thread) Start ¶
Start posts the initial thread message and returns the thread URL. Must be called before any concurrent access to the thread.
func (*Thread) ThinkingEmoji ¶
ThinkingEmoji returns the Slack shortcode for thinking/running indicator.
func (*Thread) Topic ¶
Topic returns the parsed topic text (without emojis, mentions, access markers).
func (*Thread) UpdateMessage ¶
UpdateMessage updates an existing message in the thread.
type ThreadOption ¶
type ThreadOption func(*threadConfig)
ThreadOption configures a Thread.
func WithBufferSize ¶
func WithBufferSize(n int) ThreadOption
WithBufferSize sets the text buffer size before flushing (native backend).
func WithInstanceID ¶
func WithInstanceID(id string) ThreadOption
WithInstanceID sets a specific instance ID for message tagging. If not set, a random one is generated. On resume, pass the original instance ID so the poller correctly identifies messages from this session.
func WithMarkdownConverter ¶
func WithMarkdownConverter(fn func(string) string) ThreadOption
WithMarkdownConverter sets a custom markdown-to-mrkdwn converter.
func WithObserve ¶
func WithObserve() ThreadOption
WithObserve enables observe mode: all messages are delivered for passive learning, but the agent only responds to authorized users.
func WithOpenAccess ¶
func WithOpenAccess() ThreadOption
WithOpenAccess allows all thread participants to send input.
func WithOwner ¶
func WithOwner(userID string) ThreadOption
WithOwner restricts the thread to only accept input from the given user ID.
func WithPollInterval ¶
func WithPollInterval(d time.Duration) ThreadOption
WithPollInterval sets the polling interval for new replies.
func WithSlackLog ¶
func WithSlackLog(w io.Writer) ThreadOption
WithSlackLog enables logging of all Slack API calls to w.
func WithThinkingEmoji ¶
func WithThinkingEmoji(shortcode string) ThreadOption
WithThinkingEmoji sets the Slack shortcode used as thinking/running indicator. Default is ":claude:". Example: ":claude-thinking:" for workspaces with custom emoji.
type Turn ¶
type Turn interface {
// Thinking appends thinking/reasoning content.
Thinking(text string)
// Tool reports tool activity. Status: "running", "done", "error".
Tool(id, name, status, detail string)
// Text appends response text (markdown).
Text(text string)
// Status shows a transient status line.
Status(text string)
// MarkQuestion marks this turn as a question. The prefix is prepended
// and trailing "?" is replaced with " ❓" on finish.
MarkQuestion(prefix string)
// DeleteActivity deletes the activity message (thinking + tools).
DeleteActivity()
// SetPlainText toggles plain text mode. When on, text is posted as a code
// block instead of being converted to Slack mrkdwn (e.g. for plan output).
SetPlainText(on bool)
// Finish finalizes the turn. Must be called exactly once.
Finish() error
}
Turn streams one agent response turn to a Slack thread.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package access provides a pure access-control state machine for thread ownership.
|
Package access provides a pure access-control state machine for thread ownership. |
|
Package channel provides Slack channel and user resolution.
|
Package channel provides Slack channel and user resolution. |
|
Package client provides an authenticated Slack client wrapper.
|
Package client provides an authenticated Slack client wrapper. |
|
cmd
|
|
|
claude-command-classifier-hook
command
Command claude-command-classifier-hook is a Claude Code PreToolUse hook that classifies tool calls by risk level using AI.
|
Command claude-command-classifier-hook is a Claude Code PreToolUse hook that classifies tool calls by risk level using AI. |
|
slagent-demo
command
|
|
|
slaude
command
|
|
|
slaude/internal/claude
Package claude manages Claude Code as a stream-json subprocess.
|
Package claude manages Claude Code as a stream-json subprocess. |
|
slaude/internal/perms
Package perms implements an MCP stdio server for Claude Code's --permission-prompt-tool.
|
Package perms implements an MCP stdio server for Claude Code's --permission-prompt-tool. |
|
slaude/internal/session
Package session orchestrates the slaude planning session.
|
Package session orchestrates the slaude planning session. |
|
slaude/internal/terminal
Package terminal handles simple terminal output for slaude.
|
Package terminal handles simple terminal output for slaude. |
|
slaude/shared/classify
Package classify provides AI-based tool call risk classification.
|
Package classify provides AI-based tool call risk classification. |
|
Package credential manages Slack credentials for slagent.
|
Package credential manages Slack credentials for slagent. |