8000 feat(slack): create and keep the Slack app configured from mikan's manifest by geminixiang · Pull Request #179 · geminixiang/mikan · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ change in a minor release.
with a link and ends its turn. The desktop starts on the first link, stops with the sandbox's idle
stop, and keeps the sandbox from stopping while someone has it open. It needs the sandbox image of
this release; an office whose sandbox still runs an older image gets it after the sandbox idles out.
Register `/pi-desktop` in the Slack app manifest.
Register `/pi-desktop` in the Slack app manifest, or let mikan do it (next entry).
- mikan creates and updates its Slack app (A 8000 DR 0026). With a Slack app configuration token,
`mikan onboard` creates the app from mikan's manifest, and every start replaces the app's
configuration with the manifest of the running release, so new slash commands, scopes, and events
need no edit in Slack's settings. Store a token for an existing app with `mikan slack token`, and
set the app's name and description with `mikan slack set`. Settings added by hand in Slack are
removed. When a release adds a scope, mikan DMs the token's owner a reinstall link. Without a
token nothing changes.

### Changed

Expand Down
43 changes: 24 additions & 19 deletions deploy/examples/slack-app-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,51 @@
"slash_commands": [
{
"command": "/pi-login",
"description": "login",
"description": "Store credentials in your private vault",
"should_escape": false
},
{
"command": "/pi-new",
"description": "start a new session",
"command": "/pi-session",
"description": "Open the current session in the web viewer",
"should_escape": false
},
{
"command": "/pi-compact",
"description": "summarize older messages to free up context",
"command": "/pi-desktop",
"description": "Open this conversation's desktop to watch or use its browser",
"should_escape": false
},
{
"command": "/pi-model",
"description": "switch this conversation's LLM",
"description": "Switch this conversation's LLM model",
"usage_hint": "provider/model[:thinking], e.g. anthropic/claude-sonnet-4-6:off",
"should_escape": false
},
{
"command": "/pi-session",
"description": "session viewer",
"command": "/pi-sandbox",
"description": "Show sandbox status or boost limits",
"usage_hint": "'boost' temporarily applies the configured boost limits",
"should_escape": false
},
{
"command": "/pi-desktop",
"description": "office desktop",
"command": "/pi-auto-reply",
"description": "Enable, disable, or Jev-assist replies without mentions",
"usage_hint": "on, off, or jev",
"should_escape": false
},
{
"command": "/pi-sandbox",
"description": "sandbox",
"command": "/pi-new",
"description": "Reset conversation history and start fresh",
"should_escape": false
},
{
"command": "/pi-auto-reply",
"description": "on | off | jev",
"command": "/pi-compact",
"description": "Summarize older messages to free up context",
"usage_hint": "What the summary should keep",
"should_escape": false
},
{
"command": "/pi-admin",
"description": "open admin portal",
"description": "Open the admin portal",
"should_escape": false
}
]
Expand All @@ -66,21 +70,21 @@
"redirect_urls": ["https://localhost"],
"scopes": {
"bot": [
"reactions:write",
"app_mentions:read",
"channels:history",
"channels:read",
"chat:write",
"chat:write.customize",
"commands",
"files:read",
"files:write",
"groups:history",
"groups:read",
"im:history",
"im:write",
"im:read",
"users:read",
"commands"
"im:write",
"reactions:write",
"users:read"
]
},
"pkce_enabled": false
Expand All @@ -101,6 +105,7 @@
"org_deploy_enabled": false,
"socket_mode_enabled": true,
"token_rotation_enabled": false,
"app_level_token_rotation_enabled": false,
"is_mcp_enabled": false
}
}
47 changes: 47 additions & 0 deletions docs/adr/0026-mikan-keeps-its-slack-app-configured.md
BD0
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
status: accepted
---

# mikan keeps its Slack app configured

Each mikan release carries the Slack app manifest it needs, and the daemon applies it to the Slack app at startup, so an upgrade that adds a slash command, scope, or event needs no manual change in Slack's app settings. `mikan onboard` can also create the app.

## Context

Until now an operator copied `deploy/examples/slack-app-manifest.json` into Slack's settings page by hand, and repeated that on every release that changed it; `/pi-desktop` does not exist in an app nobody edited. Live apps also drift: one test app differed from every repository manifest by scopes, events, and features added by hand.

Slack's App Manifest API was tested on a test app:

| Call | Result |
| ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `apps.manifest.export` / `validate` / `update` | Update replaces the whole manifest in about 0.6 s. A new slash command reached the running daemon at once, without reinstalling. |
| Adding a bot scope | `permissions_updated: true`; the installed bot token keeps working and gains the scope only after someone reinstalls the app. |
| `tooling.tokens.rotate` | The configuration token lasts 12 hours. Rotation returns a new token and refresh token and revokes the previous access token, including one held by another process. |
| `apps.manifest.create`, then export | Returns the app ID, secrets, and install URL. Slack adds `agent_tasks_enabled: true` to the App Home of new apps and ignores the value sent; older apps never get the field. |
| `bots.info` with the bot token | Returns the app ID, so the operator does not enter it. |

A configuration token belongs to the person who created it and to one workspace, not to the app.

## Decision

- **The desired manifest is code.** `src/adapters/slack/app-config.ts` owns one manifest per release for a classic Slack app (mentions and DMs, not the Agents & AI apps surface). Slash commands come from the command manifest, and `deploy/examples/slack-app-manifest.json` is tested to equal it.
- **Operator customization lives in `~/.mikan/slack.json`**, written by `mikan slack set`. It holds only Slack's `display_information` fields (name, description, long description, background color), validated with Slack's length limits. The applied manifest is the built-in one with those fields replaced.
- **The daemon syncs at startup** when `slack-config-token.json` exists: rotate the token and save the new pair first, find the app ID from the bot token, export the live manifest, and update when it differs from the desired one, ignoring key order and the fields Slack manages itself. The live app then matches mikan; settings added by hand in Slack are removed.
- **New scopes need a person.** When an update reports `permissions_updated` and the bot token lacks a desired scope, mikan DMs the token's owner a reinstall link once, and keeps running with the scopes it has.
- **Failures never stop startup.** Each Slack call has a 15 s timeout and no retries; a failure logs one warning and leaves the app as it was.
- **Without a configuration token nothing changes.**
- **`mikan onboard` creates new apps.** Picking Slack offers to create the app: onboarding asks for the configuration refresh token and the app name and description, and after confirmation creates the app with `apps.manifest.create`. It then prints the install link and where to create the app-level token, and asks for the bot token and the `xapp-` token, the two steps Slack offers no API for. If onboarding fails or is declined after that, it deletes the app.
- **Existing apps join through the CLI.** `mikan slack token` takes the refresh token, checks it by rotating, and stores the pair; the next start syncs the app.

## Not decided here

- The app icon: the manifest has no icon field; Slack's separate `apps.icon.set` works with the same token but is out of scope.

## Consequences

- Edits in Slack's settings pages are overwritten on the next start; `mikan slack set` is the supported way to customize.
- Every rotation revokes the previous access token, so one configuration token serves one mikan install.
- A configuration token stops working when its owner leaves the workspace or loses access to the app; sync then logs a warning, and the operator stores a token from another collaborator.
- An app built from the agent manifest loses the agent surface once a token is stored, because the built-in manifest is the classic app.
- Removing a scope from the manifest does not remove it from an installed token.
- Startup waits for about five Slack API calls, around 1 to 2 s.
12 changes: 12 additions & 0 deletions src/adapters/slack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ This directory implements the Slack platform adapter and Slack-specific session/
- `@slack/socket-mode` rejects `start()` with `undefined` when `disconnect()` interrupts a connection attempt. `start()` treats that rejection as a normal stop once `stop()` has run; otherwise `main.ts` would log `Failed to start bot undefined` and exit with code 1 in the middle of a graceful shutdown.
- DM task intent (`task-intent.ts`) is classified by Jev and falls back to `isTaskStatusQuestion` when Jev is unavailable.

## App configuration

- `app-config.ts` owns the Slack app manifest; `deploy/examples/slack-app-manifest.json` must equal `slackAppManifest()`, and slash commands come from the command manifest. With `slack-config-token.json` in the state directory, startup rotates the token, exports the live app, and replaces it when it differs, so the live app equals the manifest plus `slack.json`'s display fields (ADR 0026). Sync failures are logged and never stop startup.
- Rotation revokes the previous access token, while the previous refresh token keeps working for a while, so the newest pair is saved before any other call. Two installs sharing one token revoke each other's access tokens.
- Slack sets some fields itself and ignores what is sent for them: `features.app_home.agent_tasks_enabled` is on for apps created after Slack added it and absent on older ones. The comparison skips these fields; otherwise every start would update the app.

## App configuration

- `app-config.ts` owns the Slack app manifest; `deploy/examples/slack-app-manifest.json` must equal `slackAppManifest()`, and slash commands come from the command manifest. With `slack-config-token.json` in the state directory, startup rotates the token, exports the live app, and replaces it when it differs, so the live app equals the manifest plus `slack.json`'s display fields (ADR 0026). Sync failures are logged and never stop startup.
- Rotation revokes the previous access token, so the new pair is saved before any other call, and two installs sharing one token revoke each other's.
- Slack sets some fields itself and ignores what is sent for them: `features.app_home.agent_tasks_enabled` is on for apps created after Slack added it and absent on older ones. The comparison skips these fields; otherwise every start would update the app.

## DM tasks

Top-level DM responders expose `startTask(message, task)`. Admission posts a
Expand Down
Loading
Loading
0