Execute the approved plan in the repository. Project directory:…
- User
Execute the approved plan in the repository.
codeProject directory: /Users/user_c042661f/Documents/banodoco-workspace/brain-of-bndc Idea:Allow non-admin community members to message the BNDC Discord bot directly, with access controls. Key requirements: 1) Add a flag on the members table (e.g. can_message_bot) that controls who can interact with the bot. 2) Cordon off sensitive operations so non-admin users can only do safe read-only things (search messages, look up member info, etc.) while admins retain full control (delete messages, send messages, manage server, etc.). 3) Figure out what data/operations are actually sensitive and should be restricted. The bot currently only works via admin_chat - need to understand the full current architecture and design how to open it up safely.
User notes and answers:
-
User overrides: (1) can_message_bot goes on members table, NOT guild_members. (2) Non-admins CAN DM the bot — resolve guild context by looking up guild_members for the user. (3) Set can_message_bot=TRUE for member_id 1485999704696164502 in the migration as a test user.
codeExecution tracking source of truth (`finalize.json`): {"tasks": [ { "id": "T1", "description": "Create SQL migration
supabase/migrations/YYYYMMDD_add_can_message_bot.sqlthat addscan_message_bot BOOLEAN DEFAULT FALSEcolumn to theguild_memberstable. Run migration locally to validate.", "depends_on": [], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T2", "description": "Insrc/features/admin_chat/tools.py, nearQUERYABLE_TABLES(line 64), addMEMBER_TOOLSandADMIN_ONLY_TOOLSconstant sets. MEMBER_TOOLS = {'reply', 'end_turn', 'find_messages', 'inspect_message', 'get_active_channels', 'get_daily_summaries', 'get_member_info', 'get_bot_status', 'resolve_user'}. ADMIN_ONLY_TOOLS = {'send_message', 'edit_message', 'delete_message', 'upload_file', 'share_to_social', 'search_logs', 'query_table'}. Addget_tools_for_role(is_admin: bool) -> listthat filters the existingTOOLSlist (line 75) to return only schemas whose function name is in the appropriate set. Addallowed_tools: set = Noneparameter toexecute_tool()(line 1388); if provided and tool_name not in allowed_tools, return{\"success\": False, \"error\": \"Permission denied\"}immediately before dispatch.", "depends_on": [], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T3", "description": "In , add channel-visibility enforcement for non-admin users. (1) Add parameter to (line 1388). (2) Add async helper that uses to return channel IDs the user can see. Cache per (guild_id, user_id) for ~60s. (3) In : for the live path (line 565), after fetching channel, reject if channel.id not in visible_channels; for the DB path (line 612-628), intersect safe_channels with visible_channels. (4) In (line 743), after resolving channel_id from DB record, reject if not in visible_channels. (5) Thread (or None for admins) from to these executors. This requires adding a or parameter to and .", "depends_on": [ "T2" ], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T4", "description": "In , update the DM listener (lines 294-319). The plan's Step 4 says to add a early-return, but per the gate warning, do NOT add it for v1. Non-admin DMs should always fall through to robot sounds regardless of status. Add a comment after the admin check (line 308). This keeps v1 behavior simple: all non-admin DMs get robot sounds.", "depends_on": [ "T1" ], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T5", "description": "In , refactor the access gate (lines 105-107) to support non-admin @mentions. (1) Replace the admin-only check with a two-tier check: determine via , and if not admin, check \u2014 if DM, return early (no DM support for non-admins in v1). If guild @mention, query for that . If flag is False or not found, return silently. (2) Add method with ~60s in-memory cache. (3) Pass and (Discord user ID for non-admins, None for admins) through to . (4) Add per-user rate limiting for non-admin users: max 10 messages per 5 minutes using a sliding window dict (same pattern as dict at line 27). Reply with a brief cooldown message when hit.", "depends_on": [ "T1", "T2", "T4" ], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T6", "description": "In , update (line 111) to accept and . (1) Use when building the Claude API call (lines 214 and 222 \u2014 both the typing and non-typing paths). (2) Pass (MEMBER_TOOLS or full set) and to calls (line 264). (3) Create \u2014 a variant of (line 24) that removes write-operation instructions (delete, send, share, upload, query_table sections), frames the bot as a helpful community assistant, and lists only what members can do (search messages, look up members, browse channels, read summaries). (4) Select prompt based on . (5) Set to 10 for non-admins (vs current 20 for admins).", "depends_on": [ "T2", "T3" ], "status": "pending", "executor_notes": "", "reviewer_verdict": "" }, { "id": "T7", "description": "End-to-end validation. Test the following scenarios manually or via test scripts: (1) Admin DMs \u2192 handled by AdminChatCog, all 16 tools available, no regression. (2) Admin @mentions \u2192 same, all tools. (3) Approved member @mention in guild \u2192 response with read-only tools only. (4) Approved member tries to search a channel they can't see \u2192 rejected. (5) Approved member DMs bot \u2192 robot sounds from AdminCog. (6) Unapproved member @mention \u2192 silently ignored. (7) Unapproved member DM \u2192 robot sounds. (8) Prompt injection: member message tries to get Claude to call delete_message \u2192 executor rejects. (9) Rate limiting: 11th message in 5 minutes \u2192 cooldown reply. (10) guild_members.can_message_bot correctly gates per-guild.", "depends_on": [ "T5", "T6" ], "status": "pending", "executor_notes": "", "reviewer_verdict": "" } ], "watch_items": [ "DM routing consistency: AdminCog (admin_cog.py:294-319) must NOT add a can_message_bot early-return for v1. All non-admin DMs must reach robot sounds. The plan's Step 4 text is inconsistent with the success criteria on this point \u2014 the gate guidance is authoritative: do NOT add the early-return.", "Dual response bug: AdminCog.on_message fires before AdminChatCog.on_message (cog load order in main.py). For guild @mentions, AdminCog returns early at line 297 (message.guild is not None), so no conflict. For admin DMs, AdminCog returns early at line 306. Verify this ordering is preserved if cog loading changes.", "Tool tier completeness: MEMBER_TOOLS + ADMIN_ONLY_TOOLS must cover all 16 tools in the TOOLS list (line 75). If a new tool is added later, it must be classified. Consider adding an assertion that MEMBER_TOOLS | ADMIN_ONLY_TOOLS == {t['name'] for t in TOOLS} minus reply/end_turn.", "Channel visibility cache staleness: The 60s cache on _get_visible_channel_ids means a permission change in Discord takes up to 60s to take effect. This is acceptable per plan assumptions but should be documented in code.", "Rate limiting is in-memory only \u2014 resets on bot restart. Acceptable for v1 per plan assumptions.", "execute_tool now has two new parameters (allowed_tools, requester_id). All existing call sites must be updated to pass these, or defaults must be backward-compatible (None = unrestricted).", "MEMBER_SYSTEM_PROMPT must not mention admin-only tools by name \u2014 Claude may attempt to call tools it 'knows about' from the prompt even if they're not in the tool list.", "The guild_id for channel visibility must come from the message context (channel_context['guild_id']), not from a tool parameter that the user/Claude could manipulate." ], "sense_checks": [ { "id": "SC1", "task_id": "T1", "question": "Does the migration add to (not )? Is the column nullable or has a default so existing rows aren't broken?", "verdict": "" }, { "id": "SC2", "task_id": "T2", "question": "Do MEMBER_TOOLS + ADMIN_ONLY_TOOLS exactly cover all tool names in the TOOLS list? Is the execute_tool enforcement a hard reject (not just a warning) that returns before any dispatch?", "verdict": "" }, { "id": "SC3", "task_id": "T3", "question": "Does _get_visible_channel_ids use Discord's permissions_for(member).view_channel (not role checks or DB lookups)? Are both the live path and DB path in find_messages filtered? Is inspect_message filtered? Does admin (requester_id=None) bypass all filtering?", "verdict": "" }, { "id": "SC4", "task_id": "T4", "question": "Is the AdminCog DM listener unchanged for v1 (no can_message_bot check added)? All non-admin DMs still get robot sounds? Is there a TODO comment for future DM support?", "verdict": "" }, { "id": "SC5", "task_id": "T5", "question": "Does the cog correctly distinguish: admin (any channel) \u2192 full access, non-admin DM \u2192 return early (falls to robot sounds), non-admin guild @mention with flag \u2192 member access, non-admin guild @mention without flag \u2192 silently ignored? Does rate limiting only apply to non-admins?", "verdict": "" }, { "id": "SC6", "task_id": "T6", "question": "Are BOTH Claude API call sites (lines 210-216 typing path AND lines 218-224 non-typing path) updated to use get_tools_for_role? Does MEMBER_SYSTEM_PROMPT avoid naming admin-only tools? Is MAX_CONVERSATION_LENGTH reduced for non-admins?", "verdict": "" }, { "id": "SC7", "task_id": "T7", "question": "Were all 10 validation scenarios tested? Did the prompt injection test (scenario 8) confirm executor-level rejection even if Claude somehow attempts a restricted tool call?", "verdict": "" } ], "meta_commentary": "Critical executor guidance:\n\n1. The plan text in Step 4 says to add a early-return in AdminCog, but this contradicts the v1 design (no DM support for non-admins) and the success criteria. The gate explicitly warns against this. In T4, do NOT add the early-return \u2014 just add a TODO comment. This is the single open flag from critique and the fix is trivial.\n\n2. Lines 210-216 (inside context) and lines 218-224 (without typing). Both pass and both must be updated to use . Easy to miss the second one.\n\n3. Adding and parameters must use defaults of to avoid breaking existing call sites during incremental development. means unrestricted (admin behavior).\n\n4. \u2014 the cog passes and to , which uses them for tool selection and enforcement. Implement them together or in quick succession. The dependency graph allows T5 after T4 and T6 after T3, but they should be tested together.\n\n5. The helper needs access to the bot's guild/member cache. If the member isn't cached, makes an API call. The 60s TTL cache prevents this from being called per-tool-execution. Use or a simple dict with timestamps \u2014 the bot is single-process so no concurrency issues beyond asyncio.\n\n6. For @mentions, is set by the cog from \u2014 this is trustworthy. Do NOT use guild_id from tool_input for visibility checks, as Claude constructs tool_input from the conversation and it could be manipulated via prompt injection. The cog-level guild_id should be threaded through as a separate trusted parameter.\n\n7. T1 and T2 are independent and can be done in parallel. T3 depends on T2. T4 depends on T1 (conceptually, for the TODO to reference the column). T5 depends on T1+T2+T4. T6 depends on T2+T3. T7 is final validation after T5+T6." }
-
- Assistant