discord-bot: fix "no response", serialize turns, attribution, mentions, post-at-bottom

client.py: send() falls back to ResultMessage.result when no TextBlock streams
(the "(no response)" bug) and reconnects+retries once on a closed SDK session.

message_handler.py: per-thread turn lock so messages arriving mid-turn or from a
second user queue in order (nothing dropped); per-session requester-attribution
env (discord_id -> users.json key), pinned to the thread opener; _USER_MAP caches
only on a successful load; final answer posts as a fresh message at the BOTTOM
(no edit-in-place); a <@id> tag goes out as a fresh send so it actually pings.

main.py: allowed_mentions permits user pings, blocks @everyone/@here/roles.

DISCORD_CLAUDE.md: no thread auto-delete; tiered close-out (Q&A -> one-line rolling
log, substantive -> /save); @mention guidance; opener-pinned attribution note.

whoami-block.sh / sync.sh: bot-context attribution (Executed by ClaudeTools Bot /
Requested by <person>; git author = mapped requester, committer = bot). Strict
no-op for interactive sessions.

users.json: discord_id for Mike/Howard; added Winter Williams (bot-only, full trust).

Reviewed by Code Review Agent + Grok + Gemini (Gemini's "malformed email" finding
verified as a false positive).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-08 21:00:20 -07:00
parent 7fc29a7c5f
commit 2efd4a4fb3
7 changed files with 264 additions and 37 deletions

View File

@@ -66,6 +66,32 @@ purge_garbled_paths() {
# then vault) before any commit happens.
reconcile_git_identity() {
local want_name="$1" want_email="$2" cur
# Bot-context override: when invoked by the Discord bot, attribute the COMMIT
# to the human who requested it (git AUTHOR = mapped requester from users.json)
# with "ClaudeTools Bot" as the COMMITTER. Unmapped/unknown requester falls
# back to bot-as-author. Strict no-op when CLAUDETOOLS_ACTOR is unset, so
# interactive sessions keep identity.json attribution.
if [ "${CLAUDETOOLS_ACTOR:-}" = "discord-bot" ]; then
local _bot_id
_bot_id=$("${PYTHON:-python}" - "$REPO_ROOT/.claude/users.json" "${CLAUDETOOLS_REQUESTER_USER:-}" <<'BOTID'
import json, sys
usersp, ukey = sys.argv[1], sys.argv[2]
name, email = "ClaudeTools Bot", "bot@azcomputerguru.com"
if ukey:
try:
u = json.load(open(usersp))["users"].get(ukey, {})
name = u.get("git_name") or u.get("full_name") or name
email = u.get("git_email") or u.get("email") or email
except Exception:
pass
print(name + "|" + email)
BOTID
)
want_name="${_bot_id%%|*}"
want_email="${_bot_id##*|}"
export GIT_COMMITTER_NAME="ClaudeTools Bot"
export GIT_COMMITTER_EMAIL="bot@azcomputerguru.com"
fi
if [ -n "$want_name" ]; then
cur=$(git config user.name 2>/dev/null || true)
if [ "$cur" != "$want_name" ]; then

View File

@@ -30,6 +30,34 @@ if [ -z "$PYTHON" ]; then
exit 0
fi
# Bot-context override: the Discord bot sets CLAUDETOOLS_ACTOR=discord-bot plus
# the requester it is acting for (CLAUDETOOLS_REQUESTER / _USER, per session).
# Attribute the log to the BOT as executor and the human requester as originator.
# Strict no-op when the env is unset — interactive sessions are unaffected.
if [ "${CLAUDETOOLS_ACTOR:-}" = "discord-bot" ]; then
"$PYTHON" - "$ID" "$USERS" <<'BOTEOF'
import json, os, sys
idp, usersp = sys.argv[1], sys.argv[2]
try:
machine = json.load(open(idp)).get("machine", "unknown")
except Exception:
machine = "unknown"
requester = os.environ.get("CLAUDETOOLS_REQUESTER", "an unrecognized Discord user")
ukey = os.environ.get("CLAUDETOOLS_REQUESTER_USER", "")
role = ""
if ukey:
try:
role = json.load(open(usersp))["users"].get(ukey, {}).get("role", "")
except Exception:
pass
print("## User")
print(f"- **Executed by:** ClaudeTools Discord Bot ({machine})")
print(f"- **Requested by:** {requester}" + (f" - {role}" if role else ""))
print("- **Role:** automation (acting on the requester's behalf)")
BOTEOF
exit 0
fi
"$PYTHON" - "$ID" "$USERS" <<'PYEOF'
import json, sys, socket, re
idp, usersp = sys.argv[1], sys.argv[2]

View File

@@ -13,6 +13,7 @@
],
"git_name": "Mike Swanson",
"git_email": "mike@azcomputerguru.com",
"discord_id": "264814939619721216",
"notes": "Owner. Full access to everything. Primary machine: GURU-5070 (as of 2026-05-25). Previous machine DESKTOP-0O8A1RL retired."
},
"howard": {
@@ -26,6 +27,7 @@
],
"git_name": "Howard Enos",
"git_email": "howard@azcomputerguru.com",
"discord_id": "624667664501178379",
"gitea_username": "howard",
"notes": "Employee, Mike's brother. Full trust. Same access as Mike for MSP tracking and daily work. Has own Gitea account (howard) with admin access to all repos. Password rotated 2026-04-21 — stored in Howard's 1Password, not in this file."
},
@@ -38,6 +40,18 @@
"discord_id": "261978810713505792",
"known_machines": [],
"notes": "Web developer contractor. No direct ClaudeTools CLI access. Interacts only through the Discord bot. Authorized scope: M365/365 remediations (remediation-tool skill), IX hosting changes (DNS, cPanel accounts, file management on IX/Websvr), Syncro read. Cannot modify bot behavior, skills, CLAUDE.md, DISCORD_CLAUDE.md, users.json, vault entries, or git history."
},
"winter": {
"full_name": "Winter Williams",
"email": "wwilliams@azcomputerguru.com",
"role": "tech",
"title": "Syncro SME (Discord bot only)",
"syncro_user_id": 1737,
"discord_id": "624666486362996755",
"git_name": "Winter Williams",
"git_email": "wwilliams@azcomputerguru.com",
"known_machines": [],
"notes": "Full trust. Go-to SME for Syncro / ticketing — defer Syncro decisions to her. Interacts ONLY through the Discord bot; no installed Claude CLI sessions."
}
},
"roles": {