Skip to content

feat(brand-claim): chat tools + member-profile UI for domain challenge - #3224

Merged
bokelley merged 3 commits into
mainfrom
bokelley/brand-claim-chat-tool
Apr 25, 2026
Merged

bokelley merged 3 commits into
mainfrom
bokelley/brand-claim-chat-tool

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

Follow-ups from #3189 (WorkOS-backed domain claim challenge):

  1. Member chat tools — request_brand_domain_challenge and verify_brand_domain_challenge are exposed in the member tool set so an org admin can run the DNS-TXT claim flow inside Addie without leaving the chat.
  2. Member-profile UI panel — a "Verify domain ownership" section on /member-profile (admin/owner only) that calls the existing /brand-claim/issue and /brand-claim/verify endpoints, surfaces the DNS record (Name / Type / Value with copy buttons), and lets the user opt into adopting the prior owner's manifest.
  3. Service extraction — pulled the WorkOS orchestration out of routes/member-profiles.ts into services/brand-claim.ts so the chat handlers and HTTP handlers share one implementation of issue/verify, including the 422-collision-vs-syntactic disambiguation and isVerifiedState() cast that bypasses the SDK's OrganizationDomainState narrowing weirdness.

The chat tool handlers re-check role (admin/owner) via workos.userManagement.listOrganizationMemberships before running, mirroring the HTTP resolveBrandClaimOrgOr401 gate. The UI hides the panel for non-admins so members don't see a button that would 401.

Test plan

  • npm run typecheck clean
  • npm run test:server-unit — 2215 passed, 34 skipped, 0 failed
  • precommit hooks (test:unit + test-dynamic-imports + typecheck) green
  • member-profile.html script block parses (new Function smoke check)
  • Manual smoke: load /member-profile as admin, click Start → Request DNS challenge → see DNS record fields populate; verify panel hidden when role=member
  • Manual smoke: in Addie chat, member calls request_brand_domain_challenge and gets DNS instructions; non-admin gets 403-style refusal

🤖 Generated with Claude Code

@bokelley

Copy link
Copy Markdown
Contributor Author

Issue #3229 proposes conditional rendering of the adopt_prior_manifest checkbox (only when prior manifest has logos/colors/agents) plus a copy rewrite to neutral framing ("Start from the existing brand record") — same surface as this PR (member-profile.html + chat tool descriptions); consider folding before merge or confirm follow-up.


Generated by Claude Code

@bokelley

Copy link
Copy Markdown
Contributor Author

Issue #3231 proposes adding a STATUS: tag to request_brand_domain_challenge and verify_brand_domain_challenge responses for machine-readable model branching — same chat-tool surface as this PR; consider folding before merge or confirm as a follow-up.


Generated by Claude Code

@bokelley

Copy link
Copy Markdown
Contributor Author

Issue #3230 proposes a copy-all IT-handoff button, challenge expiry/issued-at surfacing, and a reissue button — same server/public/member-profile.html + services/brand-claim.ts surface as this PR; consider folding before merge or confirm as follow-up.


Generated by Claude Code

@bokelley

Copy link
Copy Markdown
Contributor Author

Issue #3228 proposes surfacing the brand-claim panel from the not-linked state when PUT /brand-identity returns 409 cross_org_ownership — same surface as this PR (member-profile.html + brand-claim.ts); consider folding before merge or confirm follow-up.


Generated by Claude Code

bokelley and others added 3 commits April 25, 2026 19:55
…hallenge

Chat tools `request_brand_domain_challenge` / `verify_brand_domain_challenge`
in the member tool set. Member-profile.html gains a DNS-TXT panel (admin/owner-
only) so members can claim a domain registered to another org without leaving
the app. Pulls the WorkOS orchestration out of the routes into
services/brand-claim.ts so chat handlers and HTTP handlers share one
implementation of the issue/verify flow.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- Security M1: callerIsOrgAdmin and resolveBrandClaimOrgOr401 now use
  resolveUserRole so inactive/pending memberships can't pass the gate. A
  removed admin must not be able to claim a brand on the org that
  removed them.
- HTTP response shape: restore { brand } object on /verify success and
  human-readable error strings + domain field across error paths so the
  routes match what shipped in #3189. Add machine-readable code field
  alongside error so chat consumers can branch without prose matching.
- Anti-loop: 60s in-process verify cooldown + explicit STOP guidance in
  chat handler markdown when WorkOS returns still_pending.
- Surface prior_manifest_exists from issue so chat callers can prompt
  the user about the adopt-vs-fresh decision; flow through to verify
  tool description as the precondition for adopt_prior_manifest=true.
- Tighten tool descriptions with explicit "Do NOT use when" clauses to
  stop speculative LLM calls.
- Hoist dynamic imports in member-tools.ts to top of file; brandDb
  becomes a module-scope singleton matching memberDb / orgDb pattern.
- UI: copyDomainClaimField receives the button via inline onclick so it
  no longer depends on event.target inside a microtask. toggleDomainClaim
  tracks open state in JS rather than reading display style.
- Service unit tests (16 cases) covering invalid/shared-platform/eTLD,
  collision disambiguation, idempotent re-issue, prior_manifest_exists
  detection, no_challenge, still_pending, success+brand, and the
  cooldown.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Caps verifyAttemptTimes at 10K entries with expired-first eviction so a
buggy admin client can't grow the in-process map without limit.

Drops "the LLM should not poll" wording from the still_pending cooldown
message — it ships through the HTTP /verify path too and reads weird to
non-chat consumers. Anti-loop guidance for the LLM still lives in the
chat handler markdown where it belongs.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley force-pushed the bokelley/brand-claim-chat-tool branch from dac16d9 to e01e7f4 Compare April 25, 2026 23:56
@bokelley
bokelley merged commit 602d21c into main Apr 25, 2026
11 of 12 checks passed
@bokelley
bokelley deleted the bokelley/brand-claim-chat-tool branch April 25, 2026 23:56
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