From 05cdcf1759c08c7efd6e2d16e4ddb74bde598dae Mon Sep 17 00:00:00 2001 From: Kacper Madej Date: Sat, 18 Jul 2026 12:23:27 +0000 Subject: [PATCH] feat: add DEFAULT_AGENT option to set agent for Slack sessions Adds a new plugin option DEFAULT_AGENT (with SLACK_DEFAULT_AGENT env var fallback) that sets the initial value of agentOverride when the plugin initializes. This makes new Slack prompts use the configured agent instead of opencode's global default. Motivation: when opencode's default agent carries an identity you don't want exposed in Slack (e.g. a chat-facing persona like 'Claudia' that should not introduce itself as 'Sisyphus'), there's currently no way to pick a different agent for Slack without manually running !agent in every thread or prefixing every message with @. Behavior: - Honored at plugin init only (no per-prompt re-read) - Still overridden by !agent and @ per-message - Still cleared by !agent reset (which sets agentOverride = null) - Parallel to existing DEFAULT_DIRECTORY / SLACK_DEFAULT_DIRECTORY pattern Builds cleanly with `npm run build` (dist/plugin.js regenerated). --- README.md | 1 + dist/plugin.js | 2 ++ src/plugin.ts | 2 ++ 3 files changed, 5 insertions(+) diff --git a/README.md b/README.md index d935b5b..fdfdfc0 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Add plugin with tokens to `~/.config/opencode/opencode.json`: | `SLACK_BOT_TOKEN` | — | Required. Bot token (`xoxb-...`) | | `SLACK_APP_TOKEN` | — | Required. App-level token (`xapp-...`) | | `DEFAULT_DIRECTORY` | serve directory | Default workspace for new sessions | +| `DEFAULT_AGENT` | — | Agent name to use for prompts in Slack threads. Reads plugin option first, then `SLACK_DEFAULT_AGENT` env var. Can be overridden per-message with `@` or per-thread with `!agent`; cleared by `!agent reset`. Useful when the global opencode default agent has an identity you don't want exposed in Slack (e.g., a chat-facing persona) | | `ALLOWED_USERS` | — | Comma-separated Slack user IDs or emails. If unset, everyone can use the bot | | `ATTACH_TIMEOUT_SEC` | 600 | Timeout (seconds) for `!attach bg_xxx` polling. Reads plugin option first, then env var fallback. Invalid/non-positive values fall back to 600 | diff --git a/dist/plugin.js b/dist/plugin.js index ea55873..23e8937 100644 --- a/dist/plugin.js +++ b/dist/plugin.js @@ -13566,6 +13566,8 @@ var pluginModule = { } pluginClient = input.client; defaultDirectory = expandTilde(options?.DEFAULT_DIRECTORY || process.env.SLACK_DEFAULT_DIRECTORY || input.directory); + agentOverride = options?.DEFAULT_AGENT || process.env.SLACK_DEFAULT_AGENT || null; + if (agentOverride) log(`default agent: ${agentOverride}`); attachBgTimeoutMs = resolveAttachTimeoutMs(options?.ATTACH_TIMEOUT_SEC); log(`attach timeout set to ${attachBgTimeoutMs}ms`); sessionsPath = join(input.directory, "slack-sessions.json"); diff --git a/src/plugin.ts b/src/plugin.ts index bda0677..71933cf 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1302,6 +1302,8 @@ const pluginModule: PluginModule = { pluginClient = input.client; defaultDirectory = expandTilde((options?.DEFAULT_DIRECTORY as string) || process.env.SLACK_DEFAULT_DIRECTORY || input.directory); + agentOverride = (options?.DEFAULT_AGENT as string) || process.env.SLACK_DEFAULT_AGENT || null; + if (agentOverride) log(`default agent: ${agentOverride}`); attachBgTimeoutMs = resolveAttachTimeoutMs(options?.ATTACH_TIMEOUT_SEC); log(`attach timeout set to ${attachBgTimeoutMs}ms`); sessionsPath = join(input.directory, "slack-sessions.json");