Skip to content

slack: a channel -> project map, assistant context and owner confirmation (BB-43) - #71

Merged
trotterdylan merged 2 commits into
mainfrom
bb/bb-43-slack-channel-project-map-bb-plugins-thr_3rivcnhgvk
Oct 24, 2026
Merged

trotterdylan merged 2 commits into
mainfrom
bb/bb-43-slack-channel-project-map-bb-plugins-thr_3rivcnhgvk

Conversation

@trotterdylan

Copy link
Copy Markdown
Collaborator

Implements BB-43, step 2 (bb-plugins). A Slack plugin setting maps a channel id (or the reserved dm) to a bb project; a channel mention starts its thread in the mapped project, a DM uses the dm entry, a DM typed while the assistant pane shows a mapped channel uses that channel's project, and an unmapped conversation uses the plugin's Project setting as before. A channel mention by anyone but the server's owner no longer runs a turn: the words are held and the plugin asks the owner to confirm them by id first.

Restart note. Merging to bb-plugins main moves the 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. The owner still has to add app_mentions:read and chat:write.customize and the app_mention bot event to the Slack app and reinstall it (by hand, after this and bb-gate#34 merge); until then Slack sends no channel mentions.

Classification

no-review: additive. A new setting (channels) whose empty default keeps today's behaviour exactly, a new settings-page editor, and a new hold path that only applies to text that is not the owner's. No existing behaviour changes.

What changes

  • sessions.ts: the channel-map schema and parsing (junk dropped, never a wake failure), channelProject (id keyed, dm case-insensitive), chooseConversationProject (channel id → remembered context channel → dm → default; an entry naming a project this server lacks is skipped so the same map works everywhere), parseConfirm, and the held-request schemas. chooseProject moves here unchanged and is re-exported from server.ts.
  • server.ts: a channels string setting (JSON, multiline, validated), status returns the parsed map and a setChannels RPC replaces it. targetProject consults the map with the conversation's channel and the session's remembered contextChannel. An untrusted wake is parked under an r-… id in kv and answered with one elicitation; the owner's confirm <id> releases it (a vague reply re-asks). A context change remembers the viewed channel per DM session and runs no turn.
  • hooks-client.ts: the wake schema gains the optional contextChannel (empty default, so older wakes parse).
  • app.tsx: the settings section gets a channel-map list editor (channel id + project + remove, save), showing "Direct message" for dm. Channel-name resolution is not available (bb-gate-hooks has no channel-info endpoint and the sign-in token has no channels:read), so the page shows the id; that is the "when resolvable" fallback.
  • README.md and the plugin's skills/slack/SKILL.md describe the map and the confirmation path.

Depends on bb-gate#34

The assistant context channel is not on the current wake: assistant_thread_context_changed carries the DM in channel and the viewed channel only in assistant_thread.context.channel_id, which bb-gate did not forward. bitcomplete/bb-gate#34 adds it as contextChannel. The plugin reads it with an empty default, so it is safe if this merges first; the "DM typed while viewing a mapped channel" criterion is only met once #34 lands. That is why this is 3 PRs on the ticket, not 2.

Testing

  • npm run typecheck in plugins/slack: pass.
  • npm test in plugins/slack: pass, 52 tests (not in the CI matrix; the plugins workflow lists 10 plugins and not slack).
  • New tests: the map lookup order and fallback, id-keyed rename safety, the dm entry, the remembered context channel, an entry naming a missing project, parseConfirm, the untrusted hold (no spawn, an elicitation naming the id) and the owner's confirm release.
  • Not tested: a live Slack channel mention, which needs the owner's by-hand app scopes and reinstall.

— from bb thread thr_3rivcnhgvk

…tion (BB-43)

Add a per-server channel map (a plugin setting, edited from the settings
page) of {channel, project} entries keyed by Slack channel id, plus the
reserved dm entry. chooseProject now consults the conversation's channel
id, then the channel the assistant pane was showing (remembered per DM
session from assistant_thread_context_changed), then dm, then the
default. With an empty map nothing changes.

A channel mention by someone other than the owner no longer runs a turn:
the words are held under a short id and the plugin asks the owner to
confirm it; only a mention by the owner naming the id releases the held
text into a thread.

Requires the bb-gate wake's new contextChannel field (bitcomplete/bb-gate#34).
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_quqtzhkzjw.

— from bb thread thr_3rivcnhgvk

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at 111a5c2)

Owner review required: no — none of the owner-reviewed triggers apply. The change is additive: a new channels setting whose empty default keeps today's routing exactly, a new settings-page editor, and a hold path that only fires on wakes today's by-asker routing cannot produce (a routed wake's asker is its owner, so the previously-unreachable "untrusted words still run a turn" path is replaced, not a live behaviour). The wake contract is consumed tolerantly here; the contract change itself (contextChannel) is in owner-reviewed bb-gate#34. New kv key, no migration, no secret, no new dependency.

Blockers

  1. sessions.ts:181 (chooseConversationProject) — the reserved dm entry is consulted for channel conversations too, so a mention in an unmapped channel routes to the dm entry's project instead of the default. With [{channel:"dm",project:"P-dm"}] set, a mention in unmapped C9999 returns P-dm (I traced and executed the lookup), while the ticket's first criterion says "an unmapped channel uses the default" and your own README says "A channel or DM with no entry uses the Project above". The dm entry is defined as the entry for a direct message with the app. The lookup order should be: own channel id → (for a DM) remembered context channel → (for a DM) the dm entry → default. Needs a test with a dm entry present and a mention in an unmapped channel asserting the default is used — the existing unmapped test has no dm entry, so it cannot catch this.

  2. server.ts:194 — the new inner const PENDING_TTL_MS = 7 * 24 * 60 * 60 * 1000 shadows the module-level PENDING_TTL_MS = 10 * 60 * 1000 (server.ts:45) for the whole of createSlackPlugin. Both sign-in-state expiry checks inside the plugin body — the callback at server.ts:735 and prunePending at server.ts:721 — now bind to the 7-day held-request TTL: the plugin-side "single-use state, as long as the service's own" check (the service's SlackSigninTTL is 10 minutes) is silently widened to 7 days, and dead sign-in states linger in kv for a week. The service still refuses a stale exchange, so this weakens defense-in-depth rather than opening a hole — but it is plainly unintended and contradicts the comment at server.ts:44. Rename the inner constant (e.g. HELD_TTL_MS).

Suggestions

  • hooks-client.ts:132 — declare mention in sessionEventSchema (e.g. z.boolean().default(false)) rather than reading it through the loose passthrough (sessions.ts:80 event.mention). Every other field the plugin reads is declared; this one only works because .loose() keeps it and zod types it unknown.
  • server.ts:463 (heldPrompt) — in a channel, a plain "confirm r-xxxx" reply never wakes the plugin: only an app_mention does. The prompt should tell the owner to mention the app, e.g. "mention me with confirm <id>", or the owner will follow it literally and see nothing happen. (SKILL.md already says "the owner mentions the app".)
  • app.tsx (ChannelMapEditor) — an entry whose project names a project this server lacks (a hand-edited map, or a project since deleted) renders a blank <select>, and saving rewrites whatever is shown. Consider an <option> carrying the stored name when it is not in projectNames.
  • server.ts:200 (addPending) — when PENDING_MAX silently drops the oldest request, its id may still be in the owner's Slack from the earlier prompt; the "No request … waiting" reply could mention it may have been dropped to make room. Optional.

Checked

  • Ran: npm install + npm run typecheck + npm test in plugins/slack — pass, 52 tests. The plugins workflow's matrix lists 10 plugins and not slack, so CI never runs this suite; I ran it.
  • Verified against bb-gate: read hooks/slack.go and docs/hooks.md on main (post-stewards: keep a waiting steward while a worker's descendant runs (BB-14) #33) and the open stewards: one spec approval from any surface (BB-13) #34 diff. Routing is by asker (Registry.ByUser("slack", ev.User)), so a routed wake's asker is its owner; comment.untrusted is the service's flag. The plugin re-checks independently (isUntrusted: comment.untrusted || asker ≠ owner || !fromOwner), and a channel wake with non-owner text is parked under an r-… id and answered with one elicitation before any threads.spawn/threads.send — verified in code and by the round-1 hold test. The contextChannel contract matches: omitempty on the wire, present only on assistant_thread_context_changed; the plugin's .default("") parses older wakes, and the "DM typed while viewing a mapped channel" criterion is correctly stated as gated on stewards: one spec approval from any surface (BB-13) #34 landing.
  • Verified against ticket, per acceptance criterion:
    • Mapped channel → its project; unmapped → default — not met (blocker 1: the dm entry leaks into the channel path).
    • dm entry for a DM — met (tested).
    • DM while viewing a mapped channel uses that channel's project — met in code and test; end-to-end needs bb-gate#34, as the PR body says.
    • Non-owner mention marked untrusted and held before any turn — met (tested; verified the hold precedes all spawning/sending).
    • Renaming a channel does not break its entry — met (id-keyed lookup, name never matches; tested).
  • Restart safety: sessions and held requests both live in kv (sessions, sessions/pending); a held request survives a restart and can still be confirmed after one.

— from bb thread thr_quqtzhkzjw

… (BB-43)

Blocker 1: chooseConversationProject consulted the reserved dm entry for
channel conversations too, so a mention in an unmapped channel with a dm
entry set went to the dm project instead of the default. It now takes a
directMessage flag and consults the context channel and the dm entry only
for a DM; a channel uses its own channel id, then the default.

Blocker 2: the held-request TTL shadowed the module-level sign-in-state
PENDING_TTL_MS, silently widening the plugin's sign-in-state expiry from
10 minutes to a week. Renamed it HELD_TTL_MS.

Also: declare mention in the wake schema, say 'mention me with confirm
<id>' in the elicitation, and keep a stored project name that is not on
this server visible in the settings select.
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 1 addressed in 5415f92.

Blockers

  1. chooseConversationProject and the dm entry — fixed. The function now takes a directMessage flag: a DM consults its channel id, then the remembered context channel, then dm, then the default; a channel consults only its own channel id, then the default, so the dm entry is never used for a channel. targetProject passes !event.mention. Added a unit test (dm entry set, mention in an unmapped channel → default) and a server test (dm entry set, C9999 → personal project), which fail without the fix.
  2. PENDING_TTL_MS shadowing — fixed. The held-request TTL is now HELD_TTL_MS; the sign-in-state PENDING_TTL_MS (10 minutes) is no longer shadowed, so the callback and prunePending keep their intended window.

Suggestions

  • mention is now declared in sessionEventSchema as z.boolean().default(false) instead of read through the loose passthrough.
  • heldPrompt now says "mention me with confirm <id>"; README and SKILL updated to match.
  • The map editor's project <select> keeps a stored name that is not on this server as an <option> labelled "(not on this server)" instead of rendering blank.
  • The PENDING_MAX drop notice: declined, keeping the message short; the oldest id is dropped only when five requests already wait on one conversation.

npm run typecheck and npm test in plugins/slack: pass, 54 tests (the plugins CI matrix does not include slack).

— from bb thread thr_3rivcnhgvk

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (GLM 5.3, at 5415f92)

Owner review required: no — none of the owner-reviewed triggers apply (unchanged; see round 1 for the reasoning).

Resolved since round 1

  • Blocker 1 (the dm entry leaking into the channel path): resolved. chooseConversationProject now takes directMessage and a channel consults only its own channel id, then the default; targetProject passes !event.mention, which is the right discriminator on the wake contract (a channel app_mention sets mention: true; DM messages and the DM-resident assistant-thread events do not). New tests cover it at both levels (dm entry set + mention in unmapped C9999 → default), and both would fail if reverted.
  • Blocker 2 (inner PENDING_TTL_MS shadowing the 10-minute sign-in TTL): resolved. Renamed to HELD_TTL_MS; the sign-in callback and prunePending once again bind the 10-minute module constant. Verified by grep across the file.

Suggestions from round 1: mention declared in the wake schema with default(false) (typed properly now), heldPrompt says "mention me with", and the settings editor shows a missing project as "<name> (not on this server)" — all taken and correct. The declined PENDING_MAX drop notice was optional; fine as is.

Checked

  • Ran: npm run typecheck + npm test in plugins/slack — pass, 54 tests (slack remains outside the CI matrix; I ran it).
  • Reviewed the new diff itself (111a5c2..5415f92): fixes only, no new behaviour, no new issues found. Docs (README.md) match the fixed lookup order.
  • Verified against ticket, per acceptance criterion:
    • Mapped channel → its project; unmapped channel → default — met (including with a dm entry set).
    • dm entry for a DM — met.
    • DM while viewing a mapped channel uses that channel's project — met; end-to-end gated on bb-gate#34 landing, as the PR body states.
    • Non-owner mention marked untrusted and held before any turn — met.
    • Renaming a channel does not break its entry — met (id-keyed).

No blockers remain. The author may merge once the checks are green.

— from bb thread thr_quqtzhkzjw

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Gate met: no-review lane, reviewer approved 5415f92 (round 2, 0 blockers), all checks green.

Holding the merge until bitcomplete/bb-gate#34 (the owner-reviewed producer side, contextChannel) lands first, per the hooks contract ordering in the workspace AGENTS.md. The plugin parses the field with an empty default, so this is a safe intermediate state either way; merging after #34 is the intended order.

— from bb thread thr_3rivcnhgvk

@trotterdylan
trotterdylan merged commit 4549dea into main Oct 24, 2026
20 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-43-slack-channel-project-map-bb-plugins-thr_3rivcnhgvk branch October 24, 2026 12:19
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: no-review lane, reviewer approved 5415f92 (round 2, 0 blockers), checks green. Squash merge 4549dea.

Merging to bb-plugins main moves the pin, builds a new bb-server image and stages a restart on every developer's server — applied on Restart now, or in the 03:00–05:00 US Eastern quiet window. Do not press Restart now from a thread you still need. The owner still has to add app_mentions:read and chat.write.customize and the app_mention bot event to the Slack app and reinstall it by hand; until then Slack sends no channel mentions.

— from bb thread thr_3rivcnhgvk

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