Skip to content

Slack account link, agent application feed, and agent decisions on an admin's behalf - #270

Merged
codeforphilly-bot merged 26 commits into
developfrom
feat/membership-slack-chain
Nov 30, 2026
Merged

codeforphilly-bot merged 26 commits into
developfrom
feat/membership-slack-chain

Conversation

@codeforphilly-bot

@codeforphilly-bot codeforphilly-bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #269. Site side of the plans slack-account-link, agent-application-feed and agent-decide-on-behalf. The bot side is not built yet and each plan still lists it under awaits:. Written by GrittyBot, an AI. 🧡🤖

What it does

  • Link, automatically. Every Slack account here is created through the site's SAML sign-in. So the site links a member to their Slack user on its own when two independent facts agree: the user Slack finds for the member's email has the handle the site asserted at sign-in (slackSamlNameId), and is a full, active, human member of the workspace. The site checks this itself with its own read-only Slack token. An agent never asserts it.
  • Link, by code. Members the automatic path cannot match get a one-time code on the Account screen and send it to the ops bot in a DM. Disconnecting opts out of automatic re-linking. A code reconnects.
  • Feed. GET /api/agent/events gives an agent application events with the project's admins and their linked Slack ids. Never an email address. Held applications and deactivated people do not appear.
  • Decide. An agent can record an accept or close for a named project admin who has a verified link and is an admin of that project right now. The commit is authored by the agent with On-Behalf-Of. The admin gets a confirmation email for each decision. Capped at 30 a day per agent.

How the automatic link behaves

  • One person at a time, never a sweep: about a minute after a Slack sign-in, on /api/auth/me for a signed-in person with no link, and when the feed needs an admin's Slack id (at most 5 lookups per request).
  • At most 20 Slack calls a minute. A "no match" is cached for 24 hours, a Slack error for 15 minutes.
  • An automatic link is re-verified after 24 hours and always before an on-behalf decision. A mismatch removes the link and the decision is refused.
  • Exact handle match only. Measured on the workspace: 4,806 of 5,490 live Slack members have a handle equal to a site name id, and 106 of 174 maintainers. Ignoring dots and underscores would add about 298 members. That widening is left out for now.

Read first

  • apps/api/src/services/slack-auto-link.ts and apps/api/src/slack/directory.ts
  • apps/api/src/services/agent-decision.ts and apps/api/src/routes/agent-applications.ts
  • apps/api/src/auth/caller.ts (agentScopeCaller)
  • apps/api/src/services/slack-link.ts and apps/api/src/services/agent-feed.ts
  • Tests: slack-auto-link, agent-decision, slack-link, agent-feed
  • Specs first: 5052021 and 82d00ef

To deploy

  1. The data repo adopts agent-grants/v2. No migration, it only adds scope values.
  2. Set SLACK_TEAM_ID and SLACK_BOT_TOKEN. The token is for a new Slack app of the site's own with exactly users:read and users:read.email. Without both, automatic linking is off and code linking still works. Optionally SLACK_OPS_BOT_DM_URL.
  3. An administrator mints a grant for the bot with slack:link, projects:applications:read and projects:applications:decide.

Open points

  • When Slack cannot be reached for a re-check, the decision is refused with not_project_admin, not a retryable 503.
  • An email change keeps an automatic link until its next re-check, which then uses the new email.
  • The cache and call budget live in memory and assume a single replica.

Not verified

  • Nothing ran against real Slack: the real field values, the rate tier, and whether a member can change their handle or email after sign-in.
  • Real email delivery, the data-repo adoption, and the bot side.
  • Locally: contract check, type-check, lint, build and 1,187 tests pass. The automatic path is covered by tests with a fake Slack directory, not by a browser run.

🤖 Generated with Claude Code

codeforphilly-bot added a commit that referenced this pull request Nov 29, 2026
The three closeout commits were made before the pull request existed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
codeforphilly-bot added a commit that referenced this pull request Nov 30, 2026
Operator-approved on PR #270: the site links an account to a Slack user
by itself when the user found by its email has the handle the site
asserted at sign-in. Scope, approach and validation amended; the earlier
closeout's ticks stand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
codeforphilly-bot added a commit that referenced this pull request Nov 30, 2026
…agree

Operator-approved design on PR #270. With its own read-only token
(SLACK_BOT_TOKEN: users:read, users:read.email) the site links an
account when users.lookupByEmail for the private-profile email returns a
full, active, human member of SLACK_TEAM_ID whose handle exactly equals
slackSamlNameId. It runs one person at a time: about a minute after Slack
SAML sign-in, on /me (waiting at most 1.5 s), and for up to 5 admins per
feed request; at most 20 Slack calls a minute, honouring Retry-After;
no-match cached 24 h, errors 15 min. Automatic links are re-verified when
used past 24 h, always before an on-behalf decision (a mismatch removes
the link; either failure refuses not_project_admin); the feed stops
carrying an id unverified for 7 days. Links record via (auto | code) and
verifiedAt; disconnecting records an opt-out the automatic path honours
and a code link clears. The code stays as the fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
codeforphilly-bot added a commit that referenced this pull request Nov 30, 2026
…link (PR #270)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
codeforphilly-bot and others added 25 commits November 30, 2026 00:51
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- slack-link: the code is 8 characters shown as two groups of four (the
  example had 7); the code response carries botDmUrl so the Account row
  can link the bot's name to a DM, as the screen asks; an account with no
  private profile is refused (the link lives there); redemption fails
  closed with no workspace configured; a 409 does not consume the code
- auth: /me's slack field, which account.md already reads
- conventions: the linking pair counts as credential endpoints
- data-model: agent-grants contract is v2 (the new scopes change it)
- agent-applications: application.visible is at notifiedAt (when the
  hold ended for a held one), so the cursor never skips it; events
  appear once a minute old; next is never null; where decidedBy,
  decidedVia and closedBy sit; the decide scope without its companions
  is refused at use (401), and a foreign workspace is not_project_admin
- architecture: SLACK_TEAM_ID and SLACK_OPS_BOT_DM_URL

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n private profiles

AGENT_SCOPES gains slack:link, projects:applications:read and
projects:applications:decide, with AGENT_SCOPE_REQUIRES naming each
scope's companions. agent-grants/v2 is generated and vendored into the
API mirror (with gitsheets contracts adopt; provenance lands when the
data repo adopts from the published URL). PrivateProfile gains the
optional slack { teamId, userId, linkedAt }.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h profile rewrites

bySlackUserId (teamId:userId → personId) is rebuilt with the other private
indices, so a link, a disconnect or a purge is reflected at once. The
profile rewrites on a GitHub email change, an account claim, a claim
merge and a staff email edit rebuilt the profile field by field and would
have dropped the link; they carry it now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POST /api/account/slack-link/code issues an 8-character code (two groups
of four, no 0/O/1/I/L), hashed in memory for ten minutes, one live code
per person, five per hour. POST /api/agent/slack-links (slack:link)
redeems it for the Slack user who sent it: unknown, expired, used and
orphaned codes answer one 404 code_invalid, ten failures lock the agent
out for an hour, another workspace (or none configured) is 422, and a
Slack user linked elsewhere is 409 without spending the code. DELETE
/api/account/slack-link clears it. /api/auth/me reports { linked,
linkedAt }, never the user id. Minting enforces every scope's
companions; /api/agent/* routes check scope and companions before the
body (401). Both linking paths count as credential endpoints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mint form

Connect Slack asks for a code and shows it with the instruction to DM it
to the ops bot within ten minutes (the bot's name links to botDmUrl when
configured); the row polls /api/auth/me while the code is live and turns
"Connected to Slack ✓ since …" when the bot confirms. Disconnect asks
first. The row never shows a Slack user id. The agents panel's mint form
offers the three new scopes and warns when decide lacks its companions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
projects:applications:read. Events are derived from the membership
records on each read: application.visible at notifiedAt, .reminder at
remindedAt, .accepted at decidedAt, .closed at closedAt. A held
application, one withdrawn before admins could see it, and every event of
a deactivated applicant or deleted project are left out. Each event names
the project, the applicant's facts, the application (offer, needs,
decidedBy, decidedVia, closedBy) and the active admins, with a Slack user
id only for a verified link in this workspace; no email anywhere.
Ordered by (at, record id, type) with a base64url cursor that survives a
restart; 7-day default window; events show once a minute old, and the
sweep stamps its notice bookkeeping when it commits rather than when it
started, so nothing lands behind a cursor. hasSlackLink reads the typed
field now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"The ops bot recorded that you accepted …", naming the agent, how to undo
it, and a link to the Applications screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POST /api/agent/applications/:projectSlug/:personSlug/decision under
projects:applications:decide, which must hold its two companions at use
(401 otherwise). onBehalfOf must name a Slack user in the configured
workspace with a verified link to a person who is not deactivated, not an
agent, and is a project-admin of this project right now, checked with the
site's project-admin marker alone so staff powers do not carry over (403
not_project_admin otherwise). Checked before the lock to name the admin
in the commit and again under it, with the 30-per-24-hours cap per agent
across its grants (records plus an in-process log). The effect is the
site's accept or close run as that admin, with decidedVia = agent and
agentGrantId; the commit is the agent's with Actor-Kind, Grant-Id and
On-Behalf-Of. Unknown body fields (isAdmin above all) are refused, not
dropped. The applicant gets the usual email and the admin a confirmation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The three closeout commits were made before the pull request existed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Operator-approved on PR #270: the site links an account to a Slack user
by itself when the user found by its email has the handle the site
asserted at sign-in. Scope, approach and validation amended; the earlier
closeout's ticks stand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…agree

Operator-approved design on PR #270. With its own read-only token
(SLACK_BOT_TOKEN: users:read, users:read.email) the site links an
account when users.lookupByEmail for the private-profile email returns a
full, active, human member of SLACK_TEAM_ID whose handle exactly equals
slackSamlNameId. It runs one person at a time: about a minute after Slack
SAML sign-in, on /me (waiting at most 1.5 s), and for up to 5 admins per
feed request; at most 20 Slack calls a minute, honouring Retry-After;
no-match cached 24 h, errors 15 min. Automatic links are re-verified when
used past 24 h, always before an on-behalf decision (a mismatch removes
the link; either failure refuses not_project_admin); the feed stops
carrying an id unverified for 7 days. Links record via (auto | code) and
verifiedAt; disconnecting records an opt-out the automatic path honours
and a code link clears. The code stays as the fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e opt-out

PrivateProfile.slack gains via (auto | code; absent means code) and
verifiedAt; the profile gains slackAutoLinkOptOutAt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Behind an interface so tests use a fake. 429 and ratelimited become
SlackRateLimitedError with Retry-After; users_not_found is null; anything
else is SlackApiError carrying Slack's error string, never the email.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With SLACK_BOT_TOKEN and SLACK_TEAM_ID, the site links a person when the
Slack user found for their private-profile email has a handle exactly
equal to slackSamlNameId and is a full, active, human member of the
workspace. Runs about a minute after Slack SAML sign-in, on /me (waiting
at most 1.5 s), and for up to 5 admins per feed request; 20 Slack calls a
minute site-wide, Retry-After honoured, no-match cached 24 h and errors
15 min, one attempt per person at a time; never throws to its caller.
Automatic links past 24 h are re-checked when used and always before an
on-behalf decision: a mismatch removes the link, and the decision is
refused not_project_admin if the link is removed or could not be
re-checked (resolved again under the write lock). The feed drops an
automatic link unverified for 7 days. Code links record via=code and
clear the opt-out; disconnecting records it. Profile rewrites carry the
opt-out. me.slack reports via. The email is never logged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lly or made by code

Disconnect's confirm says the site will not reconnect by itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…link (PR #270)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codeforphilly-bot
codeforphilly-bot force-pushed the feat/membership-slack-chain branch from f70a81c to b8ee18d Compare November 30, 2026 00:51
…2 adoption

apps/api/gitsheets/ mirrors codeforphilly-data's empty branch after it
adopts agent-grants/v2: sources.toml records the v2 provenance, and the
v1 document no sheet declares any more goes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from feat/project-membership-revamp to develop November 30, 2026 00:56
@codeforphilly-bot
codeforphilly-bot marked this pull request as ready for review November 30, 2026 01:14
@codeforphilly-bot
codeforphilly-bot merged commit 0a00253 into develop Nov 30, 2026
1 check passed
@codeforphilly-bot
codeforphilly-bot deleted the feat/membership-slack-chain branch November 30, 2026 01:14
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