Skip to content

slack: search channels by name in the channel map (BB-58) - #84

Merged
trotterdylan merged 2 commits into
mainfrom
bb/bb-58-bb-plugins-slack-channel-search-picker-thr_b2n3mv2rkx
Oct 25, 2026
Merged

trotterdylan merged 2 commits into
mainfrom
bb/bb-58-bb-plugins-slack-channel-search-picker-thr_b2n3mv2rkx

Conversation

@trotterdylan

Copy link
Copy Markdown
Collaborator

Implements BB-58 (plugin half, PR 2 of 2; the bb-gate half is bitcomplete/bb-gate#37, merged). The channel map's channel box becomes a search-by-name typeahead over the channels the signed-in developer can see, while the stored map stays a JSON array of {channel, project} ids.

Merging this moves the bb-plugins pin, builds a new bb-server image and stages a restart on every developer's server. Do not press Restart now from a thread you still need; a server left alone restarts in the quiet window.

Classification

owner-reviewed: a cross-repo contract (the Slack sign-in token shape and GET /v1/slack/bot/channels in bb-gate/docs/hooks.md, "Slack agent") and a change to existing behaviour (the channel box, and the sign-in token now reads channel lists).

What changes

  • New searchChannels RPC: calls Slack's conversations.list directly with the stored user token (types=public_channel,private_channel, exclude_archived=true), paginated with a page cap, cached in memory per server for five minutes and keyed by token, and filtered by name locally. is_ext_shared is returned, not hidden. A token Slack refuses as the wrong kind or lacking scope answers signin-required; a Slack outage answers unavailable, so the page still loads.
  • plugins/slack/slack-channels.ts: the Slack client and cache; the token goes in one Authorization header and is never logged.
  • ChannelMapEditor (app.tsx): the channel box is a typeahead that shows #name with a lock for a private channel, marks Slack Connect channels, flags channels bb's bot is not in ("bb is not in this channel yet; invite it"), and stores the id. A pasted C…/G… id and dm still work. With an OpenID token it says "Sign in again to search channels" and falls back to the id box.
  • hooks-client.ts: fetchBotChannels for the cluster-only GET /v1/slack/bot/channels.
  • Storage is unchanged: parseChannelMap, chooseConversationProject and routing in sessions.ts are untouched. The user token stays in the same secret setting.

Testing

  • npm run typecheck in plugins/slack: pass.
  • npm test in plugins/slack: pass (62 tests; slack is not in the CI matrix). New coverage: pagination, the cache and its refresh, local name filtering, the OpenID-token case, no-token, Slack-unavailable, bot-membership failure, and the unchanged save path.
  • npm run build in plugins/slack: pass.
  • Not tested: the real Slack API against a workspace (needs the admin scopes and a signed-in developer); the picker was exercised through the fake Slack in tests, not a browser.

Manual step before merge

A Slack admin must add the user scopes channels:read, groups:read and the bot scopes channels:read, groups:read on the bb app and reinstall it. The owner confirms this on BB-58; this PR waits for that and the owner's approval before merging.

Call Slack's conversations.list with the developer's own sign-in user
token, paginated and cached per server, and serve it to the settings page
through a new searchChannels RPC. The channel box in ChannelMapEditor
becomes a typeahead that shows #name (with a lock for a private channel),
marks Slack Connect channels and flags channels bb's bot is not in, and
stores the id; a pasted C…/G… id and dm still work. A still-valid OpenID
token cannot list channels, so the picker asks the developer to sign in
again and falls back to the id box.

The channels setting, parseChannelMap, chooseConversationProject and
routing in sessions.ts are unchanged; the token is never logged.
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_snu4ebvgek.

— from bb thread thr_b2n3mv2rkx

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at df1ce70)

Owner review required: yes — this consumes the cross-repo sign-in contract the merged bb-gate#37 shipped (the xoxp- user token shape and GET /v1/slack/bot/channels from docs/hooks.md, "Slack agent"), it puts a new credential on every developer's pod (a token that can read channel lists as that developer), and it changes existing behaviour (the channel box and the sign-in description). @trotterdylan, this one needs your approval — and, per the PR body, the Slack admin's scopes + reinstall before it merges.

Blockers

None.

Suggestions

  • app.tsx (matches) — the dropdown slices to 50 matches with no hint that it truncated. Typing a broad prefix like a silently hides everything past the first 50; one "Refine your search to see more" line when matches was capped would keep that honest.
  • slack-channels.ts (CHANNEL_PAGE_CAP) — a workspace with more than 20 pages (4,000 channels) gets a silently partial list: the loop breaks with only a server-side log warn. Rare, and the cap is the right guard against a looping cursor, but consider surfacing it (e.g. a flag in the RPC response) so the developer knows the list is incomplete.
  • app.tsx (useEffect(loadChannels, …)) — loadChannels returns a Promise, so the effect returns one too; React warns in dev ("an effect must not return anything besides a function"). Wrapping the body in braces fixes it. The existing useEffect(refetch, …) has the same shape, so this is cosmetic consistency, not a bug.
  • ChannelPicker — keyboard users can reach options only by typing an exact name/id and pressing Enter; the dropdown rows have no arrow-key navigation, and Tab blurs the input and closes the list. For a settings page used once per mapping, acceptable, but arrow keys would make the combobox properly operable from the keyboard.

Checked

  • Ran, in plugins/slack (slack is not in the plugins workflow's CI matrix — the green checks on this PR never exercised it): npm run typecheck (pass), npm test (3 files, 62 tests, pass), npm run build (pass).
  • Verified the contract against bb-gate main (docs/hooks.md, "Slack agent"): signin/start/signin/exchange shapes are consumed unchanged as documented, fetchBotChannels matches GET /v1/slack/bot/channels → {"channels":[…]}, cluster-only, best-effort with botChannels: null on failure.
  • Verified against ticket:
    • searchChannels RPC: conversations.list with types=public_channel,private_channel, exclude_archived=true, limit=200 paginated with a cursor — met (test asserts cursors [null,"1"] and the Bearer token used).
    • Cached in memory a few minutes per server, keyed by token — met (5-min TTL; test advances 6 min and sees exactly one refresh; a fresh token never gets the old list).
    • Name filtering local — met (filter test makes no second Slack call; the picker loads the full list once with query: "").
    • is_ext_shared marked, not hidden — met ("Slack Connect" in option meta and row note).
    • Picker: #name, 🔒/"private" for private channels, stores the id; existing rows resolve names from the same list; channels outside the bot membership list flagged "bb is not in this channel yet; invite it"; pasted C…/G… id (exact id, rawId row, or blur-accept) and dm all still work — met.
    • OpenID token → "Sign in again to search channels" and the id-box fallback (canSearch: false); no token → same; Slack outage → unavailable with a message, page still loads — met.
    • Storage unchanged: channels.ts, sessions.ts, sessions.test.ts untouched in the diff (git diff origin/main...HEAD --stat over them is empty); parseChannelMap, chooseConversationProject, setChannels save path unchanged, with a test exercising save while search is unavailable.
    • Token safety: the token goes into one Authorization header and nowhere else; tests assert it never appears in logs (xoxp-old-openid, xoxp-user-1, xoxp-user-token); no agent tool or doorbell carries it; no new store migration.
  • Restart behaviour: the cache is memory-only, so a server restart re-fetches — correct.
  • PR body says the required things: the pin/image/restart statement and the Slack-admin manual step; its Classification line (owner-reviewed) matches what the diff shows.

— from bb thread thr_snu4ebvgek

Address the review's suggestions: the searchChannels RPC reports whether
the page cap cut the list short and the picker says so, and the dropdown
says when it is showing only the first 50 matches. loadChannels already
has a block body and returns undefined, so no effect change was needed.
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 1 suggestions, all answered; head is now e4754e8.

  • 50-match cap hint — fixed in e4754e8: the dropdown shows "Refine your search to see more." when the pre-slice match count exceeds 50.
  • Silently partial list at the page cap — fixed in e4754e8: searchChannels now returns truncated, and the editor says "Slack has more channels than could be listed here; some may be missing from the search." Added a test that forces 21 pages and asserts 20 fetched + truncated: true.
  • useEffect(loadChannels, …) returns a Promise — declined: loadChannels has a block body (useCallback(() => { rpc.call(...).then(...) })), so it returns undefined, not a Promise; tsc would reject an effect returning one. No change needed.
  • Arrow-key navigation — declined: out of scope for this ticket. The map is edited once per mapping; a full combobox with roving focus and ARIA would be a larger change than the spec asks for.

— from bb thread thr_b2n3mv2rkx

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (GLM 5.3, at e4754e8)

Owner review required: yes — unchanged from round 1 (cross-repo sign-in contract from the merged bb-gate#37, a new credential on every developer's pod, and a change to the existing channel box). @trotterdylan, this one still needs your approval plus the Slack admin's scopes/reinstall noted in the PR body.

Blockers

None. The round-1 verdict stands over this push: it only implements my round-1 suggestions, which never needed fresh approval.

Resolved since round 1

  • Suggestion 1 (silent 50-match cap): resolved — allMatches/matches/capped, with the "Refine your search to see more." line exactly when the list was cut.
  • Suggestion 2 (page cap truncation silent): resolved — SlackChannelList.truncated threaded through the cache, the RPC output schema, and the editor ("Slack has more channels than could be listed here…"), with a new test forcing 21 pages and asserting truncated: true, 20 channels and 20 requests. Correct, including the cache carrying the flag.

Withdrawn

  • Suggestion 3 (useEffect(loadChannels, …) returning a Promise): you are right and I was wrong — loadChannels has a block body whose rpc.call(...).then(...) is a statement, so it returns undefined and React is fine. Withdrawn; nothing to change.

Declined

  • Suggestion 4 (arrow-key navigation): declined as out of scope for a settings page edited once per mapping — accepted; Enter on an exact name/id plus mouse covers it.

Checked

  • Ran, in plugins/slack (still not in the CI matrix): npm run typecheck (pass), npm test (63 tests, pass — the new page-cap test included), npm run build (pass).
  • The new diff touches nothing classified: storage, routing and the sign-in flow are untouched; the lane stays owner-reviewed for the round-1 reasons.

— from bb thread thr_snu4ebvgek

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

LGTM

@trotterdylan
trotterdylan merged commit a643dcf into main Oct 25, 2026
20 checks passed
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: owner-reviewed lane, reviewer approved e4754e8, checks green, approved by the owner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant