@capybara-hq/plugin-slack 0.1.0-rc.3 → 0.1.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "name": "slack",
4
- "version": "0.1.0-rc.3",
4
+ "version": "0.1.0-rc.4",
5
5
  "publisher": "Capybara",
6
6
  "description": "Slack (channel@1 bot over Socket Mode with Block Kit cards, identity-source@1 Sign in with Slack, directory@1)",
7
7
  "displayName": {
@@ -10,11 +10,76 @@
10
10
  },
11
11
  "icon": "./icon.svg",
12
12
  "homepage": "https://github.com/capybara-hq/plugins/tree/main/plugins/slack#readme",
13
+ "dependencies": [
14
+ {
15
+ "name": "connector-mcp",
16
+ "version": "^0.1.0-rc.1"
17
+ }
18
+ ],
19
+ "setupGuides": [
20
+ {
21
+ "id": "slack-app",
22
+ "place": "channel-connection",
23
+ "title": {
24
+ "en": "Create the Slack app",
25
+ "zh": "创建 Slack 应用"
26
+ },
27
+ "steps": [
28
+ {
29
+ "en": "Open https://api.slack.com/apps, choose Create New App → From a manifest, pick your workspace and paste the app manifest below. It registers the bot scopes, the events and the slash commands `/new`, `/env` and `/capybara` the plugin needs.",
30
+ "zh": "打开 https://api.slack.com/apps,选择 Create New App → From a manifest,选中工作区,粘贴下面的应用 manifest。它会登记插件需要的机器人权限、事件以及斜杠命令 `/new`、`/env`、`/capybara`。"
31
+ },
32
+ {
33
+ "en": "Under Basic Information → App-Level Tokens choose Generate Token and Scopes, add the scope `connections:write` and copy the `xapp-…` token into the App-level token field. Socket Mode needs no public URL.",
34
+ "zh": "在 Basic Information → App-Level Tokens 选择 Generate Token and Scopes,添加权限 `connections:write`,把 `xapp-…` 令牌填进「应用令牌」。Socket Mode 不需要公网地址。",
35
+ "mode": "long_connection"
36
+ },
37
+ {
38
+ "en": "Slack checks the Request URL {{webhookUrl}} when you create the app or save Event Subscriptions: the connection must exist first, and Capybara answers the check. If Slack reports it unverified, save the channel connection, then retry under Event Subscriptions.",
39
+ "zh": "创建应用或保存 Event Subscriptions 时,Slack 会校验 Request URL {{webhookUrl}}:渠道连接要先存在,由 Capybara 应答校验。若 Slack 提示未通过,先保存渠道连接,再到 Event Subscriptions 重试。",
40
+ "mode": "webhook"
41
+ },
42
+ {
43
+ "en": "Choose Install App → Install to Workspace and copy the Bot User OAuth Token (`xoxb-…`) into the Bot token field.",
44
+ "zh": "选择 Install App → Install to Workspace,把 Bot User OAuth Token(`xoxb-…`)填进「机器人令牌」。"
45
+ },
46
+ {
47
+ "en": "Copy Basic Information → App Credentials → Signing Secret into the Signing secret field: every webhook request is verified with it, and without it every request is refused.",
48
+ "zh": "把 Basic Information → App Credentials → Signing Secret 填进「签名密钥」:每个 webhook 请求都用它校验,不填则全部拒绝。",
49
+ "mode": "webhook"
50
+ },
51
+ {
52
+ "en": "The manifest's redirect URL {{signInCallbackUrl}} is for Sign in with Slack; it needs `http.publicUrl` set on the deployment. Without it, remove the redirect URL or ask your super admin to set it.",
53
+ "zh": "manifest 里的重定向地址 {{signInCallbackUrl}} 用于 Slack 登录,需要部署设置 `http.publicUrl`。未设置时,删掉该重定向地址,或请超级管理员设置。"
54
+ }
55
+ ],
56
+ "files": [
57
+ {
58
+ "path": "./guides/app-manifest.socket.yaml.tmpl",
59
+ "title": {
60
+ "en": "App manifest (Socket Mode)",
61
+ "zh": "应用 manifest(Socket Mode)"
62
+ },
63
+ "language": "yaml",
64
+ "mode": "long_connection"
65
+ },
66
+ {
67
+ "path": "./guides/app-manifest.webhook.yaml.tmpl",
68
+ "title": {
69
+ "en": "App manifest (webhook)",
70
+ "zh": "应用 manifest(Webhook)"
71
+ },
72
+ "language": "yaml",
73
+ "mode": "webhook"
74
+ }
75
+ ]
76
+ }
77
+ ],
13
78
  "extension": {
14
79
  "entry": "./dist/index.mjs",
15
80
  "manifest": {
16
81
  "name": "slack",
17
- "version": "0.1.0-rc.3",
82
+ "version": "0.1.0-rc.4",
18
83
  "sdk": "^0.1.0-rc.0",
19
84
  "provides": [
20
85
  "channel@1",
package/README.md CHANGED
@@ -1,12 +1,15 @@
1
1
  # @capybara-hq/plugin-slack
2
2
 
3
- The official Slack plugin. It provides three capabilities:
3
+ The official Slack plugin. It provides three capabilities and a connector template:
4
4
 
5
5
  - `channel@1` (bot): receives events over [Socket Mode](https://docs.slack.dev/apis/events-api/using-socket-mode)
6
6
  (no public callback URL needed), sends messages through the Web API, and renders approval / question /
7
7
  connection / binding cards as Block Kit.
8
8
  - `identity-source@1` (Sign in with Slack, OpenID Connect): sign in to Capybara with a Slack account.
9
9
  - `directory@1` (directory sync): syncs Slack workspace members into org members.
10
+ - The connector template `slack` ([Slack connector](#slack-connector-slacks-mcp-server)): agents search,
11
+ read and send in Slack **as the person talking to them**, through Slack's MCP server and each member's own
12
+ OAuth authorization. Switched off by default.
10
13
 
11
14
  All three use the same identity key: `identities.source` = `slack:<team id>`, `external_id` = the Slack user id (`U…`).
12
15
  When the same person appears through sign-in, a DM to the bot and directory sync, it maps to one identity row and one account.
@@ -15,9 +18,20 @@ The Slack docs cited here were consulted on 2026-10-20.
15
18
 
16
19
  ## Create the Slack app
17
20
 
18
- 1. Open <https://api.slack.com/apps> → **Create New App** → **From a manifest**, pick the workspace, and paste this directory's
19
- [`app-manifest.yaml`](./app-manifest.yaml) (format: [App manifest reference](https://docs.slack.dev/reference/app-manifest)).
20
- It turns on Socket Mode and Interactivity, subscribes to the events `message.im`, `app_mention`, `message.channels`,
21
+ The plugin ships a **setup guide** (`plugin.json` `setupGuides`, id `slack-app`): when an org admin
22
+ creates a Slack channel connection (Channels → New channel) or opens one, the web app shows the steps
23
+ below and the app manifest rendered for that connection, with a copy button and a switch between
24
+ Socket Mode and webhook mode. The manifest is filled in with the connection's name, the Sign in with
25
+ Slack callback (`<http.publicUrl>/api/v1/auth/sso/slack/callback`) and, in webhook mode, the
26
+ connection's webhook URL. When a plugin upgrade changes the manifest, the channel page says so and
27
+ asks you to update the Slack app. The templates are in [`guides/`](./guides):
28
+ [`app-manifest.socket.yaml.tmpl`](./guides/app-manifest.socket.yaml.tmpl) (Socket Mode) and
29
+ [`app-manifest.webhook.yaml.tmpl`](./guides/app-manifest.webhook.yaml.tmpl) (webhook mode); outside
30
+ Capybara, replace each `{{…}}` placeholder by hand.
31
+
32
+ 1. Open <https://api.slack.com/apps> → **Create New App** → **From a manifest**, pick the workspace, and paste the
33
+ manifest from the setup guide (format: [App manifest reference](https://docs.slack.dev/reference/app-manifest)).
34
+ It turns on Socket Mode (or, in webhook mode, sets the Request URLs) and Interactivity, subscribes to the events `message.im`, `app_mention`, `message.channels`,
21
35
  `message.groups`, `team_join` and `user_change`, registers the slash commands `/new`, `/env` and
22
36
  `/capybara` (see [Commands](#commands)), and requests these bot scopes:
23
37
 
@@ -29,7 +43,7 @@ The Slack docs cited here were consulted on 2026-10-20.
29
43
  | `im:history` | Receive DM messages |
30
44
  | `app_mentions:read` | Receive messages that @-mention the bot in channels |
31
45
  | `channels:history` / `groups:history` | Receive thread replies in public / private channels |
32
- | `users:read` | Look up the speaker's display name and avatar; people-change events; directory `users.list` |
46
+ | `users:read` | Look up the speaker's display name, avatar, time zone and language (`users.info`); people-change events; directory `users.list` |
33
47
  | `users:read.email` | Read emails during directory sync (the bot itself does not use it) |
34
48
 
35
49
  2. **Basic Information → App-Level Tokens → Generate Token and Scopes**: add the scope `connections:write`
@@ -39,6 +53,8 @@ The Slack docs cited here were consulted on 2026-10-20.
39
53
  [directory sync](#directory-directory1): leave them empty if you only chat with the bot), then **create a new channel
40
54
  connection** under Channels: pick Slack as the plugin, fill in the app-level token (`appToken`, `xapp-…`) and
41
55
  the bot token (`botToken`, `xoxb-…`), and bind an agent. Both are stored in the secret store, and the API only returns "set".
56
+ The app's name in the manifest is the connection's name; Slack caps it at 35 characters, so shorten it in
57
+ the app settings if Slack refuses it (the bot user's name stays `capybara`).
42
58
  5. In Slack, DM the bot, or add the bot to a channel and @-mention it. The first conversation gets a binding card; click the button to confirm the binding on the web page.
43
59
 
44
60
  Note: apps that use Socket Mode cannot currently be listed in the public Slack Marketplace, and one app can hold at most 10 concurrent
@@ -59,12 +75,14 @@ connection → Overview → Inbound mode); the connection page then shows its we
59
75
  1. Copy **Basic Information → App Credentials → Signing Secret** into the connection's
60
76
  `signingSecret`. Every request is verified with it (HMAC-SHA256 over `v0:<timestamp>:<body>`)
61
77
  and must be at most 5 minutes old; without it every webhook request is refused.
62
- 2. In the app settings, turn **Socket Mode** off, then use the webhook URL as the **Event
63
- Subscriptions → Request URL** (Slack verifies it with a `url_verification` challenge, which the
64
- plugin answers) and as the **Interactivity & Shortcuts → Request URL** (card buttons).
65
- 3. Under **Slash Commands**, edit `/new`, `/env` and `/capybara` and set each one's **Request URL**
66
- to the same webhook URL (the manifest leaves it out, since Socket Mode needs none). The plugin tells
67
- a slash command from an event by its form body and answers it like Socket Mode does.
78
+ 2. The webhook manifest of the setup guide turns **Socket Mode** off and uses the connection's webhook
79
+ URL as the **Event Subscriptions → Request URL** (Slack verifies it with a `url_verification`
80
+ challenge, which the plugin answers), the **Interactivity & Shortcuts → Request URL** (card
81
+ buttons) and each slash command's **Request URL**. For an existing app, paste it under **App
82
+ Manifest**, or set the four URLs by hand. The plugin tells a slash command from an event by its
83
+ form body and answers it like Socket Mode does.
84
+ 3. The webhook URL exists only once the connection is saved, so the guide shows it after saving;
85
+ create the connection first, then let Slack verify the URL.
68
86
  4. `appToken` is optional in webhook mode: only Socket Mode uses it.
69
87
 
70
88
  Both modes parse events the same way (same message and card-click ids), so the kernel's dedupe
@@ -74,7 +92,7 @@ still drops a redelivery that arrives across a mode switch.
74
92
 
75
93
  [Sign in with Slack](https://docs.slack.dev/authentication/sign-in-with-slack/) is based on OpenID Connect.
76
94
 
77
- 1. In the app settings, add
95
+ 1. The setup guide's manifest already lists the callback; otherwise, in the app settings, add
78
96
  `<http.publicUrl>/api/v1/auth/sso/slack/callback` under **OAuth & Permissions → Redirect URLs** (for example `https://capybara.example.com/api/v1/auth/sso/slack/callback`;
79
97
  the `redirect_uri` the kernel sends must equal it or be a sub-path of it).
80
98
  2. The login flow requests the scopes `openid`, `email` and `profile` in the authorization URL (`openid` is required; `email` gives the email and
@@ -122,6 +140,79 @@ channel connection uses, but the config is stored separately and goes through th
122
140
  - When `teamId` / `botToken` are not filled in (the org only uses the bot), the plugin's `configured()` returns false: the kernel does not scan or sync, and records no audit
123
141
  or warning; a manual sync returns 409 `directory.not_configured`. It is not treated as an empty directory.
124
142
 
143
+ ## Slack connector (Slack's MCP server)
144
+
145
+ The template [`connectors/slack.json`](./connectors/slack.json) connects Slack's official MCP server
146
+ (`https://mcp.slack.com/mcp`, [Slack MCP server](https://docs.slack.dev/ai/slack-mcp-server/)) through the
147
+ `connector-mcp` plugin (a dependency in `plugin.json`, preinstalled with Capybara). Each member authorizes
148
+ their own Slack account, so an agent sees and does exactly what that person may in Slack, and every call runs
149
+ on the caller's own user token; there is no shared org token. Design and decisions:
150
+ [docs/superpowers/specs/2026-11-08-slack-connector-design.md](https://github.com/capybara-hq/plugins/blob/main/docs/superpowers/specs/2026-11-08-slack-connector-design.md).
151
+
152
+ - **Off by default** (`defaultEnabled: false`): an org that turns on the `slack` plugin for the bot does not
153
+ see the connector until an org admin switches the template on and enters the OAuth client.
154
+ - **Auth**: OAuth authorization code, personal credentials, MCP discovery (Slack's metadata points at
155
+ `https://slack.com/oauth/v2_user/authorize` and `oauth.v2.user.access`), a manually entered client (Slack
156
+ offers no dynamic client registration), `client_secret_post`, and 30 explicit user scopes (the full set
157
+ Slack's server supports; a scope Slack adds later needs a template update).
158
+ - **Tools**: reads are allowed; every write (send, schedule, draft, create, update, react, upload) and
159
+ `slack_search_public_and_private` (reaches DMs and private channels) ask the person first. Org admins and
160
+ agents change the policies on the tools page; tools Slack adds later default by their annotations (`ask`
161
+ without `readOnlyHint`).
162
+
163
+ ### Create the OAuth app (Slack admin)
164
+
165
+ The recommended setup is a separate internal app, "Capybara connector" (user scopes only, MCP on, no bot):
166
+
167
+ 1. Open <https://api.slack.com/apps> → **Create New App** → **From a manifest** in the company workspace and
168
+ paste [`app-manifest.connector.yaml`](./app-manifest.connector.yaml), with its redirect URL replaced by
169
+ `<http.publicUrl>/api/v1/oauth/callback` (for example
170
+ `https://capybara.example.com/api/v1/oauth/callback`). The deployment must set `http.publicUrl`. The
171
+ manifest turns on MCP (`is_mcp_enabled`) and requests the user scopes the template asks for:
172
+ `search:read.public`, `search:read.private`, `search:read.mpim`, `search:read.im`, `search:read.files`,
173
+ `search:read.users`, `channels:history`, `groups:history`, `mpim:history`, `im:history`,
174
+ `channels:read`, `groups:read`, `mpim:read`, `im:read`, `channels:write`, `groups:write`, `mpim:write`,
175
+ `im:write`, `chat:write`, `canvases:read`, `canvases:write`, `lists:read`, `lists:write`, `files:read`,
176
+ `files:write`, `reactions:read`, `reactions:write`, `emoji:read`, `users:read`, `users:read.email`.
177
+ 2. Leave **Manage Distribution** off: Slack's MCP server serves only internal apps and Marketplace apps,
178
+ and an internal app cannot be authorized from other workspaces.
179
+ 3. Do **not** enable PKCE in the app settings: it turns the app into a public client for good. Capybara
180
+ stays a confidential client (it still sends a PKCE challenge, which Slack's metadata advertises).
181
+ 4. Keep token rotation off (the manifest does). Without rotation, user tokens do not expire.
182
+ 5. Approve or install the app as your workspace requires (with "Only allow pre-approved apps", a workspace
183
+ admin approves it; on Enterprise Grid, an org admin).
184
+ 6. Copy **Basic Information → App Credentials → Client ID** and **Client Secret**.
185
+
186
+ Reusing the channel app instead is possible as long as token rotation stays off (rotation is app-wide and
187
+ would expire the bot's static `xoxb` token): add the user scopes, turn on MCP and add the redirect URL. Slack
188
+ prefix-matches redirect URLs, so one entry `<http.publicUrl>/api/v1/` covers both this callback and the Sign
189
+ in with Slack callback that the [setup guide](#create-the-slack-app) puts in the bot app's manifest.
190
+
191
+ ### Turn it on (org admin) and connect (members)
192
+
193
+ 1. Org settings → plugins → Slack: switch on the Slack connector template and enter the client
194
+ (`clientId`, `clientSecret`) from step 6. The secret is stored encrypted and reads back only as "set";
195
+ rotate it later through the connector's org credentials. Each org enters its own client (the same app may
196
+ serve several orgs).
197
+ 2. Members open **My connections** (`/account/connections`), click **Connect** on Slack and approve on
198
+ Slack's consent screen. Until they do, a Slack tool call shows the standard "connection required" card.
199
+ 3. **Disconnect** deletes the stored token in Capybara but does not revoke it at Slack: remove the
200
+ authorization in Slack too (the app's page → **Remove app**, or a workspace admin under **Manage apps**).
201
+
202
+ ### Decided risks
203
+
204
+ - **Slack data in conversations**: tool results stay in the conversation event log and archives like any
205
+ other connector's, although Slack's Real-time Search terms say retrieved data must not be stored. The app
206
+ is the customer's own internal app under its own Slack agreement.
207
+ - **Quoting private Slack content into shared threads**: in a Slack channel thread (through the bot), a tool
208
+ call runs on the acting member's token and the reply goes to a channel others read. There is no special
209
+ rule for this; it relies on the tool policies (the `ask` default of `slack_search_public_and_private`
210
+ plus whatever the org or agent sets).
211
+ - **No identity check**: a member may connect a different Slack account than the one bound to their
212
+ Capybara account; the token still reaches only their own calls.
213
+ - **No revoke on disconnect** and **one client per org** (no platform-level client) in this release.
214
+ - **Scopes**: the full set only; there is no reduced variant (for example without DM scopes).
215
+
125
216
  ## Commands
126
217
 
127
218
  The kernel parses commands from the message text: `/new` (DM: start a new conversation), `/env [name]`
@@ -163,7 +254,7 @@ one in Slack's menu.
163
254
  `trigger_id`) reuses the cached echo, so it is posted once.
164
255
  - The fixed hints are bilingual (English · 中文): the org's IM language is not known on inbound.
165
256
 
166
- Existing apps: re-paste the manifest (**App Manifest** in the app settings) or add the three commands
257
+ Existing apps: re-paste the manifest from the setup guide (**App Manifest** in the app settings) or add the three commands
167
258
  by hand under **Slash Commands**, add the bot scopes `commands` and `im:write`, then **reinstall the
168
259
  app** to the workspace (Slack asks for it because the scopes changed). The bot token stays the same.
169
260
 
@@ -188,8 +279,15 @@ app** to the workspace (Slack asks for it because the scopes changed). The bot t
188
279
  - **Reconnect**: managed by the plugin (SDK auto-reconnect is turned off). When Slack recycles a connection normally it reconnects immediately; consecutive short-lived (under 10 seconds) connections back off exponentially
189
280
  (with jitter), and after 5 in a row, or on receiving `link_disabled`, it reports an error; the kernel records `last_error` and backs off.
190
281
  - **Idempotency**: `chat.postMessage` has no idempotency parameter, so `idempotencyKey` is ignored.
191
- - **Profile**: the display name / avatar come from the `user_profile` carried by the event, otherwise from `users.info` (cached per process for 10 minutes, at most 1000 people,
192
- 1.5 second timeout; if the lookup fails it is left out).
282
+ - **Profile, time zone and language**: every speaker is looked up with
283
+ [`users.info`](https://docs.slack.dev/reference/methods/users.info) `include_locale=true` (Tier 4, `users:read`):
284
+ `user.tz` becomes `sender.timeZone` and `user.locale` becomes `sender.locale`, passed as is (the kernel
285
+ ignores an unknown zone and normalizes the language; both win over the person's Capybara settings for the
286
+ run's date, zone and language). The display name and avatar come from the event's `user_profile` when it
287
+ has one, else from the same lookup. The result is cached in the plugin kv per team and user for 10 minutes
288
+ (shared by every replica; nothing in process memory; an unknown user is cached as empty). The lookup has a
289
+ 1.5 second timeout so the 3 second ack deadline holds; on any failure the fields are left out and nothing
290
+ is cached.
193
291
  - **Permission manifest**: `network: ["slack.com", "wss-primary.slack.com"]`, shown only and not enforced; login (OIDC) and the directory also use
194
292
  `slack.com`. The WSS host for Socket Mode is
195
293
  assigned by Slack and is not fixed (for example `wss-primary.slack.com`, `wss-backup.slack.com`, `wss-111.slack.com`); the manifest's domain
@@ -0,0 +1,52 @@
1
+ # Slack app manifest for the Slack connector of the Capybara Slack plugin (connectors/slack.json).
2
+ # A separate internal app "Capybara connector": user scopes only, MCP on, no bot, no Socket Mode.
3
+ # Paste it at https://api.slack.com/apps -> Create New App -> From a manifest, in the company
4
+ # workspace, after replacing the redirect URL with <http.publicUrl>/api/v1/oauth/callback.
5
+ # Leave Manage Distribution off (internal app) and do not enable PKCE (see README.md).
6
+ # Reference: https://docs.slack.dev/reference/app-manifest and
7
+ # https://docs.slack.dev/ai/slack-mcp-server/ (checked 2026-11-08).
8
+ display_information:
9
+ name: Capybara connector
10
+ description: Lets Capybara agents use Slack as you, with your permission.
11
+ background_color: "#3d2f24"
12
+ oauth_config:
13
+ redirect_urls:
14
+ - https://capybara.example.com/api/v1/oauth/callback
15
+ scopes:
16
+ # The user scopes Slack's MCP server supports; the connector template asks for exactly these.
17
+ user:
18
+ - search:read.public
19
+ - search:read.private
20
+ - search:read.mpim
21
+ - search:read.im
22
+ - search:read.files
23
+ - search:read.users
24
+ - channels:history
25
+ - groups:history
26
+ - mpim:history
27
+ - im:history
28
+ - channels:read
29
+ - groups:read
30
+ - mpim:read
31
+ - im:read
32
+ - channels:write
33
+ - groups:write
34
+ - mpim:write
35
+ - im:write
36
+ - chat:write
37
+ - canvases:read
38
+ - canvases:write
39
+ - lists:read
40
+ - lists:write
41
+ - files:read
42
+ - files:write
43
+ - reactions:read
44
+ - reactions:write
45
+ - emoji:read
46
+ - users:read
47
+ - users:read.email
48
+ settings:
49
+ is_mcp_enabled: true
50
+ org_deploy_enabled: false # true for an Enterprise Grid org-wide install
51
+ socket_mode_enabled: false
52
+ token_rotation_enabled: false
@@ -0,0 +1,85 @@
1
+ {
2
+ "displayName": {
3
+ "zh": "Slack",
4
+ "en": "Slack"
5
+ },
6
+ "description": "Search, read and send Slack messages, canvases, lists and files as the connected person, through Slack's MCP server. Each member connects their own Slack account; an org admin enters the OAuth client of the company's internal Slack app.",
7
+ "icon": "./icon.svg",
8
+ "defaultEnabled": false,
9
+ "template": {
10
+ "plugin": "connector-mcp",
11
+ "pluginVersion": "^0.1.0-rc.1",
12
+ "connector": "mcp",
13
+ "endpoint": {
14
+ "url": "https://mcp.slack.com/mcp"
15
+ },
16
+ "auth": {
17
+ "type": "oauth_code",
18
+ "ownership": "personal",
19
+ "discovery": "mcp",
20
+ "client": "manual",
21
+ "tokenAuthMethod": "client_secret_post",
22
+ "scopes": [
23
+ "search:read.public",
24
+ "search:read.private",
25
+ "search:read.mpim",
26
+ "search:read.im",
27
+ "search:read.files",
28
+ "search:read.users",
29
+ "channels:history",
30
+ "groups:history",
31
+ "mpim:history",
32
+ "im:history",
33
+ "channels:read",
34
+ "groups:read",
35
+ "mpim:read",
36
+ "im:read",
37
+ "channels:write",
38
+ "groups:write",
39
+ "mpim:write",
40
+ "im:write",
41
+ "chat:write",
42
+ "canvases:read",
43
+ "canvases:write",
44
+ "lists:read",
45
+ "lists:write",
46
+ "files:read",
47
+ "files:write",
48
+ "reactions:read",
49
+ "reactions:write",
50
+ "emoji:read",
51
+ "users:read",
52
+ "users:read.email"
53
+ ]
54
+ },
55
+ "defaultToolPolicies": {
56
+ "slack_search_public": "allow",
57
+ "slack_search_channels": "allow",
58
+ "slack_search_users": "allow",
59
+ "slack_search_emojis": "allow",
60
+ "slack_read_channel": "allow",
61
+ "slack_read_thread": "allow",
62
+ "slack_read_canvas": "allow",
63
+ "slack_read_file": "allow",
64
+ "slack_read_list": "allow",
65
+ "slack_read_user_profile": "allow",
66
+ "slack_list_user_channels": "allow",
67
+ "slack_list_channel_members": "allow",
68
+ "slack_get_reactions": "allow",
69
+ "slack_search_public_and_private": "ask",
70
+ "slack_send_message": "ask",
71
+ "slack_schedule_message": "ask",
72
+ "slack_send_message_draft": "ask",
73
+ "slack_create_conversation": "ask",
74
+ "slack_add_reaction": "ask",
75
+ "slack_create_canvas": "ask",
76
+ "slack_update_canvas": "ask",
77
+ "slack_create_list": "ask",
78
+ "slack_add_list_record": "ask",
79
+ "slack_update_list": "ask",
80
+ "slack_update_list_record": "ask",
81
+ "slack_get_file_upload_url": "ask",
82
+ "slack_complete_file_upload": "ask"
83
+ }
84
+ }
85
+ }
package/dist/index.mjs CHANGED
@@ -37078,7 +37078,7 @@ var T = {
37078
37078
  question: "Question",
37079
37079
  tool: "Tool",
37080
37080
  agent: "Agent",
37081
- input: "Input",
37081
+ summary: "Summary",
37082
37082
  status: "Status",
37083
37083
  reason: "Reason",
37084
37084
  expires: "Expires",
@@ -37116,7 +37116,7 @@ var T = {
37116
37116
  question: "提问",
37117
37117
  tool: "工具",
37118
37118
  agent: "Agent",
37119
- input: "输入",
37119
+ summary: "摘要",
37120
37120
  status: "状态",
37121
37121
  reason: "原因",
37122
37122
  expires: "过期时间",
@@ -37230,12 +37230,14 @@ ${esc2(c.agentName)}`, FIELD_LIMIT)
37230
37230
  }
37231
37231
  ];
37232
37232
  if (c.inputPreview !== "") {
37233
- const head = `*${t.input}*
37234
- \`\`\`
37235
- `;
37236
- const tail = "\n```";
37237
- const body = trunc(esc2(c.inputPreview), SECTION_TEXT_LIMIT - head.length - tail.length);
37238
- blocks.push(section(`${head}${body}${tail}`));
37233
+ blocks.push({
37234
+ type: "section",
37235
+ text: {
37236
+ type: "plain_text",
37237
+ text: trunc(`${t.summary}${t.sep}${c.inputPreview}`, SECTION_TEXT_LIMIT),
37238
+ emoji: false
37239
+ }
37240
+ });
37239
37241
  }
37240
37242
  if (c.state !== "pending") {
37241
37243
  const state = t.approvalStates[c.state];
@@ -37625,6 +37627,19 @@ function eventToInbound(body, botUserId) {
37625
37627
  }
37626
37628
  };
37627
37629
  }
37630
+ function userInfoProfile(u) {
37631
+ const o = obj2(u);
37632
+ if (!o) return void 0;
37633
+ const base = profileOf(o.profile) ?? profileOf({ real_name: o.real_name, name: o.name });
37634
+ const timeZone = str3(o.tz);
37635
+ const locale = str3(o.locale);
37636
+ if (base === void 0 && timeZone === void 0 && locale === void 0) return void 0;
37637
+ return {
37638
+ ...base,
37639
+ ...timeZone !== void 0 && { timeZone },
37640
+ ...locale !== void 0 && { locale }
37641
+ };
37642
+ }
37628
37643
 
37629
37644
  // src/webhook.ts
37630
37645
  import { createHmac, timingSafeEqual } from "node:crypto";
@@ -37748,8 +37763,7 @@ var MIN_EDIT_INTERVAL_MS = 2500;
37748
37763
  var SHORT_LIVED_MS = 1e4;
37749
37764
  var MAX_SHORT_LIVED = 5;
37750
37765
  var MAX_RECONNECT_DELAY_MS = 3e4;
37751
- var PROFILE_TTL_MS = 10 * 6e4;
37752
- var PROFILE_CACHE_MAX = 1e3;
37766
+ var PROFILE_CACHE_TTL_SECONDS = 600;
37753
37767
  var PROFILE_TIMEOUT_MS = 1500;
37754
37768
  var BOT_DM_CACHE_TTL_SECONDS = 86400;
37755
37769
  var COMMAND_ECHO_TTL_SECONDS = 3600;
@@ -37823,44 +37837,55 @@ function createSlackChannel(opts) {
37823
37837
  });
37824
37838
  };
37825
37839
  const parse = (config) => SlackConnection.parse(config);
37826
- const profiles = /* @__PURE__ */ new Map();
37827
- const lookupProfile = async (botToken, scope, userId, signal) => {
37828
- const key = `${scope}\0${userId}`;
37829
- const hit = profiles.get(key);
37830
- if (hit && Date.now() - hit.at < PROFILE_TTL_MS) return hit.profile;
37840
+ const lookupProfile = async (botToken, teamId, userId, signal) => {
37841
+ const key = `profile/${teamId}/${userId}`;
37842
+ const hit = await opts.kv?.get(key).catch(() => null);
37843
+ if (hit) {
37844
+ try {
37845
+ const cached = JSON.parse(hit);
37846
+ return Object.keys(cached).length > 0 ? cached : void 0;
37847
+ } catch {
37848
+ }
37849
+ }
37831
37850
  let profile;
37832
37851
  try {
37833
37852
  const s = AbortSignal.any([signal, AbortSignal.timeout(PROFILE_TIMEOUT_MS)]);
37834
- const r = await web(botToken, s).apiCall("users.info", { user: userId });
37835
- profile = profileOf(r.user?.profile) ?? profileOf({ real_name: r.user?.real_name, name: r.user?.name });
37853
+ const r = await web(botToken, s).apiCall("users.info", {
37854
+ user: userId,
37855
+ include_locale: true
37856
+ });
37857
+ profile = userInfoProfile(r.user);
37836
37858
  } catch (e) {
37837
- const code = platformErrorCode(e);
37838
- if (code !== "user_not_found") return void 0;
37839
- }
37840
- profiles.delete(key);
37841
- profiles.set(key, { at: Date.now(), profile });
37842
- if (profiles.size > PROFILE_CACHE_MAX) {
37843
- const oldest = profiles.keys().next().value;
37844
- if (oldest !== void 0) profiles.delete(oldest);
37859
+ if (platformErrorCode(e) !== "user_not_found") return void 0;
37845
37860
  }
37861
+ await opts.kv?.set(key, JSON.stringify(profile ?? {}), { ttlSeconds: PROFILE_CACHE_TTL_SECONDS }).catch(() => {
37862
+ });
37846
37863
  return profile;
37847
37864
  };
37848
37865
  const withProfile = (sender, p) => ({
37849
37866
  ...sender,
37850
37867
  ...p?.displayName !== void 0 && { displayName: p.displayName },
37851
- ...p?.avatarUrl !== void 0 && { avatarUrl: p.avatarUrl }
37868
+ ...p?.avatarUrl !== void 0 && { avatarUrl: p.avatarUrl },
37869
+ ...p?.timeZone !== void 0 && { timeZone: p.timeZone },
37870
+ ...p?.locale !== void 0 && { locale: p.locale }
37852
37871
  });
37853
- const toEvent = async (c, connectionId, botUserId, { type, body }, signal) => {
37872
+ const toEvent = async (c, botUserId, { type, body }, signal) => {
37854
37873
  if (type === "events_api") {
37855
37874
  const cand = eventToInbound(body, botUserId);
37856
37875
  if (!cand) return null;
37857
37876
  if (cand.kind === "directory") return cand.event;
37858
- const p2 = cand.profile ?? await lookupProfile(c.botToken, connectionId, cand.userId, signal);
37877
+ const looked = await lookupProfile(
37878
+ c.botToken,
37879
+ cand.event.sender.tenantId,
37880
+ cand.userId,
37881
+ signal
37882
+ );
37883
+ const p2 = looked || cand.profile ? { ...looked, ...cand.profile } : void 0;
37859
37884
  return { ...cand.event, sender: withProfile(cand.event.sender, p2) };
37860
37885
  }
37861
37886
  const a = parseBlockActions(body);
37862
37887
  if (!a) return null;
37863
- const p = await lookupProfile(c.botToken, connectionId, a.sender.externalId, signal) ?? (a.username !== void 0 ? { displayName: a.username } : void 0);
37888
+ const p = await lookupProfile(c.botToken, a.sender.tenantId, a.sender.externalId, signal) ?? (a.username !== void 0 ? { displayName: a.username } : void 0);
37864
37889
  return {
37865
37890
  type: "card_action",
37866
37891
  messageId: a.messageId,
@@ -37931,7 +37956,7 @@ function createSlackChannel(opts) {
37931
37956
  if (!cmd) return { event: null, response: void 0 };
37932
37957
  const text = slashCommandText(cmd.command, cmd.text);
37933
37958
  if (text === null) return { event: null, response: ephemeral(SLASH_REPLIES.usage) };
37934
- const profile = lookupProfile(c.botToken, connectionId, cmd.userId, signal).then(
37959
+ const profile = lookupProfile(c.botToken, cmd.teamId, cmd.userId, signal).then(
37935
37960
  (p2) => p2 ?? (cmd.userName !== void 0 ? { displayName: cmd.userName } : void 0)
37936
37961
  );
37937
37962
  const sender = { externalId: cmd.userId, tenantId: cmd.teamId };
@@ -38018,7 +38043,7 @@ function createSlackChannel(opts) {
38018
38043
  let response;
38019
38044
  try {
38020
38045
  if (type === "events_api" || type === "interactive") {
38021
- event = await toEvent(c, connectionId, botUserId, { type, body }, signal);
38046
+ event = await toEvent(c, botUserId, { type, body }, signal);
38022
38047
  } else if (type === "slash_commands") {
38023
38048
  ({ event, response } = await toCommand(c, connectionId, body, signal));
38024
38049
  }
@@ -38141,7 +38166,7 @@ function createSlackChannel(opts) {
38141
38166
  },
38142
38167
  toEvent: async (envelope, botUserId) => {
38143
38168
  try {
38144
- return await toEvent(c, connectionId, botUserId, envelope, signal);
38169
+ return await toEvent(c, botUserId, envelope, signal);
38145
38170
  } catch (e) {
38146
38171
  log.warn("slack: could not read a webhook event; acknowledging and skipping it", {
38147
38172
  connectionId,
@@ -39168,7 +39193,7 @@ function createSlackIdentitySource() {
39168
39193
  // src/index.ts
39169
39194
  var index_default = defineExtension({
39170
39195
  name: "slack",
39171
- version: "0.1.0-rc.3",
39196
+ version: "0.1.0-rc.4",
39172
39197
  sdk: "^0.1.0-rc.0",
39173
39198
  provides: [CHANNEL_EXTENSION_POINT, IDENTITY_SOURCE_EXTENSION_POINT, DIRECTORY_EXTENSION_POINT],
39174
39199
  permissions: { network: ["slack.com", "wss-primary.slack.com"] },
@@ -1,10 +1,12 @@
1
- # Slack app manifest for the Capybara Slack plugin (@capybara-hq/plugin-slack).
2
- # Paste it at https://api.slack.com/apps -> Create New App -> From a manifest.
3
- # Reference: https://docs.slack.dev/reference/app-manifest (checked 2026-10-20).
1
+ # Slack app manifest for the Capybara Slack plugin (@capybara-hq/plugin-slack), Socket Mode (long connection).
2
+ # Capybara renders this file for a channel connection (setup guide "slack-app"); paste it at
3
+ # https://api.slack.com/apps -> Create New App -> From a manifest.
4
+ # Reference: https://docs.slack.dev/reference/app-manifest (checked 2026-11-09).
4
5
  # Socket Mode needs no public request URL; the app-level token (xapp-, scope connections:write)
5
- # is created separately under Basic Information -> App-Level Tokens (see README.md).
6
+ # is created separately under Basic Information -> App-Level Tokens.
6
7
  display_information:
7
- name: Capybara
8
+ # Slack caps app names at 35 characters; shorten it in the app settings if it is longer.
9
+ name: "{{connectionName}}"
8
10
  description: Chat with your organization's Capybara agents.
9
11
  background_color: "#3d2f24"
10
12
  features:
@@ -13,12 +15,12 @@ features:
13
15
  messages_tab_enabled: true
14
16
  messages_tab_read_only_enabled: false
15
17
  bot_user:
18
+ # Fixed: the bot user's name has the same 35-character cap, and a connection name may be longer.
16
19
  display_name: capybara
17
20
  always_online: true
18
21
  # Slack rejects a message starting with an unregistered "/name", so the kernel's commands are
19
22
  # registered here. The plugin turns each into the text the kernel parses: /new -> "/new",
20
- # /env x -> "/env x", /capybara foo bar -> "/foo bar" (skill invocation). No url: Socket Mode
21
- # delivers them; in webhook mode set each command's Request URL to the webhook URL.
23
+ # /env x -> "/env x", /capybara foo bar -> "/foo bar" (skill invocation).
22
24
  slash_commands:
23
25
  - command: /new
24
26
  description: Start a new conversation (direct message)
@@ -32,11 +34,10 @@ features:
32
34
  usage_hint: "<skill> [args]"
33
35
  should_escape: false
34
36
  oauth_config:
35
- # Sign in with Slack (identity-source@1): uncomment and set to <http.publicUrl>/api/v1/auth/sso/slack/callback.
36
- # The sign-in flow requests openid / email / profile itself; do not add them as scopes here (Slack wants
37
- # Sign in with Slack scopes in a separate OAuth flow, see README.md).
38
- # redirect_urls:
39
- # - https://capybara.example.com/api/v1/auth/sso/slack/callback
37
+ # Sign in with Slack (identity-source@1): <http.publicUrl>/api/v1/auth/sso/slack/callback. The
38
+ # sign-in flow requests openid / email / profile itself; they are not app scopes.
39
+ redirect_urls:
40
+ - "{{signInCallbackUrl}}"
40
41
  scopes:
41
42
  bot:
42
43
  - chat:write # post and update replies and cards
@@ -46,7 +47,7 @@ oauth_config:
46
47
  - app_mentions:read # app_mention: @capybara in channels
47
48
  - channels:history # message.channels: thread replies in public channels
48
49
  - groups:history # message.groups: thread replies in private channels
49
- - users:read # users.info (display name, avatar); team_join / user_change; directory@1 users.list
50
+ - users:read # users.info (name, avatar, time zone, locale); team_join / user_change; users.list
50
51
  - users:read.email # directory@1: email addresses in users.list (the bot itself does not use it)
51
52
  settings:
52
53
  event_subscriptions:
@@ -0,0 +1,70 @@
1
+ # Slack app manifest for the Capybara Slack plugin (@capybara-hq/plugin-slack), webhook inbound mode.
2
+ # Capybara renders this file for a channel connection (setup guide "slack-app"); paste it at
3
+ # https://api.slack.com/apps -> Create New App -> From a manifest.
4
+ # Reference: https://docs.slack.dev/reference/app-manifest (checked 2026-11-09).
5
+ # Webhook mode: Slack posts events, card clicks and slash commands to the connection's webhook
6
+ # URL and verifies it when you save; requests are signed with the app's Signing Secret.
7
+ display_information:
8
+ # Slack caps app names at 35 characters; shorten it in the app settings if it is longer.
9
+ name: "{{connectionName}}"
10
+ description: Chat with your organization's Capybara agents.
11
+ background_color: "#3d2f24"
12
+ features:
13
+ app_home:
14
+ home_tab_enabled: false
15
+ messages_tab_enabled: true
16
+ messages_tab_read_only_enabled: false
17
+ bot_user:
18
+ # Fixed: the bot user's name has the same 35-character cap, and a connection name may be longer.
19
+ display_name: capybara
20
+ always_online: true
21
+ # Slack rejects a message starting with an unregistered "/name", so the kernel's commands are
22
+ # registered here. The plugin turns each into the text the kernel parses: /new -> "/new",
23
+ # /env x -> "/env x", /capybara foo bar -> "/foo bar" (skill invocation).
24
+ slash_commands:
25
+ - command: /new
26
+ url: "{{webhookUrl}}"
27
+ description: Start a new conversation (direct message)
28
+ should_escape: false
29
+ - command: /env
30
+ url: "{{webhookUrl}}"
31
+ description: List or set your default environment (direct message)
32
+ usage_hint: "[name]"
33
+ should_escape: false
34
+ - command: /capybara
35
+ url: "{{webhookUrl}}"
36
+ description: Run a skill
37
+ usage_hint: "<skill> [args]"
38
+ should_escape: false
39
+ oauth_config:
40
+ # Sign in with Slack (identity-source@1): <http.publicUrl>/api/v1/auth/sso/slack/callback. The
41
+ # sign-in flow requests openid / email / profile itself; they are not app scopes.
42
+ redirect_urls:
43
+ - "{{signInCallbackUrl}}"
44
+ scopes:
45
+ bot:
46
+ - chat:write # post and update replies and cards
47
+ - commands # slash commands /new, /env, /capybara
48
+ - im:write # conversations.open: tell the bot's own DM from other DMs a slash command runs in
49
+ - im:history # message.im: direct messages to the bot
50
+ - app_mentions:read # app_mention: @capybara in channels
51
+ - channels:history # message.channels: thread replies in public channels
52
+ - groups:history # message.groups: thread replies in private channels
53
+ - users:read # users.info (name, avatar, time zone, locale); team_join / user_change; users.list
54
+ - users:read.email # directory@1: email addresses in users.list (the bot itself does not use it)
55
+ settings:
56
+ event_subscriptions:
57
+ request_url: "{{webhookUrl}}"
58
+ bot_events:
59
+ - message.im
60
+ - app_mention
61
+ - message.channels
62
+ - message.groups
63
+ - team_join
64
+ - user_change
65
+ interactivity:
66
+ is_enabled: true
67
+ request_url: "{{webhookUrl}}"
68
+ socket_mode_enabled: false
69
+ org_deploy_enabled: false
70
+ token_rotation_enabled: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-slack",
3
- "version": "0.1.0-rc.3",
3
+ "version": "0.1.0-rc.4",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Slack (channel@1 bot over Socket Mode with Block Kit cards, identity-source@1 Sign in with Slack, directory@1)",